Changeset 560bc4d in observatorio for simulacion/SimEscenariosEconomicos
- Timestamp:
- May 21, 2014, 9:30:33 AM (10 years ago)
- Branches:
- simulacion
- Children:
- 209ac10
- Parents:
- 7bbc686
- Location:
- simulacion/SimEscenariosEconomicos
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
simulacion/SimEscenariosEconomicos/Makefile
r7bbc686 r560bc4d 4 4 5 5 XML = `pkg-config libxml++-2.6 --cflags --libs` 6 7 GVI = `pkg-config libgvc --cflags` 8 9 GVL = `pkg-config libgvc --libs` 6 10 7 11 CXX = g++ -O3 -g … … 16 20 -Wno-parentheses -Wno-unused-function 17 21 18 FLAGS = -std=c++ 0x -DDEBUG -D_GLIBCXX__PTHREADS $(WARN) $(XML)22 FLAGS = -std=c++11 -DDEBUG -D_GLIBCXX__PTHREADS $(WARN) $(XML) $(GVC) $(GVL) 19 23 20 24 INCLUDE = -I $(ALEPH) -I . -I $(PQ) … … 26 30 27 31 SIM = simulator 32 33 SB = svg_builder 28 34 29 35 SOURCES = dbProperties.C dbConnection.C dbQuery.C common.C strQuery.C \ … … 37 43 PREFIX = ecosim_ 38 44 39 all: gb sim45 all: obj gb sim sb 40 46 41 gb: obj42 $(CXX) $(INCLUDE) $(GB).C -o $(PREFIX)$(GB) $( OBJECTS) $(LIBS) $(FLAGS)47 gb: 48 $(CXX) $(INCLUDE) $(GB).C -o $(PREFIX)$(GB) $(LIBS) $(FLAGS) 43 49 44 sim: obj 45 $(CXX) $(INCLUDE) $(SIM).C -o $(PREFIX)$(SIM) $(OBJECTS) $(LIBS) \ 46 $(FLAGS) 50 sim: 51 $(CXX) $(INCLUDE) $(SIM).C -o $(PREFIX)$(SIM) $(LIBS) $(FLAGS) 52 53 sb: 54 $(CXX) $(INCLUDE) $(SB).C -o $(SB) $(LIBS) $(FLAGS) 47 55 48 56 obj: … … 54 62 $(RM) *~ *.o 55 63 clean-all: 56 $(RM) *~ *.o $(PREFIX)$(GB) $(PREFIX)$(SIM) $( LOCALLIB)64 $(RM) *~ *.o $(PREFIX)$(GB) $(PREFIX)$(SIM) $(SB) $(LOCALLIB) 57 65 -
simulacion/SimEscenariosEconomicos/graph_builder.C
r7bbc686 r560bc4d 21 21 */ 22 22 23 # include <argp.h> 24 23 25 # include <dbProperties.H> 24 26 # include <ioManager.H> 25 26 int main (int argc, char const * argv[]) { 27 28 if (argc < 4) { 29 std::cout << "usage: ./ecosim_graph_builder " 30 << "xmlRootsFileName xmlOutputFileName " 31 << "[db_server_info_file_name]\n"; 27 # include <process.H> 28 29 30 class Fields 31 { 32 Fields() { /* Empty */ } 33 34 public: 35 static std::string dbFileName; 36 37 static std::string xmlInputFileName; 38 39 static std::string xmlOutputFileName; 40 41 static bool generateXml; 42 43 static std::string svgOutputFileName; 44 45 static bool generateSvg; 46 47 static std::string gvOutputFileName; 48 49 static std::string dotOutputFileName; 50 51 static bool generateGv; 52 53 static bool generateDot; 54 55 static bool verbose; 56 }; 57 58 std::string Fields::dbFileName = ""; 59 60 std::string Fields::xmlInputFileName = ""; 61 62 std::string Fields::xmlOutputFileName = ""; 63 64 bool Fields::generateXml = false; 65 66 std::string Fields::svgOutputFileName = ""; 67 68 bool Fields::generateSvg = false; 69 70 std::string Fields::gvOutputFileName = ""; 71 72 bool Fields::generateGv = false; 73 74 std::string Fields::dotOutputFileName = ""; 75 76 bool Fields::generateDot = false; 77 78 bool Fields::verbose = false; 79 80 const char * argp_program_version = "Graph Builder v1.1"; 81 82 const char * argp_program_bug_address = "amujica@cenditel.gob.ve"; 83 84 static char doc[] = ""; 85 86 static char argDoc[] = ""; 87 88 static struct argp_option options [] = { 89 {"database", 'b', "database-filename", 0, 90 "filename with database attributes", 0}, 91 {"xml-input", 'i', "xml-input-filename", 0, "xml input filename", 0}, 92 {"xml-output", 'o', "xml-output-filename", OPTION_ARG_OPTIONAL, 93 "xml output filename", 0}, 94 {"svg-output", 's', "svg-output-filename", OPTION_ARG_OPTIONAL, 95 "svg output filename", 0}, 96 {"gv-output", 'g', "gv-output-filename", OPTION_ARG_OPTIONAL, 97 "gv output filename", 0}, 98 {"dot-output", 'd', "dot-output-filename", OPTION_ARG_OPTIONAL, 99 "dot output filename", 0}, 100 {"keep-dot", 'k', 0, OPTION_ARG_OPTIONAL, "Don't remove temporal'", 0}, 101 {"verbose", 'v', 0, OPTION_ARG_OPTIONAL, "Verbose mode", 0}, 102 { 0, 0, 0, 0, 0, 0 } 103 }; 104 105 static error_t parser_opt(int key, char * arg, struct argp_state *) 106 { 107 switch (key) 108 { 109 case 'b': 110 if (arg == NULL) 111 { 112 std::cout << "Waiting for filename with database attributes\n"; 113 exit(0); 114 } 115 Fields::dbFileName = arg; 116 break; 117 118 case 'i': 119 if (arg == NULL) 120 { 121 std::cout << "Waiting for xml input filename\n"; 122 exit(0); 123 } 124 Fields::xmlInputFileName = arg; 125 break; 126 127 case 'o': 128 if (arg == NULL) 129 { 130 std::cout << "Waiting for xml output filename\n"; 131 exit(0); 132 } 133 Fields::xmlOutputFileName = arg; 134 Fields::generateXml = true; 135 break; 136 137 case 's': 138 if (arg == NULL) 139 { 140 std::cout << "Waiting for svg output filename\n"; 141 exit(0); 142 } 143 Fields::svgOutputFileName = arg; 144 Fields::generateSvg = true; 145 break; 146 147 case 'g': 148 if (arg == NULL) 149 { 150 std::cout << "Waiting for gv output filename\n"; 151 exit(0); 152 } 153 Fields::gvOutputFileName = arg; 154 Fields::generateGv = true; 155 break; 156 157 case 'd': 158 if (arg == NULL) 159 { 160 std::cout << "Waiting for dot output filename\n"; 161 exit(0); 162 } 163 Fields::dotOutputFileName = arg; 164 Fields::generateDot = true; 165 break; 166 167 case 'k': 168 Fields::generateDot = true; 169 break; 170 171 case 'v': 172 Fields::verbose = true; 173 break; 174 175 default: return ARGP_ERR_UNKNOWN; 176 } 177 178 return 0; 179 } 180 181 static struct argp arg_defs = { options, parser_opt, argDoc, doc, 0, 0, 0 }; 182 183 int main (int argc, char * argv[]) { 184 185 argp_parse(&arg_defs, argc, argv, ARGP_IN_ORDER, 0, NULL); 186 187 if (Fields::dbFileName == "" or Fields::xmlInputFileName == "") { 188 189 std::cout << "filename with database attributes and xml input filename " 190 "are required\n"; 32 191 return 1; 192 33 193 } 34 194 35 std::string xmlRootsFileName = argv[1]; 36 37 std::string xmlOutputFileName = argv[2]; 38 39 std::string dbFileName = argc > 3 ? argv[3] : "dbserver"; 40 41 DBProperties::getInstance().readFile(dbFileName); 195 DBProperties::getInstance().readFile(Fields::dbFileName); 42 196 43 197 IOManager ioManager; … … 47 201 try { 48 202 49 ioManager.buildGraph(xmlRootsFileName, graph); 50 ioManager.addGraphToFile(graph, xmlRootsFileName, xmlOutputFileName, 51 IOManager::GRAPH); 203 ioManager.buildGraph(Fields::xmlInputFileName, graph); 204 205 if (Fields::generateXml) { 206 207 if (Fields::verbose) { 208 std::cout << "Generating xml output...\n"; 209 } 210 211 ioManager.addGraphToFile(graph, Fields::xmlInputFileName, 212 Fields::xmlOutputFileName, 213 IOManager::GRAPH); 214 215 if (Fields::verbose) { 216 std::cout << "Xml output generated.\n"; 217 } 218 } 52 219 53 220 } catch(const std::exception & e) { 54 221 55 std::cout << e.what() << std::endl;222 std::cout << "Exception catched: " << e.what() << std::endl; 56 223 return 2; 57 224 } 58 225 226 227 if (Fields::generateSvg or Fields::generateGv or Fields::generateDot) { 228 229 std::string dotFileName = 230 Fields::generateDot ? Fields::dotOutputFileName : "temp.dot"; 231 232 if (Fields::verbose) { 233 std::cout << "Generating " << dotFileName << "...\n"; 234 } 235 236 ioManager.generateDot<IOManager::NodeLabel, IOManager::ArcLabel> 237 (graph, dotFileName); 238 239 if (Fields::verbose) { 240 std::cerr << dotFileName << " generated.\n"; 241 } 242 243 int returnValue = 0; 244 245 char const * path = "dot"; 246 247 char * args[] = {"dot", "", (char *) dotFileName.c_str(), "-o", "", 0}; 248 249 if (Fields::generateSvg) { 250 251 args[1] = "-Tsvg"; 252 args[4] = (char *) Fields::svgOutputFileName.c_str(); 253 254 if (Fields::verbose) { 255 std::cout << "Generating " << Fields::svgOutputFileName 256 << "...\n"; 257 } 258 259 returnValue = Process::exec(path, args); 260 261 if (returnValue == 0) { 262 if (Fields::verbose) { 263 std::cerr << Fields::svgOutputFileName 264 << " generated.\n"; 265 } 266 } else { 267 std::cout << "Error generating " 268 << Fields::svgOutputFileName << "\n"; 269 } 270 } 271 272 if (Fields::generateGv) { 273 274 args[1] = "-Tgv"; 275 args[4] = (char *) Fields::gvOutputFileName.c_str(); 276 277 if (Fields::verbose) { 278 std::cout << "Generating " << Fields::gvOutputFileName 279 << "...\n"; 280 } 281 282 returnValue = Process::exec(path, args); 283 284 if (returnValue == 0) { 285 if (Fields::verbose) { 286 std::cerr << Fields::gvOutputFileName 287 << " generated.\n"; 288 } 289 } else { 290 std::cout << "Error generating " 291 << Fields::gvOutputFileName << "\n"; 292 } 293 } 294 295 if (not Fields::generateDot) { 296 297 if (Fields::verbose) { 298 std::cout << "Removing " << dotFileName << "...\n"; 299 } 300 301 remove(dotFileName.c_str()); 302 303 if (Fields::verbose) { 304 std::cerr << dotFileName << " removed.\n"; 305 } 306 } 307 308 } 309 59 310 return 0; 60 311 } -
simulacion/SimEscenariosEconomicos/ioManager.H
r7bbc686 r560bc4d 27 27 */ 28 28 29 30 29 # ifndef IO_MANAGER_H 31 30 # define IO_MANAGER_H … … 1739 1738 NodeSet & nodes, size_t & numClusters, 1740 1739 size_t & numNodes, 1741 NodeLabel & nodeLabel) { 1740 NodeLabel & nodeLabel, 1741 bool writeHref) { 1742 1742 1743 1743 std::string companyName = cinfo.companyName; … … 1797 1797 << " label = " << label 1798 1798 << " shape = box style = filled color = " << bgColor 1799 << " fontcolor = " << fontColor << "];\n"; 1799 << " fontcolor = " << fontColor; 1800 1801 if (writeHref) 1802 file << " href = \"#\"" 1803 << " onclick = \"click_nodo_primario($(this), '" 1804 << cinfo.rif << "');\""; 1805 1806 file << "];\n"; 1800 1807 1801 1808 map.insert(p, numNodes++); … … 1882 1889 size_t numNodes; 1883 1890 1891 bool writeHref; 1892 1884 1893 ClusterMapOp(std::ostream & _file, 1885 1894 Map <Graph::Node *, size_t> & _map, 1886 NodeLabel & _nodeLabel )1895 NodeLabel & _nodeLabel, bool _writeHref) 1887 1896 : file(_file), map(_map), nodeLabel(_nodeLabel), 1888 numClusters(0), numNodes(0) {1897 numClusters(0), numNodes(0), writeHref(_writeHref) { 1889 1898 1890 1899 // Empty … … 1893 1902 void operator () (const ClusterByPlantInfo & cinfo, NodeSet & nodes) { 1894 1903 writeClusterByPlant(file, map, cinfo, nodes, numClusters, numNodes, 1895 nodeLabel );1904 nodeLabel, writeHref); 1896 1905 } 1897 1906 }; … … 2090 2099 */ 2091 2100 template <class NodeLabel, class ArcLabel> 2092 void generateDot(Graph & g, const std::string & fileName,2101 void generateDot(Graph & g, std::ostream & output, bool writeHref, 2093 2102 NodeLabel & nodeLabel, ArcLabel & arcLabel) { 2094 2103 … … 2109 2118 Map <Graph::Node *, size_t> map; 2110 2119 2111 ofstream file(fileName.c_str()); 2112 2113 file << "/*\n" << COPYRIGHT << "\n*/\n\n"; 2114 2115 file << "/*\n" 2116 << " Archivo generado automáticamente por generateDot en" 2117 << " ioManager.H\n\n" 2118 << " Autor: Alejandro J. Mujica\n" 2119 << "*/\n\n"; 2120 2121 file << "digraph\n" 2122 << "{\n" 2123 << " rankdir = LR;\n\n"; 2120 output << "/*\n" << COPYRIGHT << "\n*/\n\n"; 2121 2122 output << "/*\n" 2123 << " Archivo generado automáticamente por generateDot en" 2124 << " ioManager.H\n\n" 2125 << " Autor: Alejandro J. Mujica\n" 2126 << "*/\n\n"; 2127 2128 output << "digraph\n" 2129 << "{\n" 2130 << " rankdir = LR;\n\n"; 2124 2131 2125 2132 // Escribir nodos clusterizados por planta. 2126 clustersByPlant.for_each(ClusterMapOp<NodeLabel>(file, map, nodeLabel)); 2133 clustersByPlant.for_each(ClusterMapOp<NodeLabel>(output, map, 2134 nodeLabel, writeHref)); 2127 2135 2128 2136 size_t i = map.size(); … … 2137 2145 Good * good = p->get_info().get(); 2138 2146 2139 file<< " " << i << "[label = \"Importar\\n" << good->getName()2140 << "\\n" << numtostr(good->getQuantity()) << " "2141 << good->getMeasurementUnit()2142 << "\" style = filled color = pink shape = box]\n";2147 output << " " << i << "[label = \"Importar\\n" << good->getName() 2148 << "\\n" << numtostr(good->getQuantity()) << " " 2149 << good->getMeasurementUnit() 2150 << "\" style = filled color = pink shape = box]\n"; 2143 2151 2144 2152 map.insert(p, i); … … 2161 2169 std::string label = arcLabel(g, a); 2162 2170 2163 std::string arc_color = 2171 std::string arc_color = 2164 2172 dotColor(gsl_rng_uniform_int(rng, DotColor::NUM_COLORS)); 2165 2173 2166 file<< " " << si << "->" << ti2167 << "[label = \"" << label << "\" color = "2168 << arc_color << " fontcolor = " << arc_color;2174 output << " " << si << "->" << ti 2175 << "[label = \"" << label << "\" color = " 2176 << arc_color << " fontcolor = " << arc_color; 2169 2177 2170 2178 if (a->get_info().isMin) 2171 file << " style = dashed"; 2172 2173 file << "];\n"; 2174 } 2175 2176 file << "}"; 2177 2178 file.close(); 2179 output << " style = dashed"; 2180 2181 output << "];\n"; 2182 } 2183 2184 output << "}"; 2179 2185 2180 2186 gsl_rng_free(rng); … … 2183 2189 /// @override 2184 2190 template <class NodeLabel = NodeLabel, class ArcLabel = ArcLabel> 2185 void generateDot(Graph & g, const std::string & fileName,2191 void generateDot(Graph & g, std::ostream & output, bool writeHref = false, 2186 2192 NodeLabel && nodeLabel = NodeLabel(), 2187 2193 ArcLabel && arcLabel = ArcLabel()) { 2188 2194 2189 generateDot<NodeLabel, ArcLabel>(g, fileName, nodeLabel, arcLabel); 2195 generateDot<NodeLabel, ArcLabel>(g, output, writeHref, nodeLabel, 2196 arcLabel); 2197 } 2198 2199 template <class NodeLabel = NodeLabel, class ArcLabel = ArcLabel> 2200 void generateDot(Graph & g, const std::string & fileName, bool writeHref, 2201 NodeLabel & nodeLabel, ArcLabel & arcLabel) { 2202 2203 std::ofstream file(fileName.c_str()); 2204 2205 generateDot<NodeLabel, ArcLabel>(g, file, writeHref, nodeLabel, 2206 arcLabel); 2207 2208 file.close(); 2209 } 2210 2211 template <class NodeLabel = NodeLabel, class ArcLabel = ArcLabel> 2212 void generateDot(Graph & g, const std::string & fileName, 2213 bool writeHref = false, 2214 NodeLabel && nodeLabel = NodeLabel(), 2215 ArcLabel && arcLabel = ArcLabel()) { 2216 2217 generateDot<NodeLabel, ArcLabel>(g, fileName, writeHref, nodeLabel, 2218 arcLabel); 2190 2219 } 2191 2220 };
Note: See TracChangeset
for help on using the changeset viewer.