1

I have a sparse matrix in AMPL. As a result, it includes a lot of values that are coded as ".". The "." value in AMPL means "no value specified here." When I try to solve the optimization problem I get a message reading "no value specified for..." in reference to the cells containing the "." consequently, it won't solve the problem.

However, when I try to specify a default value to replace the ".", the problem churns and churns and doesn't solve. Is there any way I can set restrictions on the parameter so that the solver doesn't look at the "." values?

Hope this is clear enough.

2 Answers2

1

Instead of specifying a default value, you can work with a sparse matrix. For example:

   param m integer > 0; 
   set C within {1..m,1..m}; 
   param A{C}; 

   data;
   param m := 4; 
   param: C: A:    1  2  3  4 := 
              1   36  .  . -2 
              2    .  7  3  . 
              3    .  . -8 16 
              4   12  3  . 77 ; 

And in your model you should replace indexing over {i in 1..m, j in 1..m} with indexing over {(i,j) in C}.

See also https://groups.google.com/d/msg/ampl/1s1X-UNSCg4/RWZm0sVa0IQJ.

vitaut
  • 49,672
  • 25
  • 199
  • 336
  • @jacobgrindal Don't forget to accept the answer (if it was useful =)) – vitaut May 01 '15 at 18:24
  • Your solutions appears to work. however, unlike your matrix (which is indexed numerically ({1..4,1..4}), mine is indexed categorically{ID_Number, ID_Number). However, it is symmetric, so only one half is needed. How do I go about referencing only one half since I can't use: {(i,j) in C: i >= j} since i and j are not numbers. – jacobgrindal May 02 '15 at 01:59
  • You can make ID_Number an ordered set and use indexing {(i,j) in C: ord(i, ID_Number) >= ord(j, ID_Number)}. – vitaut May 02 '15 at 13:34
1

Representing non-useful values with a dot (or a period) is not what I would call "sparse". It may save operations time, but it will use just as much memory as a dense representation. Having said that the above example is also not what I would call sparse. A lot of positions are non-zero.

Having said that, if you truly have a large sparse matrix, use the formulation below instead. It really takes advantage of the structure "within" and should save you some memory.

param m integer > 0;

set C within {1..m,1..m};

param A{C};

data;

param m := 4;

param: C: A:=

   1 1 36

   1 4 -2

   2 2 7

   2 3 3

   3 3 -8

   3 4 16

   4 1 12

   4 2 3

   4 4 77;
Wilmer E. Henao
  • 4,094
  • 2
  • 31
  • 39