{ "cells": [ { "cell_type": "markdown", "source": [ "# JSSEnv Example" ], "metadata": { "collapsed": false }, "id": "87684e89c5a41617" }, { "cell_type": "code", "outputs": [], "source": [], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2025-03-20T14:07:11.519106Z", "start_time": "2025-03-20T14:07:11.516207Z" } }, "id": "d50995faa4b1bbeb", "execution_count": 0 }, { "cell_type": "code", "execution_count": 1, "id": "43e81a39", "metadata": { "ExecuteTime": { "end_time": "2025-03-20T14:07:12.233842Z", "start_time": "2025-03-20T14:07:11.520269Z" } }, "outputs": [], "source": [ "import numpy as np\n", "from JSSEnv.envs import JssEnv" ] }, { "cell_type": "markdown", "id": "6224c9d2", "metadata": { "lines_to_next_cell": 2 }, "source": [ "in this example we create the instance file instead of downloading it, because https://jobshop.jjvh.nl/ is\n", "sometimes down. You can also download the instance from https://jobshop.jjvh.nl/ or use the download utils of\n", "the package.\n", "\n", "Note: this repo also contains .txt files with instances from https://jobshop.jjvh.nl/ in the resources folder. So that\n", " is an alternative to downloading the instances from the website." ] }, { "cell_type": "code", "execution_count": 2, "id": "1102ac81", "metadata": { "ExecuteTime": { "end_time": "2025-03-20T14:07:12.239251Z", "start_time": "2025-03-20T14:07:12.234847Z" } }, "outputs": [], "source": [ "# setup the jsp instance\n", "instance_text = \"\"\"6\t6 \n", "2\t1\t0\t3\t1\t6\t3\t7\t5\t3\t4\t6\n", "1\t8\t2\t5\t4\t10\t5\t10\t0\t10\t3\t4\n", "2\t5\t3\t4\t5\t8\t0\t9\t1\t1\t4\t7\n", "1\t5\t0\t5\t2\t5\t3\t3\t4\t8\t5\t9\n", "2\t9\t1\t3\t4\t5\t5\t4\t0\t3\t3\t1\n", "1\t3\t3\t3\t5\t9\t0\t10\t4\t4\t2\t1\n", "\"\"\"\n", "jsp_std_path = \"ft06.txt\"\n", "# write the instance to a file\n", "with open(jsp_std_path, \"w\") as f:\n", " f.write(instance_text)" ] }, { "cell_type": "code", "execution_count": 3, "id": "9973da59", "metadata": { "ExecuteTime": { "end_time": "2025-03-20T14:07:12.249090Z", "start_time": "2025-03-20T14:07:12.240455Z" } }, "outputs": [], "source": [ "# create the environment\n", "env = JssEnv(env_config={'instance_path': jsp_std_path})" ] }, { "cell_type": "code", "execution_count": 4, "id": "f1378619", "metadata": { "ExecuteTime": { "end_time": "2025-03-20T14:07:12.253750Z", "start_time": "2025-03-20T14:07:12.250232Z" } }, "outputs": [], "source": [ "# reset the environment\n", "obs = env.reset()" ] }, { "cell_type": "code", "execution_count": 5, "id": "b66d90c9", "metadata": { "ExecuteTime": { "end_time": "2025-03-20T14:07:12.261272Z", "start_time": "2025-03-20T14:07:12.254857Z" } }, "outputs": [], "source": [ "# perform a random action till the environment is done\n", "done = False\n", "while not done:\n", " # sample a random action\n", " mask = env.unwrapped.legal_actions.astype(np.int8)\n", " action = env.action_space.sample(mask=mask)\n", " # take a step in the environment\n", " obs, reward, done, info = env.step(action)\n", "\n", " # render the environment" ] }, { "cell_type": "code", "execution_count": 6, "id": "078575db", "metadata": { "ExecuteTime": { "end_time": "2025-03-20T14:07:12.308383Z", "start_time": "2025-03-20T14:07:12.261349Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "makespan: 80\n" ] } ], "source": [ "env.render()\n", "print(f\"makespan: {env.unwrapped.last_time_step}\")" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" }, "kernelspec": { "name": "python3", "language": "python", "display_name": "Python 3 (ipykernel)" } }, "nbformat": 4, "nbformat_minor": 5 }