Reputation: 4180
Trying to solve the following problem using Solver foundation:
Given: range: {x | x from double} and points: {(x,y) | x,y from double}
Find piece wise linear function - { (a,b) | a,b from double} where:
Example: range: {1, 2, 3} , points {(1,40), (1.5,40), (2.5,70)}
My solution:
Minimize the following problem with Simplex:
foreach i range add :
var ai = new Decision(Domain.RealRange(0, 100), null);
var bi = new Decision(Domain.RealRange(0, 100), null);
model.AddDecisions(a, b);
foreach point from points that fall in i range add constraint
model.AddConstraints("c{0}".F(pointIdx), a * point.x + b >= point.y);
Then add goal:
model.AddGoal("area", GoalKind.Minimize, goal);
And get the solution:
var solution = context.Solve(new SimplexDirective());
The solution works gives me a right answer but it takes a lot of time for simple case it takes 130 ms. Could you tell me what I am doing wrong? Where can I optimize ? Is Simplex method right for this case? Do we have better software solution then SolverFoundation for optimization.
Upvotes: 2
Views: 1185
Reputation: 5933
try loading your model from OML string, enforce simplex solver to check if your problem is LP
Upvotes: 1