JWally / jsLPSolver

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

Unexpected result #70

Closed nikogosovd closed 6 years ago

nikogosovd commented 6 years ago

Thank you for implementing and supporting such a great tool!

I was playing with the an example and modified it to the following:

var solver = require('./src/solver'),
  results,
  model = {
    optimize: 'b',
    opType: 'min',
    constraints: {
      a: { min: 350 },
      b: { min: 1000 },
      c: { min: 60, max: 80 },
      d: { min: 0.8, max : 10 },
      e: { min: 12 },
      f: { min: 215},
      g: { min: 28 },
      h: { min: 10 },
      i: { min: 18 },
      j: { min: 65, max: 2500 },
    },
    variables: {
      var1:  { a: 1, b: 44.7, c: 1411, d: 2,    e: 365, f: 0,     g: 55.4, h: 33.3, i: 441, j: 0 },
      var2:  { a: 1, b: 11.6, c: 418,  d: 0.7,  e: 54,  f: 0,     g: 3.2,  h: 1.9,  i: 68,  j: 0 },
      var3:  { a: 1, b: 11.8, c: 377,  d: 14.4, e: 175, f: 0,     g: 14.4, h: 8.8,  i: 114, j: 0 },
      var4:  { a: 1, b: 11.4, c: 252,  d: 0.1,  e: 56,  f: 0,     g: 13.5, h: 2.3,  i: 68,  j: 0 },
      var5:  { a: 1, b: 36.0, c: 897,  d: 1.7,  e: 99,  f: 30.9,  g: 17.4, h: 7.9,  i: 106, j: 0 },
      var6:  { a: 1, b: 28.6, c: 680,  d: 0.8,  e: 80,  f: 0,     g: 10.6, h: 1.6,  i: 110, j: 0 },
      var7:  { a: 1, b: 21.2, c: 460,  d: 0.6,  e: 41,  f: 0,     g: 2,    h: 4.8,  i: 60,  j: 0 },
      var8:  { a: 1, b: 25.3, c: 907,  d: 5.1,  e: 341, f: 0,     g: 37.1, h: 8.9,  i: 64,  j: 0 },
      var9:  { a: 1, b: 15.0, c: 488,  d: 2.5,  e: 115, f: 0,     g: 13.8, h: 8.5,  i: 126, j: 0 },
      var10: { a: 1, b: 12.2, c: 484,  d: 2.7,  e: 125, f: 0,     g: 13.9, h: 6.4,  i: 160, j: 0 },
      var11: { a: 1, b: 12.4, c: 439,  d: 1.1,  e: 82,  f: 0,     g: 9.9,  h: 3,    i: 66,  j: 0 },
      var12: { a: 1, b: 8.0,  c: 130,  d: 0.4,  e: 31,  f: 18.9,  g: 2.8,  h: 3,    i: 17,  j: 0 },
      var13: { a: 1, b: 12.5, c: 288,  d: 0.5,  e: 50,  f: 0,     g: 0,    h: 0,    i: 0,   j: 0 },
      var14: { a: 1, b: 6.1,  c: 310,  d: 10.5, e: 18,  f: 16.8,  g: 4,    h: 16,   i: 7,   j: 177 },
      var15: { a: 1, b: 8.4,  c: 422,  d: 15.1, e: 9,   f: 26,    g: 3,    h: 23.5, i: 11,  j: 60 },
      var16: { a: 1, b: 10.8, c: 9,    d: 0.2,  e: 3,   f: 44.2,  g: 0,    h: 0.2,  i: 2,   j: 0 },
      var17: { a: 1, b: 20.6, c: 17,   d: 0.6,  e: 6,   f: 55.8,  g: 0.2,  h: 0,    i: 0,   j: 0 },
      var18: { a: 1, b: 2.9,  c: 238,  d: 1.0,  e: 52,  f: 18.6,  g: 2.8,  h: 6.5,  i: 1,   j: 0 },
      var19: { a: 1, b: 7.4,  c: 448,  d: 16.4, e: 19,  f: 28.1,  g: 0.8,  h: 10.3, i: 4,   j: 0 },
      var20: { a: 1, b: 3.5,  c: 49,   d: 1.7,  e: 3,   f: 16.9,  g: 0.6,  h: 2.5,  i: 0,   j: 17 },
      var21: { a: 1, b: 15.7, c: 661,  d: 1.0,  e: 48,  f: 0,     g: 9.6,  h: 8.1,  i: 471, j: 0 },
      var22: { a: 1, b: 8.6,  c: 18,   d: 0.2,  e: 8,   f: 2.7,   g: 0.4,  h: 0.5,  i: 0,   j: 0 },
      var23: { a: 1, b: 20.1, c: 0,    d: 0,    e: 0,   f: 0,     g: 0,    h: 0,    i: 0,   j: 0 },
      var24: { a: 1, b: 41.7, c: 0,    d: 0,    e: 0,   f: 0.2,   g: 0,    h: 0.5,  i: 5,   j: 0 },
      var25: { a: 1, b: 2.9,  c: 166,  d: 0.1,  e: 34,  f: 0.2,   g: 2.1,  h: 2.9,  i: 69,  j: 0 },
      var26: { a: 1, b: 2.2,  c: 214,  d: 0.1,  e: 32,  f: 0.4,   g: 2.5,  h: 2.4,  i: 87,  j: 0 },
      var27: { a: 1, b: 3.4,  c: 213,  d: 0.1,  e: 33,  f: 0,     g: 0,    h: 2,    i: 0,   j: 0 },
      var28: { a: 1, b: 3.6,  c: 309,  d: 0.2,  e: 46,  f: 0.4,   g: 1,    h: 4,    i: 120, j: 0 },
      var29: { a: 1, b: 8.5,  c: 404,  d: 0.2,  e: 62,  f: 0,     g: 0.9,  h: 0,    i: 0,   j: 0 },
      var30: { a: 1, b: 2.2,  c: 333,  d: 0.2,  e: 139, f: 169.2, g: 6.4,  h: 50.8, i: 316, j: 525 },
      var31: { a: 1, b: 3.1,  c: 245,  d: 0.1,  e: 20,  f: 0,     g: 2.8,  h: 3.9,  i: 86,  j: 0 },
      var32: { a: 1, b: 3.3,  c: 140,  d: 0.1,  e: 15,  f: 0,     g: 1.7,  h: 2.7,  i: 54,  j: 0 },
      var33: { a: 1, b: 3.5,  c: 196,  d: 0.2,  e: 30,  f: 0,     g: 17.4, h: 2.7,  i: 60,  j: 0 },
      var34: { a: 1, b: 4.4,  c: 249,  d: 0.3,  e: 37,  f: 0,     g: 18.2, h: 3.6,  i: 79,  j: 0 },
      var35: { a: 1, b: 10.4, c: 152,  d: 0.2,  e: 23,  f: 0,     g: 1.8,  h: 1.8,  i: 71,  j: 0 },
      var36: { a: 1, b: 6.7,  c: 212,  d: 0.2,  e: 31,  f: 0,     g: 9.9,  h: 3.3,  i: 50,  j: 0 },
      var37: { a: 1, b: 18.8, c: 164,  d: 0.1,  e: 26,  f: 0,     g: 1.4,  h: 1.8,  i: 0,   j: 0 },
      var38: { a: 1, b: 1.8,  c: 184,  d: 0.1,  e: 30,  f: 0.1,   g: 0.9,  h: 1.8,  i: 68,  j: 46 },
      var39: { a: 1, b: 1.7,  c: 156,  d: 0.1,  e: 24,  f: 0,     g: 1.4,  h: 2.4,  i: 57,  j: 0 },
      var40: { a: 1, b: 5.8,  c: 705,  d: 6.8,  e: 45,  f: 3.5,   g: 1,    h: 4.9,  i: 209, j: 0 },
      var41: { a: 1, b: 5.8,  c: 27,   d: 0.5,  e: 36,  f: 7.3,   g: 3.6,  h: 2.7,  i: 5,   j: 544 },
      var42: { a: 1, b: 4.9,  c: 60,   d: 0.4,  e: 30,  f: 17.4,  g: 2.5,  h: 3.5,  i: 28,  j: 498 },
      var43: { a: 1, b: 1.0,  c: 21,   d: 0.5,  e: 14,  f: 0,     g: 0.5,  h: 0,    i: 4,   j: 952 },
      var44: { a: 1, b: 2.2,  c: 40,   d: 1.1,  e: 18,  f: 11.1,  g: 3.6,  h: 1.3,  i: 10,  j: 1998 },
      var45: { a: 1, b: 2.4,  c: 138,  d: 3.7,  e: 80,  f: 69,    g: 4.3,  h: 5.8,  i: 37,  j: 862 },
      var46: { a: 1, b: 2.6,  c: 125,  d: 4.0,  e: 36,  f: 7.2,   g: 9,    h: 4.5,  i: 26,  j: 5369 },
      var47: { a: 1, b: 2.7,  c: 73,   d: 2.8,  e: 43,  f: 188.5, g: 6.1,  h: 4.3,  i: 89,  j: 608 },
      var48: { a: 1, b: 0.9,  c: 51,   d: 3.0,  e: 23,  f: 0.9,   g: 1.4,  h: 1.4,  i: 9,   j: 313 },
      var49: { a: 1, b: 0.4,  c: 27,   d: 1.1,  e: 22,  f: 112.4, g: 1.8,  h: 3.4,  i: 11,  j: 449 },
      var50: { a: 1, b: 5.8,  c: 166,  d: 3.8,  e: 59,  f: 16.6,  g: 4.7,  h: 5.9,  i: 21,  j: 1184 },
      var51: { a: 1, b: 14.3, c: 336,  d: 1.8,  e: 118, f: 6.7,   g: 29.4, h: 7.1,  i: 198, j: 2522 },
      var52: { a: 1, b: 1.1,  c: 106,  d: 0,    e: 138, f: 918.4, g: 5.7,  h: 13.8, i: 33,  j: 2755 },
      var53: { a: 1, b: 9.6,  c: 138,  d: 2.7,  e: 54,  f: 290.7, g: 8.4,  h: 5.4,  i: 83,  j: 1912 },
      var54: { a: 1, b: 3.7,  c: 20,   d: 0.4,  e: 10,  f: 21.5,  g: 0.5,  h: 1,    i: 31,  j: 196 },
      var55: { a: 1, b: 3.0,  c: 8,    d: 0.3,  e: 8,   f: 0.8,   g: 0.8,  h: 0.8,  i: 5,   j: 81 },
      var56: { a: 1, b: 2.4,  c: 16,   d: 0.4,  e: 8,   f: 2,     g: 2.8,  h: 0.8,  i: 7,   j: 399 },
      var57: { a: 1, b: 0.4,  c: 33,   d: 0.3,  e: 12,  f: 16.3,  g: 1.4,  h: 2.1,  i: 17,  j: 272 },
      var58: { a: 1, b: 1.0,  c: 54,   d: 2,    e: 65,  f: 53.9,  g: 1.6,  h: 4.3,  i: 32,  j: 431 },
      var59: { a: 1, b: 7.5,  c: 364,  d: 4,    e: 134, f: 3.5,   g: 8.3,  h: 7.7,  i: 56,  j: 0 },
      var60: { a: 1, b: 5.2,  c: 136,  d: 0.2,  e: 16,  f: 12,    g: 1.6,  h: 2.7,  i: 42,  j: 218 },
      var61: { a: 1, b: 2.3,  c: 136,  d: 0.6,  e: 45,  f: 34.9,  g: 4.9,  h: 2.5,  i: 37,  j: 370 },
      var62: { a: 1, b: 1.3,  c: 63,   d: 0.7,  e: 38,  f: 53.2,  g: 3.4,  h: 2.5,  i: 36,  j: 1253 },
      var63: { a: 1, b: 1.6,  c: 71,   d: 0.6,  e: 43,  f: 57.9,  g: 3.5,  h: 2.4,  i: 67,  j: 862 },
      var64: { a: 1, b: 8.5,  c: 87,   d: 1.7,  e: 173, f: 86.8,  g: 1.2,  h: 4.3,  i: 55,  j: 57 },
      var65: { a: 1, b: 12.8, c: 99,   d: 2.5,  e: 154, f: 85.7,  g: 3.9,  h: 4.3,  i: 65,  j: 257 },
      var66: { a: 1, b: 13.5, c: 104,  d: 2.5,  e: 136, f: 4.5,   g: 6.3,  h: 1.4,  i: 24,  j: 136 },
      var67: { a: 1, b: 20.0, c: 1367, d: 4.2,  e: 345, f: 2.9,   g: 28.7, h: 18.4, i: 162, j: 0 },
      var68: { a: 1, b: 17.4, c: 1055, d: 3.7,  e: 459, f: 5.1,   g: 26.9, h: 38.2, i: 93,  j: 0 },
      var69: { a: 1, b: 26.9, c: 1691, d: 11.4, e: 792, f: 0,     g: 38.4, h: 24.6, i: 217, j: 0 },
      var70: { a: 1, b: 0,    c: 0,    d: 0,    e: 0,   f: 0,     g: 4,    h: 5.1,  i: 50,  j: 0 },
      var71: { a: 1, b: 0,    c: 0,    d: 0,    e: 0,   f: 0,     g: 0,    h: 2.3,  i: 42,  j: 0 },
      var72: { a: 1, b: 8.7,  c: 237,  d: 3,    e: 72,  f: 0,     g: 2,    h: 11.9, i: 40,  j: 0 },
      var73: { a: 1, b: 8.0,  c: 77,   d: 1.3,  e: 39,  f: 0,     g: 0.9,  h: 3.4,  i: 14,  j: 0 },
      var74: { a: 1, b: 34.9, c: 0,    d: 0,    e: 0,   f: 0,     g: 0,    h: 0,    i: 0,   j: 0 },
      var75: { a: 1, b: 14.7, c: 0,    d: 0.5,  e: 74,  f: 0,     g: 0,    h: 0,    i: 5,   j: 0 },
      var76: { a: 1, b: 9.0,  c: 0,    d: 10.3, e: 244, f: 0,     g: 1.9,  h: 7.5,  i: 146, j: 0 },
      var77: { a: 1, b: 6.4,  c: 11,   d: 0.4,  e: 7,   f: 0.2,   g: 0.2,  h: 0.4,  i: 3,   j: 0 },
    },
    ints: {
      var1: 1,
      var2: 1,
      var3: 1,
      var4: 1,
      var5: 1,
      var6: 1,
      var7: 1,
      var8: 1,
      var9: 1,
      var10: 1,
      var11: 1,
      var12: 1,
      var13: 1,
      var14: 1,
      var15: 1,
      var16: 1,
      var17: 1,
      var18: 1,
      var19: 1,
      var20: 1,
      var21: 1,
      var22: 1,
      var23: 1,
      var24: 1,
      var25: 1,
      var26: 1,
      var27: 1,
      var28: 1,
      var29: 1,
      var30: 1,
      var31: 1,
      var32: 1,
      var33: 1,
      var34: 1,
      var35: 1,
      var36: 1,
      var37: 1,
      var38: 1,
      var39: 1,
      var40: 1,
      var41: 1,
      var42: 1,
      var43: 1,
      var44: 1,
      var45: 1,
      var46: 1,
      var47: 1,
      var48: 1,
      var49: 1,
      var50: 1,
      var51: 1,
      var52: 1,
      var53: 1,
      var54: 1,
      var55: 1,
      var56: 1,
      var57: 1,
      var58: 1,
      var59: 1,
      var60: 1,
      var61: 1,
      var62: 1,
      var63: 1,
      var64: 1,
      var65: 1,
      var66: 1,
      var67: 1,
      var68: 1,
      var69: 1,
      var70: 1,
      var71: 1,
      var72: 1,
      var73: 1,
      var74: 1,
      var75: 1,
      var76: 1,
      var77: 1,
    },
  };

