linny-r 1.5.8 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -51,8 +51,8 @@ module.exports = class MILPSolver {
51
51
  // Each external MILP solver application has its own interface
52
52
  // NOTE: the list may be extended to accommodate more MILP solvers
53
53
  if(this.id === 'gurobi') {
54
- this.ext = '.mps';
55
- this.user_model = path.join(workspace.solver_output, 'usr_model.mps');
54
+ this.ext = '.lp';
55
+ this.user_model = path.join(workspace.solver_output, 'usr_model.lp');
56
56
  this.solver_model = path.join(workspace.solver_output, 'solver_model.lp');
57
57
  this.solution = path.join(workspace.solver_output, 'model.json');
58
58
  this.log = path.join(workspace.solver_output, 'model.log');
@@ -283,17 +283,17 @@ module.exports = class MILPSolver {
283
283
  x_dict = {},
284
284
  getValuesFromDict = () => {
285
285
  // Returns a result vector for as many real numbers (as strings!)
286
- // as there are columns (0 if not reported by the solver)
287
- // (1) Sort on variable name
286
+ // as there are columns (0 if not reported by the solver).
287
+ // First sort on variable name
288
288
  const vlist = Object.keys(x_dict).sort();
289
- // Start with column 1
289
+ // Start with column 1.
290
290
  let col = 1;
291
291
  for(let i = 0; i < vlist.length; i++) {
292
292
  const
293
293
  v = vlist[i],
294
- // Variable names have zero-padded column numbers, e.g. "X001"
294
+ // Variable names have zero-padded column numbers, e.g. "X001".
295
295
  vnr = parseInt(v.substring(1));
296
- // Add zeros for unreported variables until column number matches
296
+ // Add zeros for unreported variables until column number matches.
297
297
  while(col < vnr) {
298
298
  x_values.push('0');
299
299
  col++;
@@ -301,23 +301,23 @@ module.exports = class MILPSolver {
301
301
  x_values.push(x_dict[v]);
302
302
  col++;
303
303
  }
304
- // Add zeros to vector for remaining columns
304
+ // Add zeros to vector for remaining columns.
305
305
  while(col <= result.columns) {
306
306
  x_values.push('0');
307
307
  col++;
308
308
  }
309
- // No return value; function operates on x_values
309
+ // No return value; function operates on x_values.
310
310
  };
311
311
 
312
312
  if(this.id === 'gurobi') {
313
- // `messages` must be an array of strings
313
+ // `messages` must be an array of strings.
314
314
  result.messages = fs.readFileSync(this.log, 'utf8').split(os.EOL);
315
315
  if(result.status !== 0) {
316
- // Non-zero solver exit code may indicate expired license
316
+ // Non-zero solver exit code may indicate expired license.
317
317
  result.error = 'Your Gurobi license may have expired';
318
318
  } else {
319
319
  try {
320
- // Read JSON string from solution file
320
+ // Read JSON string from solution file.
321
321
  const
322
322
  json = fs.readFileSync(this.solution, 'utf8').trim(),
323
323
  sol = JSON.parse(json);
@@ -329,13 +329,16 @@ module.exports = class MILPSolver {
329
329
  if(!result.error) result.error = 'Unknown solver error';
330
330
  console.log(`Solver status: ${result.status} - ${result.error}`);
331
331
  }
332
- // Objective value
332
+ // Objective value.
333
333
  result.obj = sol.SolutionInfo.ObjVal;
334
- // Values of solution vector
334
+ // Values of solution vector.
335
335
  if(sol.Vars) {
336
+ // Fill dictionary with variable name: value entries.
336
337
  for(let i = 0; i < sol.Vars.length; i++) {
337
- x_values.push(sol.Vars[i].X);
338
+ x_dict[sol.Vars[i].VarName] = sol.Vars[i].X;
338
339
  }
340
+ // Fill the solution vector, adding 0 for missing columns.
341
+ getValuesFromDict();
339
342
  }
340
343
  } catch(err) {
341
344
  console.log('WARNING: Could not read solution file');