Commit 962a8aa8 authored by Ambi's avatar Ambi
Browse files

Adding CBC solver to replay diff

parent 9bca4717
......@@ -5,6 +5,8 @@
Fuzzing usually takes prolonged time and optimization solvers are demanding in resources.
Therefore, it is desirable to deploy the fuzzing procedure on Euler.
First, we need to install the two optimizers of interest, Cplex and Gurobi.
### Cplex
To install Cplex, go to the download page of Cplex and choose the Linux version and download it to your local laptop.
Then you can copy the `.bin` file to the Euler whichever way you like (e.g., `scp` or FileZilla).
On Euler, execute the `.bin` file by
......@@ -27,6 +29,8 @@ It is recommended to install your own python 3.8+ from Miniconda or alike.
Try if it works by typing `python -c "import cplex"`. If it prints nothing, it works.
### Gurobi
Moving on the Gurobi, Euler has Gurobi installed as modules so we only need to load them and install the python API.
For loading,
......@@ -52,6 +56,14 @@ Note: you will need to load the Gurobi module every time you log into Euler. To
module load gurobi/9.5.1
### python-mip with a CBC solver
Additionally we use python-mip with a CBC solver as a quorum for differences.
pip install mip
## Get Seed Inputs
Fuzzing needs a selected pool of seeds to start with.
......@@ -38,6 +38,7 @@ class OptFuzzer(object):
self.all_mutant = []
self.queue = Queue(maxsize=0) # unbounded queue for seeds
self.next_id = 0 # id assigned to the next mutant
print("Initializing seeds")
for s in self.seed:
mutant = {
"id" : self.next_id,
......@@ -47,6 +48,7 @@ class OptFuzzer(object):
self.next_id += 1
print("Seeds initialized")
def get_mutant(self, mut_choice : str) -> dict:
parent = self.queue.get()
......@@ -2,6 +2,7 @@ import xml.etree.ElementTree as ET
from cplex import Cplex
import gurobipy as gp
from mps_util import VerbosePrint
from mip import *
# Solver status
......@@ -175,6 +176,34 @@ class GurobiSolver(Solver):
ret[v.VarName] = v.X
return ret
class CBCSolver(Solver):
""" CBC Solver Wrapper
Python interface documentation:
def __init__(self, verbose = False) -> None:
def __call__(self, mps_file: str) -> dict:
with VerbosePrint(False):
model = Model(sense=MINIMIZE, solver_name=CBC)
status = model.optimize()
ret = dict()
if status == OptimizationStatus.OPTIMAL:
ret['status'] = OPTIMAL
ret["obj_val"] = model.objective_value
elif status == OptimizationStatus.FEASIBLE: #for now marking this as optimal as well
ret['status'] = OPTIMAL
ret["obj_val"] = model.objective_value
elif status == OptimizationStatus.NO_SOLUTION_FOUND:
ret['status'] = INFEASIBLE
return ret
if __name__ == "__main__":
mps_file = "mps/testprob_int.mps"
cpx = CplexSolver()
from optimizer import OPTIMAL, CplexSolver, GurobiSolver
from optimizer import OPTIMAL, CplexSolver, GurobiSolver, CBCSolver
import glob
import os
import sys
......@@ -21,6 +21,16 @@ def replay(path):
if grb_sol["status"] == OPTIMAL:
print(", Obj Val = ", grb_sol["obj_val"], "\n")
def cbc_solution(mps):
cbc = CBCSolver()
cbc_sol = cbc(mps)
print("CBC: Status = ", cbc_sol["status"], end="\n\n" if cbc_sol["status"] != OPTIMAL else "")
if cbc_sol["status"] == OPTIMAL:
print(", Obj Val = ", cbc_sol["obj_val"], "\n")
if __name__ == "__main__":
assert len(sys.argv) >= 2, "Number of arguments must be larger than 2"
\ No newline at end of file
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