private void TestSolverOnlyPrice(ISolver solver) { var instanceProvider = new TextReaderInstanceProvider(new StreamReader(string.Format(Path, 10))); var brutteForceSolver = new BrutteForceSolver(); foreach (var instance in instanceProvider.GetInstances()) { var res1 = brutteForceSolver.Solve(instance); var res2 = solver.Solve(instance); Assert.AreEqual(res1.Price, res2.Price, $"Prices are not equal for instance ${instance.Id}."); } }
private static void Test1() { var generator = new RandomInstanceProvider(); var instance = generator.GetInstance(25); Console.WriteLine(instance.Formula); var brutteForceSolver = new BrutteForceSolver(); var simulatedAnnealingSolver = new SimulatedAnnealingSolver(); var solution1 = brutteForceSolver.Solve(instance); var solution2 = simulatedAnnealingSolver.Solve(instance); Console.WriteLine(solution1); Console.WriteLine(solution2); }
public void TestBrutteForce() { // n = 4 // F = (x0 + x2' + x3).(x0' + x1 + x2').(x2 + x3).(x0 + x1 + x2' + x3').(x1' + x2).(x2' + x3') // W = (2, 4, 1, 6) // expected solution: {1, 0, 0, 1}, weight: 8 var formula = new LogicalProductFormula(new IFormula[] { // (x0 + x2' + x3) new LogicalSumFormula(new IFormula[] { new LiteralFormula(0), new NegateFormula(new LiteralFormula(2)), new LiteralFormula(3) }), // (x0' + x1 + x2') new LogicalSumFormula(new IFormula[] { new NegateFormula(new LiteralFormula(0)), new LiteralFormula(1), new NegateFormula(new LiteralFormula(2)), }), // (x2 + x3) new LogicalSumFormula(new IFormula[] { new LiteralFormula(2), new LiteralFormula(3) }), // (x0 + x1 + x2' + x3') new LogicalSumFormula(new IFormula[] { new LiteralFormula(0), new LiteralFormula(1), new NegateFormula(new LiteralFormula(2)), new NegateFormula(new LiteralFormula(3)), }), // (x1' + x2) new LogicalSumFormula(new IFormula[] { new NegateFormula(new LiteralFormula(1)), new LiteralFormula(2) }), // (x2' + x3') new LogicalSumFormula(new IFormula[] { new NegateFormula(new LiteralFormula(2)), new NegateFormula(new LiteralFormula(3)) }) }); Console.WriteLine(formula); var instance = new Instance { Formula = formula, Weights = new [] { 2, 4, 1, 6 } }; var solver = new BrutteForceSolver(); var res = solver.Solve(instance); var expectedConfiguration = 1L | (1L << 3); Assert.AreEqual(expectedConfiguration, res.Configuration); Assert.AreEqual(8, res.Weight); }