File size: 4,993 Bytes
6de5b47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-06-26T10:20:11.807176Z",
     "start_time": "2025-06-26T10:20:11.800149Z"
    }
   },
   "source": [
    "\n",
    "from pymongo.mongo_client import MongoClient\n",
    "from pymongo.server_api import ServerApi\n",
    "from dotenv import load_dotenv\n",
    "load_dotenv()\n",
    "import os\n",
    "import json"
   ],
   "outputs": [],
   "execution_count": 9
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-26T10:16:45.879242Z",
     "start_time": "2025-06-26T10:16:45.876031Z"
    }
   },
   "cell_type": "code",
   "source": "uri = os.getenv(\"MONGODB_URI\")",
   "id": "2d2114f7ef19f868",
   "outputs": [],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-26T10:16:47.798644Z",
     "start_time": "2025-06-26T10:16:46.158912Z"
    }
   },
   "cell_type": "code",
   "source": [
    "\n",
    "# Create a new client and connect to the server\n",
    "client = MongoClient(uri, server_api=ServerApi('1'))\n",
    "\n",
    "# Send a ping to confirm a successful connection\n",
    "try:\n",
    "    client.admin.command('ping')\n",
    "    print(\"Pinged your deployment. You successfully connected to MongoDB!\")\n",
    "except Exception as e:\n",
    "    print(e)"
   ],
   "id": "11b5d4e1c554d3af",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Pinged your deployment. You successfully connected to MongoDB!\n"
     ]
    }
   ],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-26T10:18:48.684105Z",
     "start_time": "2025-06-26T10:18:48.542880Z"
    }
   },
   "cell_type": "code",
   "source": "client.list_database_names()",
   "id": "b26f8f320fe570f4",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['admin', 'local']"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 8
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-26T13:51:22.341078Z",
     "start_time": "2025-06-26T13:51:22.338610Z"
    }
   },
   "cell_type": "code",
   "source": [
    "my_db = client[\"MAPF_Solver\"]\n",
    "perfect_heuristics_col = my_db[\"perfect_heuristics\"]"
   ],
   "id": "fd5280e0c814c23d",
   "outputs": [],
   "execution_count": 35
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-26T13:51:22.581004Z",
     "start_time": "2025-06-26T13:51:22.578972Z"
    }
   },
   "cell_type": "code",
   "source": "",
   "id": "9404c7961949bcaa",
   "outputs": [],
   "execution_count": 36
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-26T13:56:03.654179Z",
     "start_time": "2025-06-26T13:55:54.602665Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# map_name = 'empty-32-32'\n",
    "# map_name = 'maze-32-32-2'\n",
    "# map_name = 'maze-32-32-4'\n",
    "# map_name = 'random-32-32-10'\n",
    "# map_name = 'random-32-32-20'\n",
    "map_name = 'room-32-32-4'\n",
    "\n",
    "full_dir = f'logs_for_heuristics/h_dict_of_{map_name}.json'\n",
    "with open(full_dir, \"r\") as f:\n",
    "    h_dict = json.load(f)\n",
    "    exists = perfect_heuristics_col.find_one({\"name\": map_name}) is not None\n",
    "    if not exists:\n",
    "        my_db[\"perfect_heuristics\"].insert_one({\n",
    "            'name': map_name,\n",
    "            'h_dict': h_dict\n",
    "        })\n",
    "    else:\n",
    "        print(f'The perfect heuristic of {map_name} already exists in the database.')"
   ],
   "id": "368e02123432350d",
   "outputs": [],
   "execution_count": 49
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-26T13:52:27.343992Z",
     "start_time": "2025-06-26T13:52:24.754651Z"
    }
   },
   "cell_type": "code",
   "source": "doc = perfect_heuristics_col.find_one({\"name\": map_name})",
   "id": "c5e5ec57cefdbfe0",
   "outputs": [],
   "execution_count": 40
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-26T13:52:34.053818Z",
     "start_time": "2025-06-26T13:52:34.042441Z"
    }
   },
   "cell_type": "code",
   "source": "h_dict = doc['h_dict']",
   "id": "c8ebf6cb4e0133b8",
   "outputs": [],
   "execution_count": 41
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "29bf5dd9783e2fcd"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}