Commit 0c77884e authored by Bowen Wu's avatar Bowen Wu
Browse files

Fix shallow copy, fix replay timeout

parent 0d5866c7
......@@ -3,6 +3,7 @@ import random
import os
import math
import pickle
from copy import deepcopy
from typing import List
from queue import Queue
......@@ -18,8 +19,15 @@ from optimizer import OPTIMAL, CplexSolver, GurobiSolver
# 3. Collect more stats
class OptFuzzer(object):
MAX_MUTANTS_IN_DIR = 10
def __init__(self, seed : List, mut_method : List, cplex : CplexSolver, gurobi : GurobiSolver,
save_path : str, checkpoint_freq : int, checkpoint_path : str, diff_path: str, abs_tol = 1e-6) -> None:
def __init__(self, seed : List,
mut_method : List,
cplex : CplexSolver,
gurobi : GurobiSolver,
save_path : str,
checkpoint_freq : int,
checkpoint_path : str,
diff_path: str,
abs_tol = 1e-6) -> None:
self.seed = seed # a list of seed mps in dict format
self.mut_method = mut_method # a list of mutation methods
self.no_op_mut_method = NoOpMut()
......@@ -52,9 +60,7 @@ class OptFuzzer(object):
self.queue.put_nowait(mutant)
print("Seeds initialized")
def get_mutant(self, mut_choice : str, nr_mutations: int = 3) -> dict:
parent = self.queue.get()
mps = parent["mps"]
mps = deepcopy(parent["mps"])
idx = 0
if mut_choice == "fixed":
......
from time import time
import xml.etree.ElementTree as ET
from cplex import Cplex
import gurobipy as gp
......@@ -24,9 +25,10 @@ status_text = {
MAX_TIME_LIMIT = 20
class Solver(object):
def __init__(self, verbose = False) -> None:
def __init__(self, verbose = False, timeout = True) -> None:
# by default, the solvers are very talky but we can make it less verbose
self.verbose = verbose
self.timeout = timeout
self.stats = dict()
for k in [OPTIMAL, INFEASIBLE, INF_OR_UNBD, UNBOUNDED, UNKNOWN, TIME_LIMIT_EXCEEDED]:
self.stats[k] = 0
......@@ -48,7 +50,6 @@ class CplexSolver(Solver):
# MIP
101 : OPTIMAL,
102 : OPTIMAL,
103 : INFEASIBLE,
107 : TIME_LIMIT_EXCEEDED,
108 : TIME_LIMIT_EXCEEDED,
115 : INFEASIBLE, # https://www-eio.upc.edu/lceio/manuals/cplex-11/html/usrcplex/solveLP19.html
......@@ -57,8 +58,8 @@ class CplexSolver(Solver):
119 : INF_OR_UNBD
}
def __init__(self, verbose = False) -> None:
super().__init__(verbose)
def __init__(self, verbose = False, timeout = True) -> None:
super().__init__(verbose, timeout)
def __call__(self, mps_file: str) -> dict:
model = Cplex()
......@@ -66,9 +67,10 @@ class CplexSolver(Solver):
model.set_warning_stream(None)
model.set_error_stream(None)
model.set_log_stream(None)
ps = model.create_parameter_set()
ps.add(model.parameters.timelimit, MAX_TIME_LIMIT)
model.set_parameter_set(ps)
if self.timeout:
ps = model.create_parameter_set()
ps.add(model.parameters.timelimit, MAX_TIME_LIMIT)
model.set_parameter_set(ps)
with VerbosePrint(self.verbose):
model.read(mps_file)
......@@ -145,14 +147,15 @@ class GurobiSolver(Solver):
9 : TIME_LIMIT_EXCEEDED,
}
def __init__(self, verbose = False) -> None:
super().__init__(verbose)
def __init__(self, verbose = False, timeout = True) -> None:
super().__init__(verbose, timeout)
def __call__(self, mps_file: str) -> dict:
with VerbosePrint(self.verbose):
model = gp.read(mps_file)
model.setParam("OutputFlag", False)
model.setParam(gp.GRB.Param.TimeLimit, MAX_TIME_LIMIT)
if self.timeout:
model.setParam(gp.GRB.Param.TimeLimit, MAX_TIME_LIMIT)
model.optimize()
if self.get_sol_status(model) == INF_OR_UNBD:
......
......@@ -4,8 +4,8 @@ import os
import sys
def replay(path):
cpx = CplexSolver()
grb = GurobiSolver()
cpx = CplexSolver(timeout=False)
grb = GurobiSolver(timeout=False)
diff_mps = glob.glob(os.path.join(path, "*.mps"))
print(diff_mps)
for mps in diff_mps:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment