views:

166

answers:

2

Hello,
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 a*a+b*a <= 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

+1  A: 

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

My bad, you're totally right, however as soon as I try to enter any constraint involving multiplication/exponentiation/absolute value of decisions I get that exception again. To reproduce the thing you may just replace decisionA with Model.Abs(decisionA) in the Model.Sum call.
emaster70
A: 

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.

ZXX
This code seems to work correctly, but unfortunately this doesn't fully address my problem. I guess the issues I'm experiencing are at modeling level (looks like SFS can't solve my problem as I've formulated or I'm not using it the right way). Since the problem I'm tackling requires quadratic constraints - it's already a decomposed version of a problem which comes from a system of quartic equations - I either need a way to use quadratic constraints or a modeling trick.
emaster70