ArseniyPerchik commited on
Commit
6de5b47
·
1 Parent(s): cc6e340
Files changed (4) hide show
  1. README.md +15 -0
  2. functions.py +11 -1
  3. mongodb_draft.ipynb +211 -0
  4. mongodb_drafts.py +17 -0
README.md CHANGED
@@ -12,3 +12,18 @@ short_description: 'Solve your MAPF problem in one click '
12
  ---
13
 
14
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  ---
13
 
14
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
15
+
16
+
17
+ ## TODO:
18
+ - [ ] Upload perfect heuristics from MongoDB
19
+ - [ ] Create perfect heuristic and update MongoDB
20
+ - [ ] Solve with PrP with the full UI output
21
+ - [ ] Add an option for creating SV sets (also with MongoDB involved)
22
+ - [ ] Add all other algorithms to the stack via MCP
23
+ - [ ] Build a LangGraph flow to decide which algorithm to use
24
+
25
+ ## FINISHED:
26
+ - [x] Add a way to upload a map
27
+ - [x] Add a way to upload a scenario
28
+ - [x] Add a way to upload a solution
29
+
functions.py CHANGED
@@ -1,5 +1,6 @@
1
  import re
2
  import numpy as np
 
3
 
4
  def get_dims_from_pic(file_dir):
5
  with open(f'{file_dir}') as f:
@@ -18,4 +19,13 @@ def get_np_from_dot_map(file_dir):
18
  for width_index, curr_str in enumerate(line):
19
  if curr_str == '.':
20
  img_np[height_index, width_index] = 1
21
- return img_np, (height, width)
 
 
 
 
 
 
 
 
 
 
1
  import re
2
  import numpy as np
3
+ import json
4
 
5
  def get_dims_from_pic(file_dir):
6
  with open(f'{file_dir}') as f:
 
19
  for width_index, curr_str in enumerate(line):
20
  if curr_str == '.':
21
  img_np[height_index, width_index] = 1
