The new feature onlymutga with new mutation and experiments
This commit is contained in:
parent
345dc16df6
commit
e5b5e8807d
7 changed files with 1339 additions and 0 deletions
267
eo/contrib/irace/expe/gamma/run_irace.ipynb
Normal file
267
eo/contrib/irace/expe/gamma/run_irace.ipynb
Normal file
|
|
@ -0,0 +1,267 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "04867792",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Imports"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 18,
|
||||
"id": "435212a6",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"import numpy as np\n",
|
||||
"import seaborn as sb\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"from matplotlib.ticker import MaxNLocator\n",
|
||||
"import matplotlib.animation\n",
|
||||
"from math import sqrt, log, cos, sin, pi\n",
|
||||
"import numpy as np\n",
|
||||
"import os\n",
|
||||
"import shutil\n",
|
||||
"import re\n",
|
||||
"from subprocess import call\n",
|
||||
"sb.set_style(\"whitegrid\")\n",
|
||||
"#sb.set_palette(\"cubehelix\")\n",
|
||||
"sb.set_palette(\"husl\")\n",
|
||||
"sb.set(font_scale=1) # crazy big\n",
|
||||
"sb.set_style('whitegrid', {'legend.frameon':True})\n",
|
||||
"myfontsize = 12\n",
|
||||
"titlesize = 15\n",
|
||||
"%matplotlib notebook"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "d76bdf6b",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Function to generate the scenario file for irace"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 19,
|
||||
"id": "d86a9ca8",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def scenario(filename=\"scenario.txt\", \n",
|
||||
" parameterFile=\"parameters.txt\", \n",
|
||||
" execDir=\".\", \n",
|
||||
" logFile=\"./irace.Rdata\", \n",
|
||||
" targetRunner = \"target-runner.py\", \n",
|
||||
" maxExperiments = 100000,\n",
|
||||
" digits = 2):\n",
|
||||
" f = open(filename, \"w\")\n",
|
||||
" f.write(\"parameterFile=\" + parameterFile +\"\\n\")\n",
|
||||
" f.write(\"execDir=\" + execDir + \"\\n\")\n",
|
||||
" f.write(\"logFile=\" + logFile + \"\\n\")\n",
|
||||
" f.write(\"targetRunner=\" + targetRunner + \"\\n\")\n",
|
||||
" f.write(\"maxExperiments=\" + maxExperiments + \"\\n\")\n",
|
||||
" f.write(\"digits=\" + digits + \"\\n\")\n",
|
||||
" f.close()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "1213321a",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Function to generate the parameter file for irace"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 20,
|
||||
"id": "70d221c9",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Generate the param file for irace with all configuarable parameters\n",
|
||||
"def parameters(filename=\"parameters.txt\"):\n",
|
||||
" f = open(\"parameters.txt\", \"w\")\n",
|
||||
" f.write(\"# name\\tswitch\\ttype\\tvalues\\n\") # head of the param file\n",
|
||||
" cl_nb_part = 10 # number of category for the custom categorial probabilistic law\n",
|
||||
" for i in range(cl_nb_part-1): # minus 1 slice than the number of categories\n",
|
||||
" f.write(\"slice_prob_%s\\t\\\"\\\"\\tr\\t(0,1)\\n\"%i) # percentage of the residual probability for the slice\n",
|
||||
"\n",
|
||||
" ######################################### NOT USED YET ##########################################\n",
|
||||
" #for i in range(cl_nb_part-1): # minus 1 slice than the number of categories\n",
|
||||
" # f.write(\"slice_size_%s\\t\\\"\\\"\\tr\\t(0,1)\\n\"%i) # percentage of the residual size for the slice\n",
|
||||
" #################################################################################################\n",
|
||||
" f.close()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "65fcb69d",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Fonction to generate problem dedicated target-runner.py"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 21,
|
||||
"id": "a18ba251",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def target_runner(origin=\"irace-config/target-runner.py\", path=\"target-runner.py\", problem=1):\n",
|
||||
" \n",
|
||||
" generalTR = open(origin, \"r\")\n",
|
||||
" dedicatedTR = open(path, \"w\")\n",
|
||||
" for line in generalTR:\n",
|
||||
" if re.search(\"problem = \", line, flags=0):\n",
|
||||
" dedicatedTR.write(\"problem = \" + str(problem) + \"\\n\")\n",
|
||||
" else:\n",
|
||||
" dedicatedTR.write(line)\n",
|
||||
" generalTR.close()\n",
|
||||
" dedicatedTR.close()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "59421dee",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Run script"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 28,
|
||||
"id": "38dfec96",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"results_directory = \"results\"\n",
|
||||
"irace_path = \"/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/irace/bin/irace\"\n",
|
||||
"instances_file = \"instances.txt\"\n",
|
||||
"scenario_file = \"scenario.txt\"\n",
|
||||
"parameters_file = \"parameters.txt\"\n",
|
||||
"target_runner_file = \"target-runner.py\"\n",
|
||||
"\n",
|
||||
"# create or clear the results directory\n",
|
||||
"if not os.path.isdir(results_directory):\n",
|
||||
" os.mkdir(results_directory)\n",
|
||||
" \n",
|
||||
"for pb in range(1,3): # for each problem\n",
|
||||
" # create or clear a subdirectory for the problem\n",
|
||||
" problem_directory = results_directory + \"/problem_%s\"%pb\n",
|
||||
" if os.path.isdir(problem_directory):\n",
|
||||
" shutil.rmtree(problem_directory)\n",
|
||||
" os.mkdir(problem_directory)\n",
|
||||
" \n",
|
||||
" # generate a custom target runner file for the problem\n",
|
||||
" target_runner(path = problem_directory + \"/\" + target_runner_file, problem = pb)\n",
|
||||
"\n",
|
||||
" # copy the config files for iraces\n",
|
||||
" for filename in [instances_file, scenario_file, parameters_file, target_runner_file]:\n",
|
||||
" src = r'irace-config/' + filename\n",
|
||||
" dst = problem_directory + \"/\" + filename\n",
|
||||
" shutil.copyfile(src, dst)\n",
|
||||
" \n",
|
||||
" # run irace for\n",
|
||||
" cmd = [irace_path, \"--scenario\", problem_directory + \"/\" + scenario_file] #, \"&> irace.log\"\n",
|
||||
" call(cmd)\n",
|
||||
"#call(cmd)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 59,
|
||||
"id": "b707ff3b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"shutil.rmtree(\"results\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 25,
|
||||
"id": "460c588e",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"-10"
|
||||
]
|
||||
},
|
||||
"execution_count": 25,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"call([\"../../release/onlymutga\"])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 43,
|
||||
"id": "eb234425",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'problem_1/default.instances'"
|
||||
]
|
||||
},
|
||||
"execution_count": 43,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import shutil\n",
|
||||
"import os\n",
|
||||
"src = r'irace-config/default.instances'\n",
|
||||
"dst = r'problem_1/default.instances'\n",
|
||||
"shutil.copyfile(src, dst)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "7a62c411",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"chmod u+x script.py\n",
|
||||
"cp -a a b"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.8"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue