Exemple #1
0
 public void Test(Problem problem, uint expectedValue, bool[] expectedTaken, string comment)
 {
     bool[] taken;
     var value = Knapsack.Pack(problem.Capacity, problem.Values, problem.Weights, out taken);
     TestValid(problem, value, taken);
     Assert.That(value, Is.EqualTo(expectedValue));
     Assert.That(taken, Is.EqualTo(expectedTaken));
 }
Exemple #2
0
 public void TestValid(Problem problem, uint value, bool[] taken)
 {
     var usedCapacity = 0u;
     var calcValue = 0u;
     Assert.That(taken.Length, Is.EqualTo(problem.Values.Length));
     for (var i = 0; i < taken.Length; ++i)
     {
         if (!taken[i]) continue;
         usedCapacity += problem.Weights[i];
         calcValue += problem.Values[i];
     }
     Assert.That(usedCapacity, Is.LessThanOrEqualTo(problem.Capacity));
     Assert.That(calcValue, Is.EqualTo(value));
 }
 public void SetVarX(Problem p)
 {
     p.SetPredeterminedValue("x", true, SATVariable.DeterminationState.Preinitialized);
 }