Changeset 5c51ff9 in observatorio
- Timestamp:
- Apr 27, 2015, 12:02:38 PM (9 years ago)
- Branches:
- simulacion
- Children:
- ac8ea81
- Parents:
- a0523b8
- Location:
- simulacion/SimEscenariosEconomicos
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
simulacion/SimEscenariosEconomicos/indicatorGenerator.C
r7bbc686 r5c51ff9 40 40 41 41 42 void ProductionIndicatorGenerator::writeProductLine( 42 void ProductionIndicatorGenerator::writeProductLine(AutoConnection & conn, 43 43 Graph::Node * node, std::ofstream & file, 44 44 Map <long, PlantLocation> & mapPlantLocation, … … 73 73 if (ptrCiiu == NULL) { 74 74 75 std::string ciiu = getCiiu( rif);75 std::string ciiu = getCiiu(conn, rif); 76 76 77 77 ptrCiiu = mapCompanyCiiu.insert(rif, ciiu); … … 120 120 } 121 121 122 real computeGeneratedEmployment(Graph::Node * node, const std::string & rif, 123 const std::string & year, 124 const real & amountDiff) { 122 real computeGeneratedEmployment(AutoConnection & conn, Graph::Node * node, 123 const std::string & rif, 124 const std::string & year, 125 const real & amountDiff) { 125 126 126 127 real generatedEmployment = 0; … … 131 132 node->type == ROOT) and good->getType() == PRODUCT_GOOD) { 132 133 133 real staffNumber = getOperatingStaffNumber( rif, year);134 135 real totalAmount = getTotalAmount( rif, year);134 real staffNumber = getOperatingStaffNumber(conn, rif, year); 135 136 real totalAmount = getTotalAmount(conn, rif, year); 136 137 137 138 generatedEmployment = staffNumber * amountDiff / totalAmount; … … 142 143 143 144 144 void ProductionIndicatorGenerator::writeInputLine( 145 void ProductionIndicatorGenerator::writeInputLine(AutoConnection & conn, 145 146 Graph & graph, Graph::Arc * arc, std::ofstream & file, 146 147 Map <long, PlantLocation> & mapPlantLocation, … … 178 179 if (ptrCiiu == NULL) { 179 180 180 std::string ciiu = getCiiu( rif);181 std::string ciiu = getCiiu(conn, rif); 181 182 182 183 ptrCiiu = mapCompanyCiiu.insert(rif, ciiu); … … 214 215 const real amount = quantity * arc->get_info().price; 215 216 216 real employment = computeGeneratedEmployment( node, rif, year, amount);217 real employment = computeGeneratedEmployment(conn, node, rif, year, amount); 217 218 218 219 char sep = 0; … … 261 262 262 263 bool ProductionIndicatorGenerator::writeProductInputsIndicators( 264 AutoConnection & conn, 263 265 Graph & graph, const std::string & path, const std::string & year) { 264 266 … … 354 356 node->get_info()->getType() == INPUT_GOOD) { 355 357 356 writeProductLine(node, file, mapPlantLocation, mapCompanyCiiu); 358 writeProductLine(conn, node, file, mapPlantLocation, 359 mapCompanyCiiu); 357 360 358 361 writeEmptyInput(file); … … 371 374 continue; 372 375 373 writeProductLine(node, file, mapPlantLocation, mapCompanyCiiu); 374 375 writeInputLine(graph, arc, file, mapPlantLocation, 376 writeProductLine(conn, node, file, mapPlantLocation, 377 mapCompanyCiiu); 378 379 writeInputLine(conn, graph, arc, file, mapPlantLocation, 376 380 mapCompanyCiiu, year); 377 381 } … … 384 388 } 385 389 386 void ProductionIndicatorGenerator::writeProductionInfo(Graph & graph, 390 void ProductionIndicatorGenerator::writeProductionInfo(AutoConnection & conn, 391 Graph & graph, 387 392 Graph::Node * node, 388 393 const std::string & year, … … 490 495 491 496 real generatedEmployment = 492 computeGeneratedEmployment( node, COMPANY(good)->getRif(), year,497 computeGeneratedEmployment(conn, node, COMPANY(good)->getRif(), year, 493 498 amountDiff); 494 499 … … 513 518 } 514 519 515 bool ProductionIndicatorGenerator::writeProductIndicators( 520 bool ProductionIndicatorGenerator::writeProductIndicators(AutoConnection & conn, 516 521 Graph & graph, const std::string & path, const std::string & year) { 517 522 … … 610 615 continue; 611 616 612 writeProductLine( node, file, mapPlantLocation, mapCompanyCiiu);613 614 writeProductionInfo( graph, node, year, file);617 writeProductLine(conn, node, file, mapPlantLocation, mapCompanyCiiu); 618 619 writeProductionInfo(conn, graph, node, year, file); 615 620 } 616 621 … … 624 629 const std::string & year) { 625 630 626 bool res = writeProductInputsIndicators(graph, path, year); 627 628 res = res and writeProductIndicators(graph, path, year); 631 AutoConnection conn; 632 633 bool res = writeProductInputsIndicators(conn, graph, path, year); 634 635 res = res and writeProductIndicators(conn, graph, path, year); 629 636 630 637 if (not res) -
simulacion/SimEscenariosEconomicos/indicatorGenerator.H
r7bbc686 r5c51ff9 74 74 * @param mapPlantLocation buffer con ciiu de las empresas. 75 75 */ 76 void writeProductLine(Graph::Node * node, std::ofstream & file, 76 void writeProductLine(AutoConnection & conn, 77 Graph::Node * node, std::ofstream & file, 77 78 Map <long, PlantLocation> & mapPlantLocation, 78 79 Map <std::string, std::string> & … … 86 87 * @param mapPlantLocation buffer con ciiu de las empresas. 87 88 */ 88 void writeInputLine( Graph & graph,89 void writeInputLine(AutoConnection & conn, Graph & graph, 89 90 Graph::Arc * arc, std::ofstream & file, 90 91 Map <long, PlantLocation> & mapPlantLocation, … … 105 106 * @param fileName nombre del archivo sobre el cual se va a escribir. 106 107 */ 107 bool writeProductInputsIndicators(Graph & graph, const std::string & path, 108 bool writeProductInputsIndicators(AutoConnection & conn, Graph & graph, 109 const std::string & path, 108 110 const std::string & year); 109 111 110 void writeProductionInfo(Graph & graph, Graph::Node * node, 111 const std::string & year, std::ofstream & file); 112 void writeProductionInfo(AutoConnection & conn, Graph & graph, 113 Graph::Node * node, const std::string & year, 114 std::ofstream & file); 112 115 113 bool writeProductIndicators(Graph & graph, const std::string & path, 116 bool writeProductIndicators(AutoConnection & conn, Graph & graph, 117 const std::string & path, 114 118 const std::string & year); 115 119 -
simulacion/SimEscenariosEconomicos/ioManager.H
r76e705a r5c51ff9 379 379 * recorrido en amplitud. 380 380 */ 381 void buildGraphUpstream(Graph & g, DynListQueue <Graph::Node *> & queue, 381 void buildGraphUpstream(AutoConnection & conn, Graph & g, 382 DynListQueue <Graph::Node *> & queue, 382 383 const size_t & maxLevelUpstream, 383 384 const std::string & year, size_t & numNodes) { … … 397 398 List <size_t> inputsIds; 398 399 399 listInputIds( good->getId(), year, inputsIds);400 listInputIds(conn, good->getId(), year, inputsIds); 400 401 401 402 for (List <size_t>::Iterator iit(inputsIds); iit.has_current(); … … 406 407 List <InputInfo> inputs; 407 408 408 listInputs( inputId, year, inputs);409 listInputs(conn, inputId, year, inputs); 409 410 410 411 for (List <InputInfo>::Iterator it(inputs); … … 415 416 List <ProductInfo> products; 416 417 417 productInfoFromInput( input, products);418 productInfoFromInput(conn, input, products); 418 419 419 420 bool isInput = false; … … 486 487 } else { 487 488 488 getProducedQuantityAndPrice(productInfo, year); 489 getProducedQuantityAndPrice(conn, productInfo, 490 year); 489 491 490 492 ptrSrc = productMap.search(productInfo.productId); … … 504 506 505 507 arcInfo.price = 506 getAcquisitionPrice( src->get_info().get(),508 getAcquisitionPrice(conn, src->get_info().get(), 507 509 input.id, year); 508 510 arcInfo.inputId = input.id; 509 511 510 setArcMeasurementUnit( arcInfo);512 setArcMeasurementUnit(conn, arcInfo); 511 513 512 514 arcInfo.reqQuantity = 513 getUnitarianRequest( arcInfo.inputId,515 getUnitarianRequest(conn, arcInfo.inputId, 514 516 tgt->get_info()->getId()); 515 517 516 computeArcQuantityUpstream( src->get_info().get(),518 computeArcQuantityUpstream(conn, src->get_info().get(), 517 519 tgt->get_info().get(), 518 520 year, arcInfo); … … 708 710 * recorrido en amplitud. 709 711 */ 710 void buildGraphDownstream(Graph & g, DynListQueue <Graph::Node *> & queue, 712 void buildGraphDownstream(AutoConnection & conn, Graph & g, 713 DynListQueue <Graph::Node *> & queue, 711 714 const size_t & maxLevelDownstream, 712 715 const std::string & year, size_t & numNodes) { … … 724 727 computeNodeQuantity(g, src); 725 728 computeUsageInputQuantities(g, src); 726 getProducedQuantityAndPrice( good, year);729 getProducedQuantityAndPrice(conn, good, year); 727 730 } 728 731 729 732 List <Aleph::pair<ProductInfo, long>> requesters; 730 listRequesters( good, year, requesters);733 listRequesters(conn, good, year, requesters); 731 734 732 735 Tree <long> & levels = src->levels; … … 758 761 arcInfo.inputId = currentPair.second; 759 762 760 setArcMeasurementUnit( arcInfo);763 setArcMeasurementUnit(conn, arcInfo); 761 764 762 765 arcInfo.reqQuantity = 763 getUnitarianRequest( arcInfo.inputId,766 getUnitarianRequest(conn, arcInfo.inputId, 764 767 tgt->get_info()->getId()); 765 768 766 769 arcInfo.price = 767 getAcquisitionPrice( src->get_info().get(),770 getAcquisitionPrice(conn, src->get_info().get(), 768 771 arcInfo.inputId, year); 769 772 770 computeArcQuantityDownstream( good, tgt->get_info().get(),773 computeArcQuantityDownstream(conn, good, tgt->get_info().get(), 771 774 year, arcInfo); 772 775 … … 779 782 computeNodeQuantity(g, tgt); 780 783 computeUsageInputQuantities(g, tgt); 781 getProducedQuantityAndPrice(tgt->get_info().get(), year); 784 getProducedQuantityAndPrice(conn, tgt->get_info().get(), 785 year); 782 786 } 783 787 } … … 815 819 DynListQueue <Graph::Node *> downstreamQueue; 816 820 821 AutoConnection conn; 822 817 823 for (size_t i = 0; i < roots.size(); ++i) { 818 824 819 825 const size_t & id = roots.access(i); 820 826 821 ProductInfo info = loadInfoByProductId( id);827 ProductInfo info = loadInfoByProductId(conn, id); 822 828 823 829 if (info.productId == -1) { … … 830 836 } 831 837 832 getProducedQuantityAndPrice( info, year);838 getProducedQuantityAndPrice(conn, info, year); 833 839 834 840 info.quantity = info.totalQuantity; … … 844 850 845 851 if (maxLevelUpstream > 0) 846 buildGraphUpstream( g, upstreamQueue, maxLevelUpstream, year,852 buildGraphUpstream(conn, g, upstreamQueue, maxLevelUpstream, year, 847 853 numNodes); 848 854 849 855 if (maxLevelDownstream > 0) 850 buildGraphDownstream( g, downstreamQueue, maxLevelDownstream, year,851 numNodes);856 buildGraphDownstream(conn, g, downstreamQueue, maxLevelDownstream, 857 year, numNodes); 852 858 } 853 859 -
simulacion/SimEscenariosEconomicos/queries.C
rfaed520 r5c51ff9 35 35 # include <queries.H> 36 36 # include <dbQuery.H> 37 # include <autoConnection.H>38 37 39 38 # include <strQuery.H> … … 93 92 } 94 93 95 ProductInfo loadInfoByProductId(const size_t & id) { 96 97 AutoConnection conn; 94 ProductInfo loadInfoByProductId(AutoConnection & conn, const size_t & id) { 98 95 99 96 DBQuery query(conn); … … 171 168 } 172 169 173 void listInputIds(const size_t & productId, const std::string & year, 174 List <size_t> & inputIds) { 175 176 AutoConnection conn; 170 void listInputIds(AutoConnection & conn, const size_t & productId, 171 const std::string & year, List <size_t> & inputIds) { 177 172 178 173 DBQuery query(conn); … … 197 192 } 198 193 199 void listInputs(const size_t & inputId, const std::string & year, 200 List <InputInfo> & inputs) { 201 202 AutoConnection conn; 194 void listInputs(AutoConnection & conn, const size_t & inputId, 195 const std::string & year, List <InputInfo> & inputs) { 203 196 204 197 DBQuery query(conn); … … 315 308 long supplierId = std::atol(query.getValue(0)); 316 309 317 inputInfo.origCountry = getOrigCountry( supplierId);318 inputInfo.procCountry = getProcCountry( supplierId);310 inputInfo.origCountry = getOrigCountry(conn, supplierId); 311 inputInfo.procCountry = getProcCountry(conn, supplierId); 319 312 320 313 inputs.append(inputInfo); … … 322 315 } 323 316 324 void productInfoFromInput( const InputInfo & inputInfo,317 void productInfoFromInput(AutoConnection & conn, const InputInfo & inputInfo, 325 318 List <ProductInfo> & list) { 326 327 AutoConnection conn;328 319 329 320 DBQuery query(conn); … … 354 345 355 346 while (query.next()) 356 list.append(loadInfoByProductId( 347 list.append(loadInfoByProductId(conn, 357 348 std::atol(query.getValue(concat(DB::PRODUCT_TABLE_NAME, DB::ID, 358 349 '_'))))); 359 350 } 360 351 361 void listProductsId(Good * good, const std::string & year, 352 void listProductsId(AutoConnection & conn, Good * good, 353 const std::string & year, 362 354 List <Aleph::pair<long, long>> & list) { 363 364 AutoConnection conn;365 355 366 356 DBQuery query(conn); … … 413 403 } 414 404 415 void listRequesters(Good * good, const std::string & year, 405 void listRequesters(AutoConnection & conn, Good * good, 406 const std::string & year, 416 407 List <Aleph::pair<ProductInfo, long>> & list) { 417 408 418 409 List <Aleph::pair <long, long>> ids; 419 410 420 listProductsId( good, year, ids);411 listProductsId(conn, good, year, ids); 421 412 422 413 for(List <Aleph::pair<long, long>>::Iterator it(ids); it.has_current(); … … 425 416 Aleph::pair <long, long> & p = it.get_current(); 426 417 427 ProductInfo info = loadInfoByProductId( p.first);418 ProductInfo info = loadInfoByProductId(conn, p.first); 428 419 429 420 list.append(Aleph::pair<ProductInfo, long>(info, p.second)); … … 431 422 } 432 423 433 void getProducedQuantityAndPrice(const long & id, const std::string & year, 424 void getProducedQuantityAndPrice(AutoConnection & conn, const long & id, 425 const std::string & year, 434 426 real & producedQuantity, real & price) { 435 436 AutoConnection conn;437 427 438 428 DBQuery query(conn); … … 462 452 } 463 453 464 void getProducedQuantityAndPrice(Good * good, const std::string & year) { 454 void getProducedQuantityAndPrice(AutoConnection & conn, Good * good, 455 const std::string & year) { 465 456 466 457 real producedQuantity = 0.0; … … 468 459 real price = 0.0; 469 460 470 getProducedQuantityAndPrice(good->getId(), year, producedQuantity, price); 461 getProducedQuantityAndPrice(conn, good->getId(), year, producedQuantity, 462 price); 471 463 472 464 good->setTotalQuantity(producedQuantity); … … 475 467 } 476 468 477 void getProducedQuantityAndPrice(ProductInfo & info, const std::string & year) { 478 479 getProducedQuantityAndPrice(info.productId, year, info.totalQuantity, 469 void getProducedQuantityAndPrice(AutoConnection & conn, ProductInfo & info, 470 const std::string & year) { 471 472 getProducedQuantityAndPrice(conn, info.productId, year, info.totalQuantity, 480 473 info.unitarianPrice); 481 474 } 482 475 483 real getUnitarianRequest(const size_t & inputId, const size_t & productId) { 484 485 AutoConnection conn; 476 real getUnitarianRequest(AutoConnection & conn, const size_t & inputId, 477 const size_t & productId) { 486 478 487 479 DBQuery query(conn); … … 509 501 } 510 502 511 real computeInputProportionFromSupplier(const std::string & supplierRif, 503 real computeInputProportionFromSupplier(AutoConnection & conn, 504 const std::string & supplierRif, 512 505 const std::string & supplierName, 513 506 const std::string & nationality, 514 507 const size_t & inputId, 515 508 const std::string & year) { 516 517 AutoConnection conn;518 509 519 510 DBQuery query(conn); … … 565 556 } 566 557 567 real computeProportionByTariffCode(const std::string & tariffCode, 558 real computeProportionByTariffCode(AutoConnection & conn, 559 const std::string & tariffCode, 568 560 const std::string & rif, 569 561 const size_t & productId, 570 562 const std::string & year) { 571 572 AutoConnection conn;573 563 574 564 DBQuery query(conn); … … 626 616 } 627 617 628 void computeArcQuantityUpstream( Good * src, Good * tgt,618 void computeArcQuantityUpstream(AutoConnection & conn, Good * src, Good * tgt, 629 619 const std::string & year, ArcInfo & info) { 630 620 … … 652 642 653 643 real proportionFromSupplier = 654 computeInputProportionFromSupplier( rif, companyName, nationality,644 computeInputProportionFromSupplier(conn, rif, companyName, nationality, 655 645 info.inputId, year); 656 646 657 647 real proportionByTariffCode = 658 computeProportionByTariffCode( src->getTariffCode(), rif,648 computeProportionByTariffCode(conn, src->getTariffCode(), rif, 659 649 src->getId(), year); 660 650 … … 665 655 } 666 656 667 real getDeclaredBoughtQuantity(const std::string & rif, const long & inputId, 668 const std::string & year) { 669 670 AutoConnection conn; 657 real getDeclaredBoughtQuantity(AutoConnection & conn, const std::string & rif, 658 const long & inputId, const std::string & year) { 671 659 672 660 DBQuery query(conn); … … 703 691 } 704 692 705 real computePorportionByProductInput(const long & inputId, 706 const size_t & productId, 707 const std::string & year) { 708 709 AutoConnection conn; 693 real computePorportionByProductInput(AutoConnection & conn, 694 const long & inputId, 695 const size_t & productId, 696 const std::string & year) { 710 697 711 698 DBQuery query(conn); … … 753 740 } 754 741 755 real computeProportionByTartiffCode(const std::string & rif, 756 const std::string & tariffCode, 757 const long & productId, 758 const std::string & year) { 759 760 AutoConnection conn; 742 real computeProportionByTartiffCode(AutoConnection & conn, 743 const std::string & rif, 744 const std::string & tariffCode, 745 const long & productId, 746 const std::string & year) { 761 747 762 748 DBQuery query(conn); … … 811 797 } 812 798 813 void computeArcQuantityDownstream( Good * src, Good * tgt,799 void computeArcQuantityDownstream(AutoConnection & conn, Good * src, Good * tgt, 814 800 const std::string & year, ArcInfo & arcInfo) { 815 801 816 802 real proportionByProductInput = 817 computePorportionByProductInput(arcInfo.inputId, tgt->getId(), year); 803 computePorportionByProductInput(conn, arcInfo.inputId, tgt->getId(), 804 year); 818 805 819 806 … … 824 811 825 812 real declaredQuantity = 826 getDeclaredBoughtQuantity( rif, arcInfo.inputId, year);813 getDeclaredBoughtQuantity(conn, rif, arcInfo.inputId, year); 827 814 828 815 real proportion = src->getQuantity() / src->getTotalQuantity(); 829 816 830 817 real proportionByTartiffCode = 831 computeProportionByTartiffCode( rif, src->getTariffCode(), src->getId(),832 year);818 computeProportionByTartiffCode(conn, rif, src->getTariffCode(), 819 src->getId(), year); 833 820 834 821 arcInfo.quantity = declaredQuantity * proportion * … … 839 826 840 827 arcInfo.reqQuantity = 841 getUnitarianRequest(arcInfo.inputId, tgt->getId()); 842 } 843 844 real getAcquisitionPrice(Good * good, const long & id, 845 const std::string & year) { 846 847 AutoConnection conn; 828 getUnitarianRequest(conn, arcInfo.inputId, tgt->getId()); 829 } 830 831 real getAcquisitionPrice(AutoConnection & conn, Good * good, const long & id, 832 const std::string & year) { 848 833 849 834 DBQuery query(conn); … … 878 863 } 879 864 880 std::string getCountry(const long & supplierId, const std::string & field) { 881 882 AutoConnection conn; 865 std::string getCountry(AutoConnection & conn, const long & supplierId, 866 const std::string & field) { 883 867 884 868 DBQuery query(conn); … … 908 892 } 909 893 910 std::string getOrigCountry(const long & supplierId) { 911 return getCountry(supplierId, DB::ORIG_COUNTRY_ID); 912 } 913 914 std::string getProcCountry(const long & supplierId) { 915 return getCountry(supplierId, DB::PROC_COUNTRY_ID); 916 } 917 918 void listSuggestedSuppliers(const std::string & tariffCode, 894 std::string getOrigCountry(AutoConnection & conn, const long & supplierId) { 895 return getCountry(conn, supplierId, DB::ORIG_COUNTRY_ID); 896 } 897 898 std::string getProcCountry(AutoConnection & conn, const long & supplierId) { 899 return getCountry(conn, supplierId, DB::PROC_COUNTRY_ID); 900 } 901 902 void listSuggestedSuppliers(AutoConnection & conn, 903 const std::string & tariffCode, 919 904 const std::string & year, 920 905 List<ProductInfo> & list) { 921 922 AutoConnection conn;923 906 924 907 DBQuery query(conn); … … 949 932 long productId = std::atol(query.getValue(0)); 950 933 951 ProductInfo info = loadInfoByProductId( productId);952 953 getProducedQuantityAndPrice( info, year);934 ProductInfo info = loadInfoByProductId(conn, productId); 935 936 getProducedQuantityAndPrice(conn, info, year); 954 937 955 938 list.append(info); … … 957 940 } 958 941 959 void listRealProductId(const long & id, const std::string & year, 960 List<long> & ids) { 961 962 AutoConnection conn; 942 void listRealProductId(AutoConnection & conn, const long & id, 943 const std::string & year, List<long> & ids) { 963 944 964 945 DBQuery query(conn); … … 1000 981 } 1001 982 1002 std::string getInputName(const long & id) { 1003 1004 AutoConnection conn; 983 std::string getInputName(AutoConnection & conn, const long & id) { 1005 984 1006 985 DBQuery query(conn); … … 1024 1003 } 1025 1004 1026 PlantLocation getPlantLocation(const long & id) { 1027 1028 AutoConnection conn; 1005 PlantLocation getPlantLocation(AutoConnection & conn, const long & id) { 1029 1006 1030 1007 DBQuery query(conn); … … 1071 1048 } 1072 1049 1073 std::string getCiiu(const std::string & rif) { 1074 1075 AutoConnection conn; 1050 std::string getCiiu(AutoConnection & conn, const std::string & rif) { 1076 1051 1077 1052 DBQuery query(conn); … … 1102 1077 } 1103 1078 1104 real getOperatingStaffNumber( const std::string & rif,1079 real getOperatingStaffNumber(AutoConnection & conn, const std::string & rif, 1105 1080 const std::string & year) { 1106 1107 AutoConnection conn;1108 1081 1109 1082 DBQuery query(conn); … … 1147 1120 } 1148 1121 1149 real getTotalAmount(const std::string & rif, const std::string & year) { 1150 1151 AutoConnection conn; 1122 real getTotalAmount(AutoConnection & conn, const std::string & rif, 1123 const std::string & year) { 1152 1124 1153 1125 DBQuery query(conn); … … 1192 1164 } 1193 1165 1194 void listCompaniesLike( const std::string & company,1166 void listCompaniesLike(AutoConnection & conn, const std::string & company, 1195 1167 List <CompanyRifName> & list) { 1196 1197 AutoConnection conn;1198 1168 1199 1169 DBQuery query(conn); … … 1244 1214 } 1245 1215 1246 void listProductsByCompany( const std::string & rif,1216 void listProductsByCompany(AutoConnection & conn, const std::string & rif, 1247 1217 List <ProductIdName> & list) { 1248 1249 AutoConnection conn;1250 1218 1251 1219 DBQuery query(conn); … … 1287 1255 } 1288 1256 1289 void setArcMeasurementUnit(ArcInfo & info) { 1290 1291 AutoConnection conn; 1257 void setArcMeasurementUnit(AutoConnection & conn, ArcInfo & info) { 1292 1258 1293 1259 DBQuery query(conn); … … 1317 1283 } 1318 1284 1319 void getProductionYears(const long productId, List<std::string> & years) { 1320 1321 AutoConnection conn; 1285 void getProductionYears(AutoConnection & conn, const long productId, 1286 List<std::string> & years) { 1322 1287 1323 1288 DBQuery query(conn); -
simulacion/SimEscenariosEconomicos/queries.H
r7941763 r5c51ff9 32 32 33 33 # include <common.H> 34 # include <autoConnection.H> 34 35 35 36 /** Encierra una cadena entre comillas simples. … … 129 130 * @return Objeto ProductInfo con toda la información del producto consultado. 130 131 */ 131 ProductInfo loadInfoByProductId( const size_t & id);132 ProductInfo loadInfoByProductId(AutoConnection & conn, const size_t & id); 132 133 133 134 /** Carga la lista de id de los insumos para un producto dado. … … 138 139 * de los insumos. 139 140 */ 140 void listInputIds( const size_t & productId, const std::string & year,141 List <size_t> & inputIds);141 void listInputIds(AutoConnection & conn, const size_t & productId, 142 const std::string & year, List <size_t> & inputIds); 142 143 143 144 /** Carga a todos los proveedores de un insumo dado. … … 147 148 * @param[out] Lista de proveedores del insumo. 148 149 */ 149 void listInputs( const size_t & inputId, const std::string & year,150 List <InputInfo> & inputs);150 void listInputs(AutoConnection & conn, const size_t & inputId, 151 const std::string & year, List <InputInfo> & inputs); 151 152 152 153 … … 157 158 * @param[out] Lista de productos asociados al insumo. 158 159 */ 159 void productInfoFromInput( const InputInfo & inputInfo,160 void productInfoFromInput(AutoConnection & conn, const InputInfo & inputInfo, 160 161 List <ProductInfo> & list); 161 162 … … 168 169 * junto al id que se le asocia como insumo a good por cada uno. 169 170 */ 170 void listRequesters(Good * good, const std::string & year, 171 void listRequesters(AutoConnection & conn, Good * good, 172 const std::string & year, 171 173 List <Aleph::pair<ProductInfo, long>> & list); 172 174 … … 178 180 * @return cantidad de insumo para producir una unidad de producto. 179 181 */ 180 real getUnitarianRequest(const size_t & inputId, const size_t & productId); 182 real getUnitarianRequest(AutoConnection & conn, const size_t & inputId, 183 const size_t & productId); 181 184 182 185 /** Carga la cantidad producida y el precio de un producto en un año dado. … … 186 189 * @param year año de la producción. 187 190 */ 188 void getProducedQuantityAndPrice(Good * good, const std::string & year); 191 void getProducedQuantityAndPrice(AutoConnection & conn, Good * good, 192 const std::string & year); 189 193 190 194 … … 195 199 * @param year año de la producción. 196 200 */ 197 void getProducedQuantityAndPrice(ProductInfo & info, const std::string & year); 201 void getProducedQuantityAndPrice(AutoConnection & conn, ProductInfo & info, 202 const std::string & year); 198 203 199 204 /** Calcula la cantidad que se le debe asignar a un arco que va hacia aguas … … 205 210 * @param[out] info Referencia a la información del arco 206 211 */ 207 void computeArcQuantityUpstream( Good * src, Good * tgt,212 void computeArcQuantityUpstream(AutoConnection & conn, Good * src, Good * tgt, 208 213 const std::string & year, ArcInfo & info); 209 214 … … 215 220 * @return cantidad de insumo declarado. 216 221 */ 217 real getDeclaredBoughtQuantity( const std::string & rif, const long & inputId,218 222 real getDeclaredBoughtQuantity(AutoConnection & conn, const std::string & rif, 223 const long & inputId, const std::string & year); 219 224 220 225 /** Calcula la cantidad que se le debe asignar a un arco que va hacia aguas … … 227 232 * @param[in] year año de la relación. 228 233 */ 229 void computeArcQuantityDownstream( Good * src, Good * tgt,234 void computeArcQuantityDownstream(AutoConnection & conn, Good * src, Good * tgt, 230 235 const std::string & year, ArcInfo & arcInfo); 231 236 … … 238 243 * @return precio de compra del insumo. 239 244 */ 240 real getAcquisitionPrice( Good * good, const long & id,241 245 real getAcquisitionPrice(AutoConnection & conn, Good * good, const long & id, 246 const std::string & year); 242 247 243 248 /** Consulta el país de origen de una empresa. … … 246 251 * @return nombre del país de origen. 247 252 */ 248 std::string getOrigCountry( const long & supplierId);253 std::string getOrigCountry(AutoConnection & conn, const long & supplierId); 249 254 250 255 /** Consulta el país de procedencia de una empresa. … … 253 258 * @return nombre del país de procedencia. 254 259 */ 255 std::string getProcCountry( const long & supplierId);260 std::string getProcCountry(AutoConnection & conn, const long & supplierId); 256 261 257 262 /** Carga una lista de posibles proveedores para un insumo. … … 261 266 * @param[out] list Lista de posibles proveedores. 262 267 */ 263 void listSuggestedSuppliers(const std::string & tariffCode, 268 void listSuggestedSuppliers(AutoConnection & conn, 269 const std::string & tariffCode, 264 270 const std::string & year, 265 271 List<ProductInfo> & list); … … 271 277 * @param[out] ids lista de id de los productos. 272 278 */ 273 void listRealProductId( const long & id, const std::string & year,274 List<long> & ids);279 void listRealProductId(AutoConnection & conn, const long & id, 280 const std::string & year, List<long> & ids); 275 281 276 282 /** Consulta el nombre de un insumo. … … 279 285 * @return nombre del insumo. 280 286 */ 281 std::string getInputName( const long & id);287 std::string getInputName(AutoConnection & conn, const long & id); 282 288 283 289 /** Consulta la ubicación de una planta. … … 293 299 * @return valor del CIIU de la actividad económica. 294 300 */ 295 std::string getCiiu( const std::string & rif);301 std::string getCiiu(AutoConnection & conn, const std::string & rif); 296 302 297 303 /** Consulta la cantidad de emplados operativos de una unidad económica. … … 301 307 * @return cantidad de empleados en la unidad económica. 302 308 */ 303 real getOperatingStaffNumber(const std::string & rif, const std::string & year); 309 real getOperatingStaffNumber(AutoConnection & conn, const std::string & rif, 310 const std::string & year); 304 311 305 312 /** Consulta el monto total producido por una empresa en un año dado. … … 309 316 * @return monto total producido por la empresa. 310 317 */ 311 real getTotalAmount(const std::string & rif, const std::string & year); 318 real getTotalAmount(AutoConnection & conn, const std::string & rif, 319 const std::string & year); 312 320 313 321 /** Extrae los años para los cuales existe una producción. … … 316 324 * @param[out] years Lista de años para los cuales hay producción declarada. 317 325 */ 318 void getProductionYears(const long productId, List<std::string> & years); 326 void getProductionYears(AutoConnection & conn, const long productId, 327 List<std::string> & years); 319 328 320 329 struct CompanyRifName { … … 329 338 * @param[out] list Lista de pares (rif, nombre) de cada empresa coincidente. 330 339 */ 331 void listCompaniesLike( const std::string & company,340 void listCompaniesLike(AutoConnection & conn, const std::string & company, 332 341 List <CompanyRifName> & list); 333 342 … … 345 354 * @param[out] list Lista de pares (id, nombre) de cada cada producto. 346 355 */ 347 void listProductsByCompany( const std::string & rif,356 void listProductsByCompany(AutoConnection & conn, const std::string & rif, 348 357 List <ProductIdName> & list); 349 358 350 void setArcMeasurementUnit(A rcInfo & info);359 void setArcMeasurementUnit(AutoConnection & conn, ArcInfo & info); 351 360 352 361 # endif // QUERIES_H -
simulacion/SimEscenariosEconomicos/simulator.C
r6c79fb4 r5c51ff9 607 607 struct MakeSuggestions { 608 608 609 AutoConnection & conn; 610 609 611 Graph & g; 610 612 … … 619 621 ArcsIndex & arcsIndex; 620 622 621 MakeSuggestions(Graph & _g, Graph::Node * _tgt, SuggestionBuffer & _buffer, 623 MakeSuggestions(AutoConnection & _conn, 624 Graph & _g, Graph::Node * _tgt, SuggestionBuffer & _buffer, 622 625 const std::string & _year, MapProductNode & _mapProductNode, 623 626 ArcsIndex & _arcsIndex) 624 : g(_g), tgt(_tgt), buffer(_buffer), year(_year),627 : conn(_conn), g(_g), tgt(_tgt), buffer(_buffer), year(_year), 625 628 mapProductNode(_mapProductNode), arcsIndex(_arcsIndex) { 626 629 … … 639 642 ptrSuggestions = buffer.insert(group.tariffCode, SuggestionList()); 640 643 641 listSuggestedSuppliers(group.tariffCode, year, *ptrSuggestions); 644 listSuggestedSuppliers(conn, group.tariffCode, year, 645 *ptrSuggestions); 642 646 } 643 647 … … 647 651 List <long> ids; 648 652 649 listRealProductId( id, year, ids);653 listRealProductId(conn, id, year, ids); 650 654 651 655 for (SuggestionList::Iterator it(*ptrSuggestions); it.has_current(); ){ … … 778 782 struct SuggestImport { 779 783 784 AutoConnection & conn; 785 780 786 Graph & g; 781 787 … … 784 790 MapImports & map; 785 791 786 SuggestImport(Graph & _g, Graph::Node * _tgt, MapImports & _map) 787 : g(_g), tgt(_tgt), map(_map) { 792 SuggestImport(AutoConnection & _conn, 793 Graph & _g, Graph::Node * _tgt, MapImports & _map) 794 : conn(_conn), g(_g), tgt(_tgt), map(_map) { 788 795 789 796 // Empty … … 802 809 803 810 input->setQuantity(group.neededQuantity); 804 input->setName(getInputName( id));811 input->setName(getInputName(conn, id)); 805 812 806 813 Company company; … … 882 889 queue.put(start); 883 890 891 AutoConnection conn; 892 884 893 while (not queue.is_empty()) { 885 894 … … 900 909 mapGroupArcs.for_each(PutSuppliersInQueue(g, queue)); 901 910 902 mapGroupArcs.for_each(MakeSuggestions( g, p, buffer, year,911 mapGroupArcs.for_each(MakeSuggestions(conn, g, p, buffer, year, 903 912 mapProductNode, arcsIndex)); 904 913 905 mapGroupArcs.for_each(SuggestImport( g, p, mapImports));914 mapGroupArcs.for_each(SuggestImport(conn, g, p, mapImports)); 906 915 907 916 }
Note: See TracChangeset
for help on using the changeset viewer.