Why runkit.com code returns different values than local code?

117 Views Asked by At

I've double checked that is same Node.js version v12.10.0, same npm package version (javascript-lp-solver 0.4.5), same input and we got different results.

Scenario A


Scenario B

var formulador = require("./src/solver.js");

var modelo = {
  optimize: "custo",
  opType: "min",
  constraints: {
    N: {
      min: 18000.0,
      max: 18800.0
    },
    PCNA: {
      min: 5000.0,
      max: 5800.0
    },
    K: {
      min: 24000.0,
      max: 24800.0
    },
    "I::100268_100328": {
      max: 1.0
    },
    "I::100268_100328_D1": {
      min: 0.0
    },
    "I::100268_100328_D2": {
      min: 0.0
    },
    peso: {
      equal: 1000.0
    }
  },
  variables: {
    "100194": {
      CA: 12.0,
      S: 1.5,
      MG: 6.0,
      peso: 1.0,
      custo: 446.19,
      preco: 446.19
    },
    "100249": {
      K: 60.0,
      peso: 1.0,
      custo: 1964.49,
      preco: 1964.49
    },
    "100268": {
      PCNA: 21.0,
      CA: 18.0,
      S: 10.0,
      PH2O: 16.0,
      peso: 1.0,
      custo: 1192.33,
      preco: 1192.33,
      "I::100268_100328_D1": 1.0,
      "I::100268_100328_D2": -1.0
    },
    "100287": {
      N: 3.0,
      PCNA: 17.0,
      CA: 16.0,
      S: 11.0,
      peso: 1.0,
      custo: 1444.68,
      preco: 1444.68
    },
    "100302": {
      N: 11.0,
      PCNA: 52.0,
      PH2O: 44.0,
      peso: 1.0,
      custo: 2537.45,
      preco: 2537.45
    },
    "100328": {
      N: 34.0,
      peso: 1.0,
      custo: 1428.98,
      preco: 1428.98,
      "I::100268_100328_D1": 1.0,
      "I::100268_100328_D2": -1.0
    },
    D100268: {
      "I::100268_100328_D1": -1.0,
      "I::100268_100328": 1.0,
      "I::100268_100328_D2": 1000.0
    },
    D100328: {
      "I::100268_100328_D1": -1.0,
      "I::100268_100328": 1.0,
      "I::100268_100328_D2": 1000.0
    }
  },
  ints: {
    "100194": 1,
    "100249": 1,
    "100268": 1,
    "100287": 1,
    "100302": 1,
    "100328": 1
  },
  binaries: {
    D100268: 1,
    D100328: 1
  }
};

var resultado = formulador.Solve(modelo);
console.table(resultado);

Note that is the same input.


In Scenario A, the result is

┌──────────┬────────────┐
│ (index)  │   Values   │
├──────────┼────────────┤
│  100194  │     4      │
│  100249  │    400     │
│  100268  │     -0     │
│  100287  │     1      │
│  100302  │     96     │
│  100328  │    499     │
│ feasible │    true    │
│  result  │ 1745681.66 │
│ bounded  │    true    │
│ D100268  │     1      │
└──────────┴────────────┘

In Scenario B, the result is:

┌──────────┬────────────┐
│ (index)  │   Values   │
├──────────┼────────────┤
│  100194  │     3      │
│  100249  │    400     │
│  100268  │     3      │
│  100302  │     95     │
│  100328  │    499     │
│ feasible │    true    │
│  result  │ 1744830.33 │
│ bounded  │    true    │
│ D100268  │     1      │
└──────────┴────────────┘

So, why this occurs? I need the return from runkit.com to be the same from local code.

1

There are 1 best solutions below

0
tetri On BEST ANSWER

Finally found out: the Github repository does not have a release of version 0.4.5 and the current code available in Github does not contain some changes delivered to npm as version 0.4.5. Shame on you dev, shame on you...

How did I find out? I created a Node.js project using the npm package from version 0.4.5 and used the same data entry. The result was, as expected, the same as that obtained on runkit.com. So I compared the contents of the node_modules (from the npm package) and jsLPSolver (from Github) folders with WinMerge and he pointed me to the files with the differences.

Implementing the differences in the code obtained from Github, everything became clear and came back to the same identical solutions.