22
+ return img_np, (height, width)
23
+
24
+
25
+
26
+ def load_locations(loc_string: str):
27
+ try:
28
+ loc_dict = json.loads(loc_string)
29
+ return loc_dict
30
+ except json.JSONDecodeError:
31
+ return 'None'
mongodb_draft.ipynb ADDED
@@ -0,0 +1,211 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "id": "initial_id",
6
+ "metadata": {
7
+ "collapsed": true,
8
+ "ExecuteTime": {
9
+ "end_time": "2025-06-26T10:20:11.807176Z",
10
+ "start_time": "2025-06-26T10:20:11.800149Z"
11
+ }
12
+ },
13
+ "source": [
14
+ "\n",
15
+ "from pymongo.mongo_client import MongoClient\n",
16
+ "from pymongo.server_api import ServerApi\n",
17
+ "from dotenv import load_dotenv\n",
18
+ "load_dotenv()\n",
19
+ "import os\n",
20
+ "import json"
21
+ ],
22
+ "outputs": [],
23
+ "execution_count": 9
24
+ },
25
+ {
26
+ "metadata": {
27
+ "ExecuteTime": {
28
+ "end_time": "2025-06-26T10:16:45.879242Z",
29
+ "start_time": "2025-06-26T10:16:45.876031Z"
30
+ }
31
+ },
32
+ "cell_type": "code",
33
+ "source": "uri = os.getenv(\"MONGODB_URI\")",
34
+ "id": "2d2114f7ef19f868",
35
+ "outputs": [],
36
+ "execution_count": 3
37
+ },
38
+ {
39
+ "metadata": {
40
+ "ExecuteTime": {
41
+ "end_time": "2025-06-26T10:16:47.798644Z",
42
+ "start_time": "2025-06-26T10:16:46.158912Z"
43
+ }
44
+ },
45
+ "cell_type": "code",
46
+ "source": [
47
+ "\n",
48
+ "# Create a new client and connect to the server\n",
49
+ "client = MongoClient(uri, server_api=ServerApi('1'))\n",
50
+ "\n",
51
+ "# Send a ping to confirm a successful connection\n",
52
+ "try:\n",
53
+ " client.admin.command('ping')\n",
54
+ " print(\"Pinged your deployment. You successfully connected to MongoDB!\")\n",
55
+ "except Exception as e:\n",
56
+ " print(e)"
57
+ ],
58
+ "id": "11b5d4e1c554d3af",
59
+ "outputs": [
60
+ {
61
+ "name": "stdout",
62
+ "output_type": "stream",
63
+ "text": [
64
+ "Pinged your deployment. You successfully connected to MongoDB!\n"
65
+ ]
66
+ }
67
+ ],
68
+ "execution_count": 4
69
+ },
70
+ {
71
+ "metadata": {
72
+ "ExecuteTime": {
73
+ "end_time": "2025-06-26T10:18:48.684105Z",
74
+ "start_time": "2025-06-26T10:18:48.542880Z"
75
+ }
76
+ },
77
+ "cell_type": "code",
78
+ "source": "client.list_database_names()",
79
+ "id": "b26f8f320fe570f4",
80
+ "outputs": [
81
+ {
82
+ "data": {
83
+ "text/plain": [
84
+ "['admin', 'local']"
85
+ ]
86
+ },
87
+ "execution_count": 8,
88
+ "metadata": {},
89
+ "output_type": "execute_result"
90
+ }
91
+ ],
92
+ "execution_count": 8
93
+ },
94
+ {
95
+ "metadata": {
96
+ "ExecuteTime": {
97
+ "end_time": "2025-06-26T13:51:22.341078Z",
98
+ "start_time": "2025-06-26T13:51:22.338610Z"
99
+ }
100
+ },
101
+ "cell_type": "code",
102
+ "source": [
103
+ "my_db = client[\"MAPF_Solver\"]\n",
104
+ "perfect_heuristics_col = my_db[\"perfect_heuristics\"]"
105
+ ],
106
+ "id": "fd5280e0c814c23d",
107
+ "outputs": [],
108
+ "execution_count": 35
109
+ },
110
+ {
111
+ "metadata": {
112
+ "ExecuteTime": {
113
+ "end_time": "2025-06-26T13:51:22.581004Z",
114
+ "start_time": "2025-06-26T13:51:22.578972Z"
115
+ }
116
+ },
117
+ "cell_type": "code",
118
+ "source": "",
119
+ "id": "9404c7961949bcaa",
120
+ "outputs": [],
121
+ "execution_count": 36
122
+ },
123
+ {
124
+ "metadata": {
125
+ "ExecuteTime": {
126
+ "end_time": "2025-06-26T13:56:03.654179Z",
127
+ "start_time": "2025-06-26T13:55:54.602665Z"
128
+ }
129
+ },
130
+ "cell_type": "code",
131
+ "source": [
132
+ "# map_name = 'empty-32-32'\n",
133
+ "# map_name = 'maze-32-32-2'\n",
134
+ "# map_name = 'maze-32-32-4'\n",
135
+ "# map_name = 'random-32-32-10'\n",
136
+ "# map_name = 'random-32-32-20'\n",
137
+ "map_name = 'room-32-32-4'\n",
138
+ "\n",
139
+ "full_dir = f'logs_for_heuristics/h_dict_of_{map_name}.json'\n",
140
+ "with open(full_dir, \"r\") as f:\n",
141
+ " h_dict = json.load(f)\n",
142
+ " exists = perfect_heuristics_col.find_one({\"name\": map_name}) is not None\n",
143
+ " if not exists:\n",
144
+ " my_db[\"perfect_heuristics\"].insert_one({\n",
145
+ " 'name': map_name,\n",
146
+ " 'h_dict': h_dict\n",
147
+ " })\n",
148
+ " else:\n",
149
+ " print(f'The perfect heuristic of {map_name} already exists in the database.')"
150
+ ],
151
+ "id": "368e02123432350d",
152
+ "outputs": [],
153
+ "execution_count": 49
154
+ },
155
+ {
156
+ "metadata": {
157
+ "ExecuteTime": {
158
+ "end_time": "2025-06-26T13:52:27.343992Z",
159
+ "start_time": "2025-06-26T13:52:24.754651Z"
160
+ }
161
+ },
162
+ "cell_type": "code",
163
+ "source": "doc = perfect_heuristics_col.find_one({\"name\": map_name})",
164
+ "id": "c5e5ec57cefdbfe0",
165
+ "outputs": [],
166
+ "execution_count": 40
167
+ },
168
+ {
169
+ "metadata": {
170
+ "ExecuteTime": {
171
+ "end_time": "2025-06-26T13:52:34.053818Z",
172
+ "start_time": "2025-06-26T13:52:34.042441Z"
173
+ }
174
+ },
175
+ "cell_type": "code",
176
+ "source": "h_dict = doc['h_dict']",
177
+ "id": "c8ebf6cb4e0133b8",
178
+ "outputs": [],
179
+ "execution_count": 41
180
+ },
181
+ {
182
+ "metadata": {},
183
+ "cell_type": "code",
184
+ "outputs": [],
185
+ "execution_count": null,
186
+ "source": "",
187
+ "id": "29bf5dd9783e2fcd"
188
+ }
189
+ ],
190
+ "metadata": {
191
+ "kernelspec": {
192
+ "display_name": "Python 3",
193
+ "language": "python",
194
+ "name": "python3"
195
+ },
196
+ "language_info": {
197
+ "codemirror_mode": {
198
+ "name": "ipython",
199
+ "version": 2
200
+ },
201
+ "file_extension": ".py",
202
+ "mimetype": "text/x-python",
203
+ "name": "python",
204
+ "nbconvert_exporter": "python",
205
+ "pygments_lexer": "ipython2",
206
+ "version": "2.7.6"
207
+ }
208
+ },
209
+ "nbformat": 4,
210
+ "nbformat_minor": 5
211
+ }
mongodb_drafts.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from pymongo.mongo_client import MongoClient
3
+ from pymongo.server_api import ServerApi
4
+ from dotenv import load_dotenv
5
+ load_dotenv()
6
+ import os
7
+
8
+ uri = os.getenv("MONGODB_URI")
9
+ # Create a new client and connect to the server
10
+ client = MongoClient(uri, server_api=ServerApi('1'))
11
+
12
+ # Send a ping to confirm a successful connection
13
+ try:
14
+ client.admin.command('ping')
15
+ print("Pinged your deployment. You successfully connected to MongoDB!")
16
+ except Exception as e:
17
+ print(e)