def run_experiments(machine_num, fixVN=0): machine_dpath = opath.join(exp_dpath, 'm%d' % machine_num) if not fixVN: gen_cFile('CWL4') from CWL4 import run as CWL4_run assert opath.exists(machine_dpath) gen_prmts(machine_dpath) else: gen_cFile('CWL4_fixVN') from CWL4_fixVN import run as CWL4_run prmt_dpath = opath.join(machine_dpath, 'prmt') log_dpath = opath.join(machine_dpath, 'log') sol_dpath = opath.join(machine_dpath, 'sol') for path in [log_dpath, sol_dpath]: if opath.exists(path): shutil.rmtree(path) os.mkdir(path) problems_fpaths = [ opath.join(prmt_dpath, fn) for fn in os.listdir(prmt_dpath) if fn.endswith('.pkl') ] problems_fpaths.sort() for fpath in problems_fpaths: with open(fpath, 'rb') as fp: prmt = pickle.load(fp) problemName = prmt['problemName'] cwl_no = 4 etc = { 'solFilePKL': opath.join(sol_dpath, 'sol_%s_CWL%d.pkl' % (problemName, cwl_no)), 'solFileCSV': opath.join(sol_dpath, 'sol_%s_CWL%d.csv' % (problemName, cwl_no)), 'solFileTXT': opath.join(sol_dpath, 'sol_%s_CWL%d.txt' % (problemName, cwl_no)), 'logFile': opath.join(log_dpath, '%s_CWL%d.log' % (problemName, cwl_no)), 'itrFileCSV': opath.join(log_dpath, '%s_itrCWL%d.csv' % (problemName, cwl_no)), } CWL4_run(prmt, etc)
import os.path as opath import multiprocessing import datetime, time import csv, pickle import numpy as np from gurobipy import * # from _util_cython import gen_cFile prefix = 'PD_IH' gen_cFile(prefix) from PD_IH import run as PD_IH_run NUM_CORES = int(multiprocessing.cpu_count() * 0.8) EPSILON = 0.00001 def write_log(fpath, contents): with open(fpath, 'a') as f: logContents = '\n\n' logContents += '======================================================================================\n' logContents += '%s\n' % str(datetime.datetime.now()) logContents += '%s\n' % contents logContents += '======================================================================================\n' f.write(logContents) def itr2file(fpath, contents=[]): if not contents: if opath.exists(fpath): os.remove(fpath)
import os.path as opath import multiprocessing import time import pickle, csv import datetime import numpy as np from gurobipy import * # from _util_cython import gen_cFile # gen_cFile('CWL4') from CWL4 import write_log, itr2file, res2file from CWL4 import generate_RMP from CWL4 import NUM_CORES, EPSILON prefix = 'PD_IH' gen_cFile(prefix) from PD_IH import run as PD_IH_run from PD_IH import calc_travelTime def LS_run(prmt, cwl_inputs): T, cP, cC, _delta, t_ij = [ prmt.get(k) for k in ['T', 'cP', 'cC', '_delta', 't_ij'] ] # pi_i, mu = [cwl_inputs.get(k) for k in ['pi_i', 'mu']] C, sC, c0 = [cwl_inputs.get(k) for k in ['C', 'sC', 'c0']] s_c = cwl_inputs['s_c'] mT = cwl_inputs['mT'] #