1 | /* _________________________________________________________________________ |
---|
2 | * |
---|
3 | * PICO: A C++ library of scalable branch-and-bound and related methods. |
---|
4 | * Copyright (c) 2001, Sandia National Laboratories. |
---|
5 | * This software is distributed under the GNU Lesser General Public License. |
---|
6 | * For more information, see the README file in the top PICO directory. |
---|
7 | * _________________________________________________________________________ |
---|
8 | */ |
---|
9 | // |
---|
10 | // PicoLPCutMngmnt.cpp |
---|
11 | // |
---|
12 | |
---|
13 | #include <acro_config.h> |
---|
14 | #include <pico/PicoLPCutMngmnt.h> |
---|
15 | #include <pico/lpEnum.h> |
---|
16 | |
---|
17 | namespace pico { |
---|
18 | |
---|
19 | |
---|
20 | void PicoLPCutMngmnt::execAddRows(BasicArray<picoRowCut*>& cutlist, int num_rows) |
---|
21 | { |
---|
22 | for (size_type i=0; i< (size_type)num_rows; i++) { |
---|
23 | cutlist[i]->lp_cut_index = rowNameCtr; |
---|
24 | PicoLPInterface::addRow(cutlist[i]->lpform(), cutlist[i]->lb(), |
---|
25 | cutlist[i]->ub()); |
---|
26 | } |
---|
27 | } |
---|
28 | |
---|
29 | |
---|
30 | |
---|
31 | void PicoLPCutMngmnt::replaceRows(BasicArray<picoRowCut*>& cutlist) |
---|
32 | { |
---|
33 | // |
---|
34 | // Delete all of the rows |
---|
35 | // |
---|
36 | deleteRows(num_core_rows,getNumRows()-1); |
---|
37 | |
---|
38 | // |
---|
39 | // Add the current cutlist |
---|
40 | // |
---|
41 | addRows(cutlist, cutlist.size()); |
---|
42 | } |
---|
43 | |
---|
44 | |
---|
45 | // This sets the core variables from the basis. All the slack |
---|
46 | // variables for the additional cuts are set to nonbasic except for |
---|
47 | // the basic ones (from degenerate binding or nonbinding cuts). |
---|
48 | // basic_list (1 or 2) is a list of the indices (in cutlist 1 or 2) of |
---|
49 | // the cuts with basic slack variables. The first pair is for |
---|
50 | // persistent cuts, the second for binding (normal) cuts. The |
---|
51 | // "nonbasic" setting for row slacks/auxilliary variables is |
---|
52 | // interpreted by each solver individually. For CLP, cplex, etc, that |
---|
53 | // use slacks (Ax + Iy = b representation), then this is usually |
---|
54 | // atLower. For solvers like glpk that use auxilliary variables set |
---|
55 | // to Ax and set bounds on these variables, the value may be |
---|
56 | // atUpper. Warning: rows must be loaded into the LP before calling |
---|
57 | // this. |
---|
58 | |
---|
59 | void PicoLPCutMngmnt::setBasisWithCuts(BasicArray<picoRowCut*>& cutlist1, |
---|
60 | BasicArray<int>& basic_list1, |
---|
61 | BasicArray<picoRowCut*>& cutlist2, |
---|
62 | BasicArray<int>& basic_list2, |
---|
63 | BasisArray& basis) |
---|
64 | { |
---|
65 | // |
---|
66 | // Setup the basis array. |
---|
67 | // |
---|
68 | |
---|
69 | size_type num_rows = getNumRows(); |
---|
70 | size_type num_cols = getNumCols(); |
---|
71 | size_type basis_size = num_rows + num_cols; |
---|
72 | |
---|
73 | // Make sure this leaves the current data intact |
---|
74 | if (basis.size() < basis_size) |
---|
75 | basis.resize(basis_size); |
---|
76 | size_type i; |
---|
77 | // Most will be at lower |
---|
78 | for (i= num_cols + num_core_rows; i< basis_size; i++) |
---|
79 | basis.put(i,nonbasic); |
---|
80 | size_type stop_point = basic_list1.size(); |
---|
81 | for (i=0; i<stop_point; i++) |
---|
82 | basis.put(num_cols + getCurrRowNum(*cutlist1[basic_list1[i]]),basic); |
---|
83 | stop_point = basic_list2.size(); |
---|
84 | for (i=0; i<stop_point; i++) |
---|
85 | basis.put(num_cols + getCurrRowNum(*cutlist2[basic_list2[i]]),basic); |
---|
86 | setBasis(basis); |
---|
87 | } |
---|
88 | |
---|
89 | /// Put the (integer) ranks for the cuts in cutlist into the rankList. |
---|
90 | |
---|
91 | void PicoLPCutMngmnt::getRanks(BasicArray<picoRowCut *>& cutlist, IntVector &rankList) |
---|
92 | { |
---|
93 | size_type num_to_delete = cutlist.size(); |
---|
94 | if (rankList.size() != num_to_delete) |
---|
95 | rankList.resize(num_to_delete); |
---|
96 | for (size_type i = 0; i < num_to_delete; i++) |
---|
97 | { |
---|
98 | rankList[i] = rowInfo.rank(LPInfoKey(cutlist[i]->lp_cut_index,0)); |
---|
99 | } |
---|
100 | } |
---|
101 | |
---|
102 | } // namespace pico |
---|