00001 /* (c) 2008,2009 Jonathan Hogg and Andreas Grothey, University of Edinburgh 00002 * 00003 * This file is part of SML. 00004 * 00005 * SML is free software: you can redistribute it and/or modify it under the 00006 * terms of the GNU Lesser General Public License as published by the Free 00007 * Software Foundation, using version 3 of the License. 00008 * 00009 * SML is distributed in the hope that it will be useful, but WITHOUT ANY 00010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00011 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00012 * details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public License 00015 * along with this program. If not, see http://www.gnu.org/licenses/. 00016 */ 00017 00018 #ifndef EXPANDED_MODEL_H 00019 #define EXPANDED_MODEL_H 00020 00021 /* This is the Expanded version of the AMPL model 00022 (as opposed to the FLAT version). 00023 00024 It serves to define a tree representation of the model that has a node for 00025 EVERY submodel (rather than just every type of submodel as the FLAT model) 00026 00027 It would serve as an intermediate step between the AmplModel view of 00028 the world (which seems the right structure for a Benders type solver - 00029 complicating constraints/variables are associated with the parent node) 00030 and the OOPS view of the world (where complicating 00031 variables/constraints belong to off-diagonal subblocks) 00032 00033 This would still be in the Benders view. 00034 */ 00035 00036 #include "ExpandedModelInterface.h" 00037 #include "symtab.h" 00038 #include <list> 00039 #include <string> 00040 00041 class AmplModel; 00042 class NlFile; 00043 00104 class ExpandedModel : public ExpandedModelInterface { 00105 00106 private: 00107 00109 int nLocalVars; 00110 00112 int nLocalCons; 00113 00118 bool localVarInfoSet; 00119 00120 /* Store solutions */ 00121 double *pvar, *dvar; 00122 double *prow, *drow; 00123 00125 AmplModel *src; 00126 00128 std::string model_file; 00129 00135 NlFile *nlfile; 00136 00137 //list of constraints 00138 // FIXME: can we assume that all constraints in *.nl belong to this node? 00139 //list of variables 00140 //FIXME: in which form? regex? numbers? 00141 // BOTH: regex at the start. Info on numbers can be generated by a 00142 // class method 00143 00145 std::list<std::string> listOfVarNames; 00146 00148 std::list<std::string> listOfLocalVarNames; 00149 00151 std::list<std::string> listOfConNames; 00152 00154 std::list<std::string> listOfLocalConNames; 00155 00157 std::list<int> listOfLocalVars; 00158 00160 std::list<std::string> localVarDef; 00161 00162 public: 00163 00169 static std::list<std::string> pathToNodeStack; 00170 00171 // -------------------------- methods ------------------------------------ 00172 00174 ExpandedModel(AmplModel *src_model); 00175 00177 ~ExpandedModel(); 00178 00180 void print() const; 00181 00183 int getNLocalVars() const; 00184 00186 int getNLocalCons() const; 00187 00189 const std::list<std::string>& getLocalVarNames() const; 00190 00192 const std::list<std::string>& getLocalConNames() const; 00193 00195 int getNzJacobianOfIntersection(ExpandedModelInterface *emcol); 00196 00198 void getJacobianOfIntersection(ExpandedModelInterface *emcol, int *colbeg, 00199 int *collen, int *rownbs, double *el); 00200 00202 void getRowBounds(double *lower, double *upper) const; 00203 00205 void getColLowBounds(double *elts); 00206 00208 void getColUpBounds(double *elts); 00209 00211 void getObjGradient(double *elts); 00212 00214 void setPrimalSolColumns(const double *elts); 00215 00217 void setDualSolColumns(const double *elts); 00218 00220 void setPrimalSolRows(const double *elts); 00221 00223 void setDualSolRows(const double *elts); 00224 00226 void setupNlFile(const std::string& name); 00227 00229 int findIxOfLocalVarsInNlFile(NlFile *nlf, int *lvar); 00230 00232 std::string getName() const { return model_file; } 00233 00235 void outputSolution(std::ostream &out, int indent=0); 00236 00238 void appendLocalVarDef(const std::string& name) { 00239 localVarDef.push_back(name); 00240 } 00241 00243 void setLocalVarInfo(); 00244 00245 private: 00246 std::list<SymbolTable::Entry> getObjList() const; 00247 00248 }; 00249 00250 #endif