3

I have a parameter B in matrix format, defined in the model file as

param B {Rn,Rn};

for which I define the non-sparse values as

from numpy import random
from scipy import sparse
from amplpy import AMPL, Environment, dataframe

B = random.randint(0, 2, (3, 3))
BSparse = sparse.lil_matrix(B)

dfB = dataframe.DataFrame(('RnRow', 'RnCol'), 'val')
dfB.setValues({
    (i+1, j+1): BSparse.data[i][jPos]
    for i, row in enumerate(BSparse.rows)
    for jPos, j in enumerate(row)
    })

Later on, when I want to solve my model, the solver complains

Error executing "solve" command:
error processing constraint f[1]:
    no value for B[1,1]

Apparently, missing values have not value 0 by default. How can I set that up to be the default value?

FooBar
  • 15,724
  • 19
  • 82
  • 171
  • Have you tried using a non-sparse version of the matrix to see if that works? Probably on a toy example – ShreyasG Oct 01 '17 at 14:31
  • @ShreyasG A non-sparse version does work (basically then I'm iterating through all values and explicitly setting the zeros). I'm particularly interested in setting the defaults for the sparse format because of the large efficiency gains. – FooBar Oct 01 '17 at 14:39
  • Right. Probably there's some way to tweak this within your 'solver' module then? Where you can instruct it to loop over only non-NaN values. – ShreyasG Oct 01 '17 at 14:45
  • @ShreyasG within `AMPL`, I can define matrices within a default value, and and then use `.` to denote sparse values (independent of solver). This is the functionality that I am looking for from `amplpy`. – FooBar Oct 01 '17 at 14:55

1 Answers1

0

I'm still not aware of doing this within amplpy, but at least one can directly specify them in the model file

param B {Rn, Rn} default 0;
FooBar
  • 15,724
  • 19
  • 82
  • 171