Matrix/List operation - delete a column? (AMPL cun.run example, Figure 14-3)

249 views
Skip to first unread message

duanem...@gmail.com

unread,
Jul 31, 2017, 2:57:31 PM7/31/17
to AMPL Modeling Language
I'm experimenting with the AMPL cutting stock example "cut.run" as discussed in Figure 14-3 of the AMPL book.
The example includes a column generation example, which I understand and works well.
But for the data that I'm working with, I wanted to see what happens if I removed unused columns....if there is any advantage to doing so.
It seems like it would be advantageous to reduce the size of the problem for unproductive patterns.

In the AMPL book example notation, if a term in the variable "Cut" is zero, then I want to remove
that entry, and the corresponding column in the variable "nbr", which corresponds to the pattern in question.

I don't see any easy way to delete  a column.  Column generation only appends a column to the end of the matrix/list.
It seems like I have to copy the whole thing, and then copy it back to the original matrix, or have a double buffer type of solution. 

So my question is, is there an easy way to remove a column (or row) from an AMPL matrlx/List?
(or any matrix operations in general).

It looks like maybe the redeclare command could be used for this by redefining "PATTERN" and then using redeclare on nbr.



#------------------------------------AMPL example code
model cut.mod;
data cut.dat;
option solver cplex, solution_round 6;
option display_1col 0, display_transpose -10;
problem Cutting_Opt: Cut, Number, Fill;
option relax_integrality 1;
problem Pattern_Gen: Use, Reduced_Cost, Width_Limit;
option relax_integrality 0;

let nPAT := 0;
for {i in WIDTHS}
{   let nPAT := nPAT + 1;
    let nbr[i,nPAT] := floor (roll_width/i);
    let {i2 in WIDTHS: i2 <> i} nbr[i2,nPAT] := 0;
}
repeat
{    solve Cutting_Opt;
     let {i in WIDTHS} price[i] := Fill[i].dual;
     solve Pattern_Gen;
     if Reduced_Cost < -0.00001 then
     {   #======================Something like this
         # if a particular pattern isn't used, then remove it.
         #for{nbr in PATTERNS}
         #{   if Cut[nbr] == 0
         #    {  delete Fill[nbr]
         #       delete nbr[nbr]
         #       nPAT := nPAT-1;
         #    }
         #======================
         let nPAT := nPAT + 1;
         let {i in WIDTHS} nbr[i,nPAT] := Use[i];
     }
     else break;
}

Figure 14-3: Gilmore-Gomory procedure for cutting-stock problem (cut.run).

____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Robert Fourer

unread,
Aug 1, 2017, 10:02:30 PM8/1/17
to am...@googlegroups.com

You'll have to define something like

   set ACTIVE_PATTERNS within 1..nPAT;

and index your data over 1..nPAT but your variables, objective, and constraints over ACTIVE_PATTERNS.  Then you can use commands like

   let ACTIVE_PATTERNS := ACTIVE_PATTERNS union {nPAT};
   let ACTIVE_PATTERNS := ACTIVE_PATTERNS diff {nbr};

to add and remove patterns, respectively, from your problem to be solved.

Bob Fourer
am...@googlegroups.com


--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.

duanem...@gmail.com

unread,
Aug 3, 2017, 9:21:04 AM8/3/17
to AMPL Modeling Language, 4...@ampl.com
Okay. Great. Thanks. That works. I'll have to get use to using sets/lists instead of matrices and vectors.
Here's a example that shows how the set difference can be used to delete a column.

ampl: reset;
      param nPAT integer >=0;
      set PATTERNS within 1..nPAT;
      set REMOVED  within 1..nPAT;
      let nPAT := 50;
      let PATTERNS := {1..nPAT};
      let REMOVED := {4,5,6, 8,9,10};

ampl: display PATTERNS;
set PATTERNS :=
1    5    9    13   17   21   25   29   33   37   41   45   49
2    6    10   14   18   22   26   30   34   38   42   46   50
3    7    11   15   19   23   27   31   35   39   43   47
4    8    12   16   20   24   28   32   36   40   44   48;

ampl: let PATTERNS := PATTERNS diff REMOVED;

ampl: display PATTERNS;
set PATTERNS :=
1    7    13   16   19   22   25   28   31   34   37   40   43   46   49
2    11   14   17   20   23   26   29   32   35   38   41   44   47   50
3    12   15   18   21   24   27   30   33   36   39   42   45   48;


--------------------------------------------------------------------------------------------------------------
Reply all
Reply to author
Forward
0 new messages