Search code examples
parametersnullsparse-matrixmissing-dataampl

Sparse Matrix in AMPL


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.


Solution

  • 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.