Specifying default values

Viewed 207

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?

1 Answers

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;
Related