JWally / jsLPSolver

Simple OOP javaScript library to solve linear programs, and mixed integer linear programs
The Unlicense
418 stars 69 forks source link

Feasible result generates NaN result #111

Closed aihornmac closed 3 years ago

aihornmac commented 4 years ago

Input lines:

-879.0803237290603u + 879.0803237290603v + x <= -10.39070749736004
1120.9196762709396u + -1120.9196762709396v + x >= 10.432946145723236
-1502.7648401132958u + 1502.7648401132958v + y <= -10.90813093980978
1497.2351598867044u + -1497.2351598867044v + y >= 10.95036958817309
u - v >= -1
min: u + v

Output:

{ feasible: true, result: NaN, bounded: true, u: NaN }
JWally commented 3 years ago

How are you getting to your solution?

var solver = require("../../src/solver");
var fs = require("fs");

var problem = `
-879.0803237290603u + 879.0803237290603v + x <= -10.39070749736004
1120.9196762709396u + -1120.9196762709396v + x >= 10.432946145723236
-1502.7648401132958u + 1502.7648401132958v + y <= -10.90813093980978
1497.2351598867044u + -1497.2351598867044v + y >= 10.95036958817309
u - v >= -1
min: u + v
`;

//
// Convert the standard form of an LP
// into a JSON model that this library can
// make use of; and log it
//
var problem = solver.ReformatLP(problem);
console.log(problem);

/*************
{
  opType: 'min',
  optimize: '_obj',
  constraints: {
    __1: { max: -10.39070749736004 },
    __2: { min: 10.432946145723236 },
    __3: { max: -10.90813093980978 },
    __4: { min: 10.95036958817309 },
    __5: { min: -1 }
  },
  variables: {
    u: {__1: -879.0803237290603, __2: 1120.9196762709396,__3: -1502.7648401132958,__4: 1497.2351598867044,__5: 1,_obj: 1},
    v: {__1: 879.0803237290603,__2: -1120.9196762709396,__3: 1502.7648401132958,__4: -1497.2351598867044,__5: -1,_obj: 1},
    x: { __1: 1, __2: 1, __3: 0, __4: 0},
    y: { __1: 0, __2: 0, __3: 1, __4: 1}
  }
}
***************/

//
// Solve the problem...
// and log it
//
var data = solver.Solve(problem);
console.log(data);
/***
{ feasible: true, result: 0.01181998, bounded: true, u: 0.01181998 }
*///

Which also seems to tie out when you model it in excel: image

I'm going to close this; but if this doesn't solve your issue, please feel free to re-open. Thanks, -JWW