results = solver.Solve(model, null, false, true);
console.log(results);

And I get the following result:

{ feasible: true,
  result: -Infinity,
  bounded: false,
  var51: 1304362.00000001,
  var70: 1.6352736395150337e+36,
  var50: 248520187561305870000,
  var4: 184035095172865620000,
  var74: 131707210,
  var71: 312,
  var8: 114959664727729370000,
  var36: 1.63550998754279e+21,
  var59: 1349766,
  var64: 2.841424062706935e+21,
  var44: 250051195134805930000,
  var34: 5.138361402535557e+21,
  var30: 5.927771967540281e+21,
  var43: 6.170253407483763e+21 }

Especially strange thing is that I've got -Infinity for b while I have a constraint for that attribute —b: { min: 1000 } — and it's being checked (the last argument to the Solve function).

The second issue I've got when eliminated a constraint from the above example — I'm still waiting for result. Does it hang?

lvenerosy commented 6 years ago

There is a problem that I will investigate from next week. It may or may not be linked to your issue but I will use it as a test case.

lvenerosy commented 6 years ago

Sorry I was partying too hard. It is still in the works.

JWally commented 6 years ago

@nikogosovd is this more in line with what you were expecting? If so I might have found the culprit!

image

lvenerosy commented 6 years ago

I will try your instance soon but you can try again if/when https://github.com/JWally/jsLPSolver/pull/64 gets merged.