0

I'm currently solving a linear equation system with MS-Solver-Foundation. I were able to solve the problem with it and I'm now trying to make it more dynamic (so that I don't have to change the code each time the problem changes).

I got multiple constrains of the type:

model.AddConstraint("bottleneck_1", flow[0] + flow[3] + flow[5] + flow[6] + flow[8] + flow[11] + s + overflow[0] == Cmin[0]);
model.AddConstraint("bottleneck_2", flow[1] + flow[2] + flow[4] + s + overflow[1] == Cmin[1]);

Where the flow[i] and overflow[i] are Decision (so of the type class). Now I'm trying to add all those constraints in a for loop. For that I created a list that contains all parts of the left side (so all flow, overflow and s needed for one constraint) before and now I'm trying to do something like:

for (int i = 0; i < Bottelnecknumber; i++)
{
    model.AddConstraint("bottleneck_" + i, sum(Bottelneck[i]) == Cmin[i]);
}

which failed. I also tried to use SumTermBuilder:

List<SumTermBuilder> Bottelneck = new List<SumTermBuilder>();
for (int i = 0; i < Bottelnecknumber; i++)
{
    Bottelneck.Add( new SumTermBuilder(0));
    Bottelneck[i].Add(s);
    Bottelneck[i].Add(overflow[i]);
}
for(int i = 0; i < routenumber; i++)
{
    for(int j = 0; j < Bottelnecknumber; j++)
    {
        if (Route[i].uses[Bottelneckplace[j]])
        {
            Bottelneck[i].Add(flow[i]);
        }
    }
}
for (int i = 0; i < Bottelnecknumber; i++)
{
    model.AddConstraint("bottleneck_" + i,  Bottelneck[i].Equals(Cmin[i]));
}

But that also failed because I then get the solution 0 for everything, which isn't right.

My question is now: How can I create this sum on the left part of the equation in a constraint without manually writing it down, so that I only need one for loop?

hanss314
  • 1
  • 2
  • I formated your code a little and fixed some typos. Since I don't edit code in questions: I guess `fluesse[6]` should be `flow[6]`? – René Vogt Jan 11 '17 at 12:48
  • Yeah my bad i changed it so should be right now. I also noticed that .Equals() gives a bool back, which is wrong here and i should use .ToTerm()==Cmin[i], so its working now. – hanss314 Jan 11 '17 at 13:15

0 Answers0