JWally / jsLPSolver

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

Need help to get approximate int results #79

Closed myocytebd closed 5 years ago

myocytebd commented 6 years ago

Hi, I have a problem of 114 constraints x 291 variables, where all the variables should be integer. The non-integer problem is solved in <100ms, while the integer problem cannot be solved in five minutes (at least 5000 times slower).

Is there any way to find approximate integer results in a short time? (e.g. 100 times slow down at current problem size) By approximate, I mean that I want to avoid lots of variables with fraction +-0.5, but it is OK if most (do not need all) variables have fraction of +-0.05.

If there are some parameters to control it, I could tune them for my problem. However I didn't find any apparent ones. The precision argument in Solve() doesn't seem to work for integers.

u.txt -> u.js and run with node (at jsLPSolver/..) u.txt model.txt

JWally commented 5 years ago

Sorry for the delay!

Try adding the following to your model:

    "options": {
        "timeout": 10000,
        "tolerance": 0.05
    }

The timeout will return (for milps) the best solution after {{time}} milliseconds and quit. The tolerance option will quit if it can get within {{tolerance}} of a non-integral solution.

When I try this, your model returns the following after 10 seconds:

// jsLPSolver: 10067.674ms
{ feasible: true,
  result: 3667.125,
  bounded: true,
  'sw_10(5_3)_1[1_WordB3]': 10,
  'sw_3(4_0)_0[2_WordB8]': 8,
  'sw_14(6_3)_5[0_WordG3]': 8.5,
  'su_11(6_0)_3': 1.4375,
  'sw_10(5_3)_4[1_WordB10]': 10,
  'sw_1(3_1)_2[1_WordB15]': 2.5,
  'sw_4(4_1)_3[1_WordB18]': 10,
  'sw_9(5_2)_4[0_WordP12]': 5.875,
  'sw_9(5_2)_4[2_WordB12]': 4.125,
  'sw_3(4_0)_2[1_WordB19]': 10,
  'sw_4(4_1)_0[2_WordB12]': 4.875,
  'st_5(4_2)': 1,
  'su_13(6_2)_0': 2.84375,
  'sw_13(6_2)_5[1_WordB2]': 1,
  'sw_3(4_0)_2[0_WordP14]': 0.84375,
  'sw_11(6_0)_5[0_WordP1]': 10,
  'sw_3(4_0)_0[0_WordP4]': 2.84375,
  'sw_3(4_0)_3[1_WordB6]': 10,
  'sw_4(4_1)_2[0_WordP6]': 8.25,
  'sw_11(6_0)_1[0_WordP5]': 10,
  'sw_10(5_3)_2[2_WordB1]': 10,
  'sw_12(6_1)_4[1_WordB14]': 10,
  'sw_9(5_2)_3[1_WordB9]': 0.84375,
  'sw_13(6_2)_0[0_WordP4]': 7.15625,
  'sw_13(6_2)_2[0_WordP2]': 10,
  'sw_13(6_2)_5[0_WordP11]': 9,
  'sw_12(6_1)_2[2_WordB17]': 8.25,
  'sw_14(6_3)_0[1_WordB15]': 7.5,
  'sw_14(6_3)_1[2_WordB20]': 8.75,
  'st_0(3_0)': 5.125,
  'sw_11(6_0)_0[0_WordG0]': 0.9375,
  'sw_1(3_1)_0[0_WordG2]': 2.5,
  'sw_1(3_1)_1[0_WordG1]': 2.5,
  'st_1(3_1)': 2.5,
  'su_0(3_0)_0': 5.125,
  'st_3(4_0)': 10.84375,
  'sw_14(6_3)_4[0_WordG2]': 8.75,
  'sw_3(4_0)_1[1_WordB7]': 10,
  'sw_9(5_2)_3[0_WordP10]': 9.15625,
  'sw_3(4_0)_3[0_WordP10]': 0.84375,
  'st_4(4_1)': 13.125,
  'sw_4(4_1)_1[1_WordB2]': 9,
  'sw_4(4_1)_0[1_WordP3]': 8.25,
  'sw_0(3_0)_2[1_WordB9]': 0.09375,
  'sw_5(4_2)_1[0_WordP11]': 1,
  'sw_9(5_2)_2[1_WordB13]': 10,
  'sw_12(6_1)_2[0_WordG2]': 1.75,
  'sw_5(4_2)_3[0_WordP13]': 1,
  'st_8(5_1)': 1.75,
  'sw_13(6_2)_3[0_WordP0]': 8.25,
  'sw_8(5_1)_0[0_WordP3]': 1.75,
  'sw_8(5_1)_1[2_WordB23]': 1.25,
  'sw_3(4_0)_1[2_WordB16]': 0.84375,
  'sw_8(5_1)_4[0_WordP0]': 1.75,
  'st_9(5_2)': 10,
  'sw_9(5_2)_0[1_WordB24]': 10,
  'sw_9(5_2)_1[0_WordP13]': 9,
  'sw_4(4_1)_1[0_WordP14]': 4.125,
  'sw_4(4_1)_2[1_WordB22]': 4.875,
  'sw_10(5_3)_0[1_WordB0]': 10,
  'st_10(5_3)': 10,
  'sw_12(6_1)_0[2_WordB16]': 5.40625,
  'sw_10(5_3)_3[1_WordB11]': 10,
  'sw_12(6_1)_5[2_WordB5]': 10,
  'st_11(6_0)': 10,
  'sw_4(4_1)_3[0_WordP12]': 3.125,
  'sw_11(6_0)_0[2_WordB9]': 9.0625,
  'sw_11(6_0)_2[0_WordP7]': 10,
  'sw_8(5_1)_3[0_WordP6]': 1.75,
  'sw_11(6_0)_4[0_WordG1]': 10,
  'st_12(6_1)': 10,
  'sw_12(6_1)_0[0_WordG0]': 4,
  'sw_12(6_1)_1[2_WordB4]': 10,
  'sw_13(6_2)_4[0_WordP8]': 10,
  'sw_12(6_1)_3[1_WordB21]': 10,
  'sw_11(6_0)_3[0_WordG0]': 8.5625,
  'st_13(6_2)': 10,
  'su_12(6_1)_0': 0.59375,
  'sw_13(6_2)_1[0_WordP9]': 10,
  'sw_9(5_2)_1[2_WordB12]': 1,
  'sw_0(3_0)_2[0_WordP14]': 5.03125,
  'sw_13(6_2)_3[2_WordB17]': 1.75,
  'sw_0(3_0)_1[1_WordB22]': 5.125,
  'st_14(6_3)': 8.75,
  'sw_14(6_3)_0[2_WordB20]': 1.25,
  'sw_14(6_3)_2[2_WordB16]': 3.75,
  'sw_14(6_3)_2[0_WordG3]': 5,
  'sw_14(6_3)_3[2_WordB23]': 8.75,
  'sw_14(6_3)_5[2_WordB8]': 0.25,
  'sw_8(5_1)_1[0_WordG2]': 0.5,
  'sw_8(5_1)_2[2_WordB8]': 1.75,
  'sw_5(4_2)_2[0_WordP12]': 1,
  'sw_5(4_2)_0[0_WordG1]': 1 }