em70
em70

Reputation: 6081

Microsoft Solver Foundation constraint

I'm trying to use Microsoft Solver Foundation 2 to solve a fairly complicated situation, however I'm stuck with an UnsupportedModelException even when I dumb down the model as much as possible.
Does anyone have an idea of what I'm doing wrong?
Following is the least example required to reproduce the problematic behavior.

var ctx = SolverContext.GetContext();
var model = ctx.CreateModel();
var someConstant = 1337.0;

var decisionA = new Decision(Domain.Real, "decisionA");
var decisionB = new Decision(Domain.Real, "decisionB");
var decisionC = new Decision(Domain.Real, "decisionC");

model.AddConstraint("ca", decisionA <= someConstant);
model.AddConstraint("cb", decisionB <= someConstant);
model.AddConstraint("cc", decisionC <= someConstant);

model.AddConstraint("mainConstraint", Model.Equal(Model.Sum(Model.Abs(decisionA), decisionB, decisionC), someConstant))

model.AddDecisions(decisionA, decisionB, decisionC);

model.AddGoal("myComplicatedGoal", GoalKind.Minimize, decisionC);

var solution = ctx.Solve();

solution.GetReport().WriteTo(Console.Out);

Console.ReadKey();

Please consider that my actual model should include, once complete, a few constraints in the form of aa+ba <= someValue, so if what I'm willing to do ultimately isn't supported, please let me know in advance. If that's the case I'd also appreciate a suggestion of some other solver with a .NET friendly interface that I could use (only well-known commercial packages, please).

Thanks in advance

Upvotes: 1

Views: 2498

Answers (2)

Nathan Brixius
Nathan Brixius

Reputation: 289

I think you need to add the decisions to the model before you use them in the constraints. If you add this line after creating the Decisions your code works for me:

model.AddDecisions(decisionA, decisionB, decisionC);

Nathan

Upvotes: 2

ZXX
ZXX

Reputation: 4762

Grab the source from this link and try (it has several Model.Abs). If it dies then something is wrong with your setup and the shortest solution is to uninstall, reboot and reinstall.

http://geekswithblogs.net/cyoung/archive/2009/02/25/129672.aspx

OK, now that you mentioned quadratic constraints, at least Express version definitely dosn't support them:

http://code.msdn.microsoft.com/solverfoundation/Thread/View.aspx?ThreadId=2756

Enterprise version might but it costs $$$$ - if you got "Academic Enterprise" it's still without Gurobi solver so before thinking about parting from your moneys it would be good to send them specific questions ( http://gurobi.com/ ) and ask for some guarantee in case they say it would handle it but it doesn't.

Upvotes: 1

Related Questions