{ "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 }