00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "CouenneProblemElem.hpp"
00012 #include "CouenneProblem.hpp"
00013
00014 #include "exprAux.hpp"
00015 #include "exprIVar.hpp"
00016 #include "depGraph.hpp"
00017
00018
00019
00020
00021 void replace (CouenneProblem *p, int wind, int xind);
00022
00023
00025 exprAux *CouenneConstraint::standardize (CouenneProblem *p) {
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifdef DEBUG
00035 printf ("################################\nStandardizing constraint: "); print ();
00036
00037 printf (" ["); fflush (stdout); lb_ -> print ();
00038 printf (","); fflush (stdout); ub_ -> print (); fflush (stdout);
00039
00040
00041
00042
00043
00044
00045 printf ("]\n");
00046 #endif
00047
00048 if (compareExpr (&lb_, &ub_) == 0) {
00049
00050
00051
00052
00053 expression *rest;
00054
00055
00056 int wind = p -> splitAux ((*lb_) (), body_, rest, p -> Commuted ());
00057
00058 if (wind >= 0) {
00059
00060
00061
00062 expression *restSimple = rest -> simplify ();
00063
00064 if (restSimple) {
00065 delete rest;
00066 rest = restSimple;
00067 }
00068
00069
00070
00071
00072 if (rest -> code () == COU_EXPRCONST) {
00073
00074 p -> Var (wind) -> lb () =
00075 p -> Var (wind) -> ub () = rest -> Value ();
00076
00077 delete rest;
00078 return NULL;
00079 }
00080
00081
00082
00083
00084
00085 p -> Commuted () [wind] = true;
00086
00087 #ifdef DEBUG
00088 printf ("---> %d & ", wind); fflush (stdout);
00089 rest -> print (); printf ("\n");
00090 #endif
00091
00092 assert (p -> Var (wind) -> Type () == VAR);
00093
00094
00095
00096
00097 int xind = rest -> Index ();
00098
00099 if (xind >= 0) {
00100
00101 replace (p, wind, xind);
00102
00103 p -> auxiliarize (p -> Var (wind), p -> Var (xind));
00104 p -> Var (wind) -> zeroMult ();
00105
00106 } else {
00107
00108
00109 exprAux *w = new exprAux (rest, wind, 1 + rest -> rank (),
00110 p -> Var (wind) -> isInteger () ?
00111 exprAux::Integer : exprAux::Continuous,
00112 p -> domain ());
00113
00114 std::set <exprAux *, compExpr>::iterator i = p -> AuxSet () -> find (w);
00115
00116
00117 if (i == p -> AuxSet () -> end ()) {
00118
00119 p -> AuxSet () -> insert (w);
00120 p -> getDepGraph () -> insert (w);
00121
00122 #ifdef DEBUG
00123 printf ("now replacing x [%d] with ", wind); fflush (stdout);
00124 w -> print (); printf (" := ");
00125 w -> Image () -> print (); printf ("\n");
00126 #endif
00127
00128
00129
00130 p -> auxiliarize (w);
00131 }
00132
00133 #ifdef DEBUG
00134 else {
00135 printf ("found aux occurrence of "); fflush (stdout);
00136 w -> print (); printf (" := ");
00137 w -> Image () -> print (); printf (" ... ");
00138 (*i) -> print (); printf (" := ");
00139 (*i) -> Image () -> print (); printf ("\n");
00140
00141
00142
00143
00144
00145
00146
00147
00148 int xind = (*i) -> Index (), iMax, iMin;
00149
00150 if (xind < wind) {
00151 iMax = wind;
00152 iMin = xind;
00153 } else {
00154 iMax = xind;
00155 iMin = wind;
00156 }
00157
00158 replace (p, iMax, iMin);
00159
00160 p -> auxiliarize (p -> Var (iMax), p -> Var (iMin));
00161 p -> Var (iMax) -> zeroMult ();
00162 p -> auxiliarize (w);
00163 }
00164 #endif
00165 }
00166
00167 return NULL;
00168 }
00169 }
00170
00171 #ifdef DEBUG
00172 printf ("\nnormal\n-----------------\n");
00173 #endif
00174
00175 return body_ -> standardize (p);
00176 }
00177
00178
00179
00180 void replace (CouenneProblem *p, int wind, int xind) {
00181
00182 exprVar
00183 *varLeaves = p -> Variables () [wind],
00184 *varStays = p -> Variables () [xind];
00185
00186
00187
00188 varStays -> lb () = varLeaves -> lb () = CoinMax (varStays -> lb (), varLeaves -> lb ());
00189 varStays -> ub () = varLeaves -> ub () = CoinMin (varStays -> ub (), varLeaves -> ub ());
00190
00191 if (varStays -> isInteger () ||
00192 varLeaves -> isInteger ()) {
00193
00194 varStays -> lb () = ceil (varStays -> lb ());
00195 varStays -> ub () = floor (varStays -> ub ());
00196
00197 if (varStays -> Type () == AUX)
00198 varStays -> setInteger (true);
00199 else {
00200
00201 p -> Variables () [xind] = varStays = new exprIVar (xind, p -> domain ());
00202 p -> auxiliarize (varStays);
00203
00204 }
00205 }
00206 }