Commit 39a53577 authored by Bowen Wu's avatar Bowen Wu
Browse files

Add MoreIntMut and FlipObjSense mutations

parent e4e7c983
......@@ -84,6 +84,38 @@ class NoOpMut(MutantMethod):
def __call__(self, mps):
return mps
class MoreIntMut(MutantMethod):
def __init__(self, prob) -> None:
super().__init__()
self.prob = prob
def __call__(self, mps):
# Produce more integral constraints
bnd_name = mps["bnd_names"][0]
for i in range(len(mps["col_types"])):
if mps["col_types"][i] != "integral" and random.random() < self.prob:
mps["col_types"][i] = "integral"
tmp = mps["bnd"][bnd_name]['LO'][i]
mps["bnd"][bnd_name]['LO'][i] = int(tmp) if tmp != -np.inf else -np.inf
tmp = mps["bnd"][bnd_name]['UP'][i]
mps["bnd"][bnd_name]['UP'][i] = int(tmp) if tmp != np.inf else np.inf
self.inc_cnt()
return mps
# This mutation has to be applied with other mutations
# otherwise it's deterministic
class FlipObjSense(MutantMethod):
def __init__(self) -> None:
super().__init__()
def __call__(self, mps):
if mps["objsense"] == "" or mps["objsense"] == "MINIMIZE":
mps["objsense"] = "MAXIMIZE"
else:
mps["objsense"] = "MINIMIZE"
self.inc_cnt()
return mps
if __name__ == "__main__":
test_mps = "mps/testprob.mps"
......@@ -91,8 +123,12 @@ if __name__ == "__main__":
smm = SparseMatMut(prob = 0.5)
dmm = DenseMatMut(prob = 0.9)
fsm = FlipSignMut(prob = 0.9)
mim = MoreIntMut(prob = 0.3)
fos = FlipObjSense()
print_mps_dict(sm(load_mps_dict(test_mps)))
print_mps_dict(smm(load_mps_dict(test_mps)))
print_mps_dict(dmm(load_mps_dict(test_mps)))
print_mps_dict(fsm(load_mps_dict(test_mps)))
\ No newline at end of file
print_mps_dict(fsm(load_mps_dict(test_mps)))
print_mps_dict(mim(load_mps_dict(test_mps)))
print_mps_dict(fos(load_mps_dict(test_mps)))
\ No newline at end of file
......@@ -8,7 +8,7 @@ from typing import List
from queue import Queue
from generator import MPSProgram
from mps_mut import DenseMatMut, ScaleMut, SparseMatMut, FlipSignMut, NoOpMut
from mps_mut import DenseMatMut, FlipObjSense, ScaleMut, SparseMatMut, FlipSignMut, NoOpMut, MoreIntMut
from mps_util import load_mps_dict
from optimizer import OPTIMAL, CplexSolver, GurobiSolver
......@@ -73,7 +73,8 @@ class OptFuzzer(object):
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)
print(self.mut_method)
print('idx = ', idx, ' Mutating using ', mut_method)
mps_prime = mut_method(mps_prime)
else:
mps_prime = self.mut_method[idx](mps)
......@@ -194,6 +195,10 @@ def main():
c = DenseMatMut(0.5)
elif m == "FlipSignMut":
c = FlipSignMut(0.5)
elif m == "MoreIntMut":
c = MoreIntMut(0.3)
elif m == "FlipObjSense":
c = FlipObjSense()
mut_method.append(c)
import glob
......
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