Microsoft Solver Foundation - Never returns value

MCAlexandre

New Member
I need to port an excel spreadsheet that uses the solver plugin to an ASP.NET c# site, I'm using the Solver Foundation 3.1 to no avail.The equation is iterative, and two conditions need to be met in order to determine the two decision values.The two decision values on the spreadsheet are set to 1\[code\]Ng = 1Nv = 1\[/code\]Then the goal is to find the MAX of Formula1 when the following conditions are met:\[code\]Decision 1: Formula1 = _naDecision 2: Formula2 = Formula3\[/code\]All formulas use Ng and Nv, hitting solve changes Ng and Nv to satisfy each equation, it takes and average of 22 iterations on the spreadsheet.I've implemented it in c# as follows:\[code\] public class FluxSolver { public FluxSolver(double _na, double _ygo, double _k, double _alpha, double _inletVoidFraction) { var solver = SolverContext.GetContext(); solver.ClearModel(); var model = solver.CreateModel(); var decisionNG = new Decision(Domain.RealNonnegative, "NG"); var decisionNV = new Decision(Domain.RealNonnegative, "NV"); model.AddDecision(decisionNG); model.AddDecision(decisionNV); Term formula1 = (_ygo * decisionNG) + ((1 - _ygo) * decisionNV); model.AddGoal("Goal", GoalKind.Maximize, formula1); model.AddConstraint("Constraint1", ((_inletVoidFraction / _k) * (1 / decisionNG)) == (_alpha * ((1 / decisionNV) - 1))); model.AddConstraint("Constraint2", ( _ygo * decisionNG) + ((1 - _ygo) * decisionNV) == _na); var solution = solver.Solve(); NV = decisionNV.GetDouble(); NG = decisionNG.GetDouble(); Quality = solution.Quality.ToString(); } public double NG { get; set; } public double NV { get; set; } public string Quality { get; set; } }\[/code\]I've been at it for 3 days now and still not making any progress, the solver just loads and and disappears, never times out, doesn't return the values etc. Is there something fundamentally wrong in my code?Any help appreciated!
 
Back
Top