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 AMPLMODEL_H 00019 #define AMPLMODEL_H 00020 00021 #include "symtab.h" 00022 #include <list> 00023 #include <string> 00024 00025 class ExpandedModel; 00026 class IDNode; 00027 class ModelComp; 00028 class SyntaxNode; 00029 class SyntaxNodeIx; 00030 class SyntaxNodeIDREF; 00031 struct changeitem; 00032 00046 class AmplModel{ 00047 public: 00048 00062 SymbolTable symbol_table; 00063 00065 std::string name; 00066 00068 std::string global_name; 00069 00070 int n_vars; 00071 int n_cons; 00072 int n_params; 00073 int n_sets; 00074 int n_objs; 00075 int n_submodels; 00076 int n_total; 00077 int level; 00078 00081 ModelComp *node; 00082 00084 std::list<ModelComp*> comps; 00085 00087 AmplModel *parent; 00088 00094 SyntaxNodeIx *ix; 00095 00097 static std::list<changeitem> changes; 00098 00100 static AmplModel *root; 00101 00102 // -------------------------- methods ---------------------------------- 00104 AmplModel(const std::string& orig_name, AmplModel *par = NULL); 00105 00107 virtual ~AmplModel(); 00108 00110 void setGlobalName(); 00111 00113 void setGlobalNameRecursive(); 00114 00117 void writeTaggedComponents(std::ostream& fout); 00118 00120 ExpandedModel* createExpandedModel(const std::string& smodelname, 00121 const std::string& sinstanceStub); 00122 00124 void addDummyObjective(); 00125 00127 virtual void addComp(ModelComp *comp); 00128 00130 void removeComp(const ModelComp *comp); 00131 00133 void reassignDependencies(); 00134 00136 void print() const; 00137 00139 void dump(const char *filename) const; 00140 00142 void dump(std::ostream& fout) const; 00143 00144 static void applyChanges(); //< apply the model changes stored in Q 00145 00147 const SymbolTable::Entry *findComponent(const std::string& id) const; 00148 std::list<SymbolTable::Entry> getObjList() const; 00149 00150 virtual SyntaxNodeIDREF* find_var_ref_in_context(IDNode *ref); 00151 00152 // Virtual methods implemented only for stochastic models 00153 virtual AmplModel* expandToFlatModel() { throw; } 00154 virtual SyntaxNode* getProbs() const { throw; } 00155 00156 private: 00157 00159 void check() const; 00160 00161 }; 00162 00163 enum {CHANGE_NOACT=0,CHANGE_REM=1,CHANGE_ADD=2}; 00164 00174 struct changeitem { 00175 00177 ModelComp *comp; 00178 00180 AmplModel *model; 00181 00183 int action; 00184 00185 }; 00186 00187 #endif