00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "CouenneProblem.hpp"
00013 #include "exprClone.hpp"
00014
00015
00016
00020
00021 void CouenneProblem::auxiliarize (exprVar *aux, exprVar *subst) {
00022
00023 #ifdef DEBUG
00024 printf ("replacing "); if (aux) aux -> print ();
00025 printf (" with "); if (subst) subst -> print ();
00026 printf ("\n");
00027 #endif
00028
00029 bool same_var = (subst == NULL);
00030
00031 if (!subst)
00032 subst = aux;
00033
00034
00035
00036 int index = aux -> Index ();
00037
00038 assert (index >= 0);
00039
00040 std::vector <exprVar *>::iterator orig;
00041
00042 for (orig = variables_.begin ();
00043 orig != variables_.end (); ++orig)
00044
00045 if ((((*orig) -> Type () == VAR) || !same_var) &&
00046 ((*orig) -> Index () == index))
00047
00048 break;
00049
00050 if (orig == variables_ . end ()) {
00051 printf ("CouenneProblem::auxiliarize: no original variables correspond\n");
00052 return;
00053 }
00054
00055
00056
00057 for (std::vector <CouenneObjective *>::iterator i = objectives_.begin ();
00058 i != objectives_.end (); ++i) {
00059
00060 expression *body = (*i) -> Body ();
00061
00062 if (body) {
00063 if ((body -> Type () == VAR) ||
00064 (body -> Type () == AUX)) {
00065
00066 if (body -> Index () == (*orig) -> Index ()) {
00067
00068 delete body;
00069 (*i) -> Body (new exprClone (subst));
00070 }
00071 } else body -> replace (*orig, subst);
00072 }
00073 }
00074
00075
00076
00077 for (std::vector <CouenneConstraint *>::iterator i = constraints_.begin ();
00078 i != constraints_.end (); ++i) {
00079
00080 expression *body = (*i) -> Body ();
00081
00082 if (body) {
00083 if ((body -> Type () == VAR) ||
00084 (body -> Type () == AUX)) {
00085
00086 if (body -> Index () == (*orig) -> Index ()) {
00087
00088 delete body;
00089 (*i) -> Body (new exprClone (subst));
00090 }
00091 } else body -> replace (*orig, subst);
00092 }
00093 }
00094
00095
00096
00097 for (std::vector <exprVar *>::iterator i = variables_.begin ();
00098 i != variables_.end (); ++i)
00099
00100 if (((*i) -> Type () == AUX) &&
00101 ((*i) -> Index () != (*orig) -> Index ())) {
00102
00103 #ifdef DEBUG
00104
00105
00106
00107 #endif
00108
00109 expression *image = (*i) -> Image ();
00110
00111 if ((image -> Type () == VAR) ||
00112 (image -> Type () == AUX)) {
00113
00114 if (image -> Index () == (*orig) -> Index ()) {
00115
00116 delete image;
00117 (*i) -> Image (new exprClone (subst));
00118
00119 }
00120 } else image -> replace (*orig, subst);
00121
00122
00123 }
00124
00125
00126
00127 if (same_var)
00128 *orig = aux;
00129 }