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?

asked Oct 1, 2017 at 14:00
4
  • Have you tried using a non-sparse version of the matrix to see if that works? Probably on a toy example Commented Oct 1, 2017 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. Commented Oct 1, 2017 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. Commented Oct 1, 2017 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. Commented Oct 1, 2017 at 14:55

1 Answer 1

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;
answered Oct 2, 2017 at 7:16
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.