Stick to constraint parsing convention and refactor fuzzer harness.

This commit is contained in:
Bhargava Shastry
2022-03-01 16:52:29 +01:00
parent 5535bf90e2
commit 3e88f7f85a
4 changed files with 73 additions and 52 deletions
@@ -33,7 +33,7 @@ string ConstraintGenerator::generate()
constraint += to_string(zeroOrOne());
for (int j = 0; j < numFactors(); j++)
if (bernoulliDist(s_piecewiseConstantProb))
constraint += "," + to_string(randomMinusOneToOne());
constraint += ",0";
else
constraint += "," + to_string(randomInteger());
constraint += "\n";
@@ -90,7 +90,7 @@ struct ConstraintGenerator
/// Largest value of a factor in linear constraint
static constexpr int s_maxFactor = 100;
/// Probability that a factor in the range of [-1, 1] is chosen
static constexpr double s_piecewiseConstantProb = 0.25;
static constexpr double s_piecewiseConstantProb = 0.75;
};
}
@@ -32,11 +32,7 @@ LinearExpression FuzzerSolverInterface::linearExpression(vector<int> _factors)
LinearExpression lexp;
lexp.resize(_factors.size());
for (auto&& [index, value]: _factors | ranges::views::enumerate)
// Move constant term to RHS.
if (index == 0)
lexp[index] = -rational{value};
else
lexp[index] = rational{value};
lexp[index] = rational{value};
return lexp;
}