Commit e4e7c983 authored by Bowen Wu's avatar Bowen Wu
Browse files

Merge branch 'dev' of gitlab.ethz.ch:asridhar/fuzzopt

parents a7893b16 4df35223
......@@ -19,7 +19,7 @@ class ScaleMut(MutantMethod):
self.hi = hi
def __call__(self, mps):
scale = random.randrange(self.lo, self.hi)
scale = self.lo + random.random()*(self.hi - self.lo)
mps["obj_coeff"] *= scale
mps["con_mat"] *= scale
......@@ -77,6 +77,13 @@ class FlipSignMut(MutantMethod):
self.inc_cnt()
return mps
class NoOpMut(MutantMethod):
def __init__(self) -> None:
super().__init__()
def __call__(self, mps):
return mps
if __name__ == "__main__":
test_mps = "mps/testprob.mps"
......
......@@ -8,7 +8,7 @@ from typing import List
from queue import Queue
from generator import MPSProgram
from mps_mut import DenseMatMut, ScaleMut, SparseMatMut, FlipSignMut
from mps_mut import DenseMatMut, ScaleMut, SparseMatMut, FlipSignMut, NoOpMut
from mps_util import load_mps_dict
from optimizer import OPTIMAL, CplexSolver, GurobiSolver
......@@ -22,6 +22,7 @@ class OptFuzzer(object):
save_path : str, checkpoint_freq : int, checkpoint_path : str, diff_path: str, rel_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()
self.next_mut = 0
self.n_mut = len(self.mut_method)
self.cplex = cplex # cplex solver
......@@ -50,7 +51,7 @@ class OptFuzzer(object):
self.queue.put_nowait(mutant)
print("Seeds initialized")
def get_mutant(self, mut_choice : str) -> dict:
def get_mutant(self, mut_choice : str, nr_mutations: int = 4) -> dict:
parent = self.queue.get()
mps = parent["mps"]
idx = 0
......@@ -66,7 +67,17 @@ class OptFuzzer(object):
print(f"Unsupported mutant choice {mut_choice}")
os.abort()
mps_prime = self.mut_method[idx](mps)
print("========== GOING TO MUTATE ============")
if mut_choice == 'random':
mps_prime = mps
for _ct in range(nr_mutations):
idx = random.randint(0, self.n_mut - 1)
mut_method = self.no_op_mut_method if (random.random() < 0.5) else self.mut_method[idx]
print('Mutating using ', mut_method)
mps_prime = mut_method(mps_prime)
else:
mps_prime = self.mut_method[idx](mps)
ret = {
"id" : self.next_id,
"parent" : [parent["id"]], # root seed, no parent
......@@ -176,7 +187,7 @@ def main():
for m in args.mut_methods:
c = None
if m == "ScaleMut":
c = ScaleMut(0.5)
c = ScaleMut(0.3,2.5)
elif m == "SparseMatMut":
c = SparseMatMut(0.5)
elif m == "DenseMatMut":
......
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