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?
asked Oct 1, 2017 at 14:00
FooBar
16.7k20 gold badges95 silver badges189 bronze badges
1 Answer 1
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;
answered Oct 2, 2017 at 7:16
FooBar
16.7k20 gold badges95 silver badges189 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py
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 fromamplpy.