//================================================================================================== // P r o g r a m Interface // S o l v e _ t e n s i o n // C o n s o l e // By Bruno Bachelet //================================================================================================== // Copyright (c) 1999-2016 // Bruno Bachelet - bruno@nawouak.net - http://www.nawouak.net // // This file is part of the B++ Library. This library is free software; you can redistribute it // and/or modify it under the terms of the GNU Library General Public License as published by the // Free Software Foundation; either version 2 of the License, or (at your option) any later // version. // // This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See // the GNU Library General Public License for more details (http://www.gnu.org).
/*DESCRIPTION*/ /* This module provides facilities to execute the program in console mode. */
// File Name //------------------------------------------------------------------------------------- #line __LINE__ "program/solve_tension/console.hpp"
// Guardian //-------------------------------------------------------------------------------------- #ifndef guProgramSolveTensionConsole #define guProgramSolveTensionConsole
// Headers //--------------------------------------------------------------------------------------- #include <bpp/calendar.hpp> /*INCLUDE*/ #include <bpp/graph_problem/min_cost_tension.hpp> /*INCLUDE*/
namespace bpp {
// Importation/Exportation //----------------------------------------------------------------------- #ifdef PROGRAM_SOLVE_TENSION_DLL #define dll_export DLL_EXPORT #else #define dll_export DLL_IMPORT #endif
// Namespaces //------------------------------------------------------------------------------------ #define public_area programSolveTensionConsole #define private_area programSolveTensionConsole_private
namespace public_area { /*NAMESPACE*/ using namespace graphProblemMinCostTension; } namespace private_area { using namespace public_area; }
extern_module_name;
// Initialization //-------------------------------------------------------------------------------- #define iniProgramSolveTensionConsole has_initializer;
// Macrocommands //---------------------------------------------------------------------------------
// Types & Classes //------------------------------------------------------------------------------- namespace public_area {} namespace private_area {}
// Functions Interface //--------------------------------------------------------------------------- namespace public_area { function tyReturn run(tyCardinal,tcString []); } namespace private_area {}
// Errors //---------------------------------------------------------------------------------------- namespace public_area { /*ERROR*/ extern_error erSyntax; /* Syntax error in the command line. */ }
// Constants & Variables //------------------------------------------------------------------------- namespace public_area {} namespace private_area {}
// X X X Interface //------------------------------------------------------------------------------ namespace {}
// Functions Inline //------------------------------------------------------------------------------ namespace public_area {} namespace private_area {}
// X X X Inline //--------------------------------------------------------------------------------- namespace {}
// End //------------------------------------------------------------------------------------------- } #undef dll_export #undef public_area #undef private_area #endif |
//================================================================================================== // P r o g r a m Implementation // S o l v e _ t e n s i o n // C o n s o l e // By Bruno Bachelet //================================================================================================== // Copyright (c) 1999-2016 // Bruno Bachelet - bruno@nawouak.net - http://www.nawouak.net // // This file is part of the B++ Library. This library is free software; you can redistribute it // and/or modify it under the terms of the GNU Library General Public License as published by the // Free Software Foundation; either version 2 of the License, or (at your option) any later // version. // // This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See // the GNU Library General Public License for more details (http://www.gnu.org).
// File Name //------------------------------------------------------------------------------------- #line __LINE__ "program/solve_tension/console.cpp"
// DLL Belonging //--------------------------------------------------------------------------------- #define PROGRAM_SOLVE_TENSION_DLL
// Headers //--------------------------------------------------------------------------------------- #include <bpp/program/solve_tension/console.hpp> /*INTERFACE*/
namespace bpp {
// Namespaces //------------------------------------------------------------------------------------ #define public_area programSolveTensionConsole #define private_area programSolveTensionConsole_private #define dll_export DLL_EXPORT
namespace public_area {} namespace private_area {}
static_module_name("Program/Solve_tension/Console");
// Initialization //-------------------------------------------------------------------------------- #undef iniProgramSolveTensionConsole static_constant(private_area::clInitializer,goInitializer);
// Errors //---------------------------------------------------------------------------------------- namespace public_area { static_error erSyntax; }
// Constants & Variables //------------------------------------------------------------------------- namespace public_area {} namespace private_area {}
// Static Members //-------------------------------------------------------------------------------- namespace public_area {} namespace private_area {}
// Functions Implementation //---------------------------------------------------------------------- namespace public_area { //----------------------------------------------------------------------------------------------Run /*FUNCTION*/ /* Start function of the program. It deals with the commands the user gives through a command line and executes the appropriate functions. */ function tyReturn run(tyCardinal agCounter,tcString agParameterS[]) { method_name("run");
typedef graphProblemMinCostTensionStructure::clLinearArcData clLinearArcData; typedef graphProblemMinCostTensionStructure::clNodeData clNodeData; typedef graphProblemMinCostTensionStructure::clVariableContent clVariableContent;
graphProblemMinCostTension::clBinaryGraph lcBinaryGraph; tyInteger lcClock; clString lcCommand; graphProblemMinCostTension::clConvexGraph1 lcConvexGraph1; graphProblemMinCostTension::clConvexGraph2 lcConvexGraph2; tyCardinal lcCounter2; graphProblemMinCostTension::clDiscreteGraph lcDiscreteGraph; tyBoolean lcError; clInFile lcFin; clOutFile lcFout; graphProblemMinCostTension::clLinearGraph lcLinearGraph; tyInteger lcNbIteration; tyCardinal lcNbNode; graphProblemMinCostTension::clPiecewiseGraph lcPiecewiseGraph; clString lcSPTreeFileName; graphProblemMinCostTension::clTensionSystem lcSystem;
tyCardinal lcCounter = 1; tyBoolean lcDecompositionPostProcessed = false; tyBoolean lcDisplayed = false; tyBoolean lcSPTree = false; tyBoolean lcShortCycles = false;
environment_private::goProgramName = "S o l v e T e n s i o n";
try { if (agCounter==1) send_error(erSyntax);
while (lcCounter<agCounter) { lcCommand=agParameterS[lcCounter]; lcError=true;
//---------------------------------------------------------------------------------------Context if (lcCommand=="+context") { lcError=false; environment::nextLine(); environment::outContext(); }
//------------------------------------------------------------------------------------------Help else if (lcCommand=="+help") { lcError=false; environment::nextLine(); environment::inform("-=-=- H E L P -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"); environment::out(" This program solves tension problems in graphs.",true,true); environment::nextLine(); environment::out(" * Syntax: [options] [commands] [input file] [output file]",true,true); environment::nextLine(); environment::out(" * Options:",true,true); environment::out(" -display = displays additional information.",true,true); environment::out(" -postdecompose = for aggregation (version 2) methods only,",true,true); environment::out(" decomposition is post-processed to be adapted",true,true); environment::out(" to the reconstruction phase.",true,true); environment::out(" -shortcycles = for linear program modeling I and II, uses short",true,true); environment::out(" cycles to create the cycle base.",true,true); environment::out(" -sptree <f> = for aggregation (version 2) methods only, uses the",true,true); environment::out(" SP-tree description stored in <f> instead of calling",true,true); environment::out(" a decomposition technique to solve the problem.",true,true); environment::out(" -temporary = keeps the temporary files used by the linear program",true,true); environment::out(" solvers.",true,true); environment::nextLine(); environment::out(" * Commands:",true,true); environment::out(" +context = shows the context of the program's running.",true,true); environment::out(" +help = shows this help.",true,true); environment::out(" +info = shows information about the program.",true,true); environment::out(" +license = shows the license of the program.",true,true); environment::out(" +aggregation1 = solves a minimum linear cost problem with the",true,true); environment::out(" \"aggregation\" algorithm. It works only with",true,true); environment::out(" a serial-parallel graph.",true,true); environment::out(" +aggregation2a = solves a minimum linear cost problem with the",true,true); environment::out(" \"aggregation\" algorithm. It works with any",true,true); environment::out(" graph. The method I is used to decompose the",true,true); environment::out(" graph into serial-parallel components.",true,true); environment::out(" +aggregation2b = solves a minimum linear cost problem with the",true,true); environment::out(" \"aggregation\" algorithm. It works with any",true,true); environment::out(" graph. The method II is used to decompose the",true,true); environment::out(" graph into serial-parallel components.",true,true); environment::out(" +aggregation2c = solves a minimum linear cost problem with the",true,true); environment::out(" \"aggregation\" algorithm. It works with any",true,true); environment::out(" graph. The method III is used to decompose the",true,true); environment::out(" graph into serial-parallel components.",true,true); environment::out(" +aggregation3a = solves a minimum binary cost problem with the",true,true); environment::out(" \"aggregation\" algorithm. It works only with",true,true); environment::out(" a serial-parallel graph. The method I is used",true,true); environment::out(" to compute the inf-convolution.",true,true); environment::out(" +aggregation3b = solves a minimum binary cost problem with the",true,true); environment::out(" \"aggregation\" algorithm. It works only with",true,true); environment::out(" a serial-parallel graph. The method II is used",true,true); environment::out(" to compute the inf-convolution, without",true,true); environment::out(" redundant cases elimination.",true,true); environment::out(" +aggregation3c = solves a minimum binary cost problem with the",true,true); environment::out(" \"aggregation\" algorithm. It works only with",true,true); environment::out(" a serial-parallel graph. The method II is used",true,true); environment::out(" to compute the inf-convolution, with",true,true); environment::out(" redundant cases elimination.",true,true); environment::out(" +bincut1 = solves a minimum binary cost problem with the",true,true); environment::out(" cutting algorithm. Subproblems are solved with",true,true); environment::out(" mixed integer programming.",true,true); environment::out(" +bincut2 = solves a minimum binary cost problem with the",true,true); environment::out(" cutting algorithm. Subproblems are solved with",true,true); environment::out(" the aggregation technique.",true,true); environment::out(" +bingreedy1a <p> = solves a minimum binary cost problem with the",true,true); environment::out(" greedy heuristic (strategy I: single fixing,",true,true); environment::out(" relaxed variables to 1 are fixed). <p> is",true,true); environment::out(" the fixing threshold.",true,true); environment::out(" +bingreedy1b <p> = solves a minimum binary cost problem with the",true,true); environment::out(" greedy heuristic (strategy I: single fixing,",true,true); environment::out(" relaxed variables to 1 are not fixed). <p> is",true,true); environment::out(" the fixing threshold.",true,true); environment::out(" +bingreedy1c <p> = solves a minimum binary cost problem with the",true,true); environment::out(" greedy heuristic (strategy I: single fixing,",true,true); environment::out(" relaxed variables to 1 are not fixed, scores",true,true); environment::out(" based on the cycle topology are used). <p> is",true,true); environment::out(" the fixing threshold.",true,true); environment::out(" +bingreedy2 <p> = solves a minimum binary cost problem with the",true,true); environment::out(" greedy heuristic (strategy II: fixing order",true,true); environment::out(" based on the topology of the cycles). <p> is",true,true); environment::out(" the fixing threshold.",true,true); environment::out(" +bingreedy3 = solves a minimum binary cost problem combining",true,true); environment::out(" the greedy heuristic (strategy II) and the",true,true); environment::out(" Lagrangean relaxation of the problem.",true,true); environment::out(" +binrelaxlag <n> = solves the Lagrangean relaxation of a minimum",true,true); environment::out(" binary cost problem. <n> is the number of",true,true); environment::out(" iterations of the subgradient method.",true,true); environment::out(" +binrelaxlin = solves the linear relaxation of a minimum",true,true); environment::out(" binary cost problem.",true,true); environment::out(" +ceconform1 <p> = solves with the precision <p> a minimum convex",true,true); environment::out(" exponential cost problem with the \"conforming\"",true,true); environment::out(" algorithm (method I).",true,true); environment::out(" +ceconform2 <p> = solves with the precision <p> a minimum convex",true,true); environment::out(" exponential cost problem with the \"conforming\"",true,true); environment::out(" algorithm (method II).",true,true); environment::out(" +ceconform3 <p> = solves with the precision <p> a minimum convex",true,true); environment::out(" exponential cost problem with the \"conforming\"",true,true); environment::out(" algorithm (method III).",true,true); environment::out(" +cqconform1 <p> = solves with the precision <p> a minimum convex",true,true); environment::out(" quadratic cost problem with the \"conforming\"",true,true); environment::out(" algorithm (method I).",true,true); environment::out(" +cqconform2 <p> = solves with the precision <p> a minimum convex",true,true); environment::out(" quadratic cost problem with the \"conforming\"",true,true); environment::out(" algorithm (method II).",true,true); environment::out(" +cqconform3 <p> = solves with the precision <p> a minimum convex",true,true); environment::out(" quadratic cost problem with the \"conforming\"",true,true); environment::out(" algorithm (method III).",true,true); environment::out(" +cfile1 = translates a minimum linear cost problem into a",true,true); environment::out(" CPLEX model using the modeling I.",true,true); environment::out(" +cfile1b = translates a minimum binary cost problem into a",true,true); environment::out(" CPLEX model using the modeling I.",true,true); environment::out(" +cfile1d = translates a minimum linear cost and discrete",true,true); environment::out(" tension problem into a CPLEX model using the",true,true); environment::out(" modeling I.",true,true); environment::out(" +cfile2 = translates a minimum linear cost problem into a",true,true); environment::out(" CPLEX model using the modeling II.",true,true); environment::out(" +cfile2b = translates a minimum binary cost problem into a",true,true); environment::out(" CPLEX model using the modeling II.",true,true); environment::out(" +cfile2d = translates a minimum linear cost and discrete",true,true); environment::out(" tension problem into a CPLEX model using the",true,true); environment::out(" modeling II.",true,true); environment::out(" +cfile3 = translates a minimum linear cost problem into a",true,true); environment::out(" CPLEX model using the modeling III.",true,true); environment::out(" +check = verifies that the tension in a graph is valid and",true,true); environment::out(" compatible (for linear cost graphs).",true,true); environment::out(" +checkb = verifies that the tension in a graph is valid and",true,true); environment::out(" compatible (for binary cost graphs).",true,true); environment::out(" +compatible1 = finds a compatible tension with the method I.",true,true); environment::out(" +compatible2 = finds a compatible tension with the method II.",true,true); environment::out(" +compatible3 = finds a compatible tension with the method III.",true,true); environment::out(" +compatible4 = finds a compatible tension with the method IV.",true,true); environment::out(" +dualcostscale = solves a minimum linear cost problem with the",true,true); environment::out(" dual cost-scaling algorithm.",true,true); environment::out(" +justcycles = eliminates the non cycles of a graph.",true,true); environment::out(" +lcapscale = solves a minimum linear cost problem with the",true,true); environment::out(" capacity-scaling version of the \"conforming\"",true,true); environment::out(" algorithm.",true,true); environment::out(" +lconform1 = solves a minimum linear cost problem with the",true,true); environment::out(" \"conforming\" algorithm (method I).",true,true); environment::out(" +lconform2 = solves a minimum linear cost problem with the",true,true); environment::out(" \"conforming\" algorithm (method II).",true,true); environment::out(" +lcostscale = solves a minimum linear cost problem with the",true,true); environment::out(" cost-scaling version of the \"conforming\"",true,true); environment::out(" algorithm.",true,true); environment::out(" +lp1 = translates a minimum linear cost problem into a",true,true); environment::out(" linear program according to the modeling I.",true,true); environment::out(" +lp1b = translates a minimum binary cost problem into a",true,true); environment::out(" linear program according to the modeling I.",true,true); environment::out(" +lp1d = translates a minimum linear cost and discrete",true,true); environment::out(" tension problem into a linear program according",true,true); environment::out(" to the modeling I.",true,true); environment::out(" +lp2 = translates a minimum linear cost problem into a",true,true); environment::out(" linear program according to the modeling II.",true,true); environment::out(" +lp2b = translates a minimum binary cost problem into a",true,true); environment::out(" linear program according to the modeling II.",true,true); environment::out(" +lp2d = translates a minimum linear cost and discrete",true,true); environment::out(" tension problem into a linear program according",true,true); environment::out(" to the modeling II.",true,true); environment::out(" +lp3 = translates a minimum linear cost problem into a",true,true); environment::out(" linear program according to the modeling III.",true,true); environment::out(" +lsolve1 = solves a minimum linear cost problem with a linear",true,true); environment::out(" solver using the modeling I.",true,true); environment::out(" +lsolve1b = solves a minimum binary cost problem with a linear",true,true); environment::out(" solver using the modeling I.",true,true); environment::out(" +lsolve1d = solves a minimum linear cost and discrete tension",true,true); environment::out(" problem with a linear solver using the modeling I.",true,true); environment::out(" +lsolve2 = solves a minimum linear cost problem with a linear",true,true); environment::out(" solver using the modeling II.",true,true); environment::out(" +lsolve2b = solves a minimum binary cost problem with a linear",true,true); environment::out(" solver using the modeling II.",true,true); environment::out(" +lsolve2d = solves a minimum linear cost and discrete tension",true,true); environment::out(" problem with a linear solver using the modeling II.",true,true); environment::out(" +lsolve3 = solves a minimum linear cost problem with a linear",true,true); environment::out(" solver using the modeling III.",true,true); environment::out(" +pconform1 = solves a minimum piecewise linear cost problem",true,true); environment::out(" with the \"conforming\" algorithm (method I).",true,true); environment::out(" +pconform2 = solves a minimum piecewise linear cost problem",true,true); environment::out(" with the \"conforming\" algorithm (method II).",true,true); environment::out(" +restrict1 = restricts the constraints of a minimum linear cost",true,true); environment::out(" problem with the method I.",true,true); environment::out(" +restrict2 = restricts the constraints of a minimum linear cost",true,true); environment::out(" problem with the method II.",true,true); environment::out(" +rsolve1 = restricts the constraints (method I) and solves a",true,true); environment::out(" minimum linear cost problem with a linear solver",true,true); environment::out(" using the modeling I.",true,true); environment::out(" +rsolve2 = restricts the constraints (method I) and solves a",true,true); environment::out(" minimum linear cost problem with a linear solver",true,true); environment::out(" using the modeling II.",true,true); environment::out(" +rsolve3 = restricts the constraints (method I) and solves a",true,true); environment::out(" minimum linear cost problem with a linear solver",true,true); environment::out(" using modeling III.",true,true); environment::out("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-",true,true); }
//------------------------------------------------------------------------------------------Info else if (lcCommand=="+info") { lcError=false; environment::nextLine(); environment::outInformation(); }
//---------------------------------------------------------------------------------------License else if (lcCommand=="+license") { lcError=false; environment::nextLine(); environment::outLicense(); }
//---------------------------------------------------------------------------------------Display else if (lcCommand=="-display") { lcError=false; lcDisplayed=true; }
//---------------------------------------------------------------------------------PostDecompose else if (lcCommand=="-postdecompose") { lcError=false; lcDecompositionPostProcessed=true; }
//-----------------------------------------------------------------------------------Shortcycles else if (lcCommand=="-shortcycles") { lcError=false; lcShortCycles=true; }
//----------------------------------------------------------------------------------------Sptree else if (lcCommand=="-sptree") { if (agCounter-lcCounter>1) { lcSPTree=true; lcSPTreeFileName=agParameterS[lcCounter+1]; ++lcCounter; lcError=false; } }
//-------------------------------------------------------------------------------------Temporary else if (lcCommand=="-temporary") { lcError=false; linearSystem::preserveTemporary(); }
//----------------------------------------------------------------------------------Aggregation1 else if (lcCommand=="+aggregation1") { if (agCounter-lcCounter>2) { typedef graphProblemMinCostTensionAggregation::clSolveSerialParallelAlgo<clLinearArcData,clNodeData> clSolveAlgo;
clGraphLayout lcGraphLayout;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcLinearGraph; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
environment::inform("Solving Problem (\"Aggregation\" Algorithm)..."); lcClock=environment::currentClock(); lcNbIteration=clSolveAlgo().run(lcLinearGraph); lcClock=environment::currentClock()-lcClock; environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Total Cost = ",false,true); environment::out(graphProblemMinCostTension::totalCost(lcLinearGraph),true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true); }
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcLinearGraph; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); lcError=false; } }
//--------------------------------------------------Aggregation2a & Aggregation2b & Agregation2c else if (lcCommand=="+aggregation2a" or lcCommand=="+aggregation2b" or lcCommand=="+aggregation2c") { if (agCounter-lcCounter>2) { typedef graphProblemMinCostTensionAggregation::clSolveAlgoI<clLinearArcData,clNodeData> clSolveAlgoI;
typedef graphProblemMinCostTensionAggregation::clSolveAlgoII<clLinearArcData,clNodeData> clSolveAlgoII;
typedef clBinaryTree<graphProblemSerialParallel::clSerialParallelData<clLinearArcData,clNodeData> > clTree;
graphProblemSerialParallel::clDecomposeAlgoI<clLinearArcData,clNodeData> lcDecomposeAlgo1; graphProblemSerialParallel::clDecomposeAlgoII<clLinearArcData,clNodeData> lcDecomposeAlgo2; graphProblemSerialParallel::clDecomposeAlgoIII<clLinearArcData,clNodeData> lcDecomposeAlgo3;
clGraphLayout lcGraphLayout; std_vector(clTree *) * lcTreeS;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcLinearGraph; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
if (lcSPTree) { lcTreeS=new_object(std_vector(clTree *)); environment::inform("Reading SP-Tree File..."); open(lcFin,lcSPTreeFileName.data(),ios::in); lcFin >> *lcTreeS; close(lcFin); if (lcFin.fail()) send_error(erFileReading); lcCounter2=0;
while (lcCounter2<lcTreeS->size()) { associateTreeWithGraph(*((*lcTreeS)[lcCounter2]),lcLinearGraph); ++lcCounter2; } } else lcTreeS=nil;
if (lcCommand=="+aggregation2a") { if (lcDecompositionPostProcessed) environment::inform("Solving Problem (\"Aggregation\" Algorithm, Post-Decomposition I)..."); else environment::inform("Solving Problem (\"Aggregation\" Algorithm, Decomposition I)..."); } else if (lcCommand=="+aggregation2b") { if (lcDecompositionPostProcessed) environment::inform("Solving Problem (\"Aggregation\" Algorithm, Post-Decomposition II)..."); else environment::inform("Solving Problem (\"Aggregation\" Algorithm, Decomposition II)..."); } else { if (lcDecompositionPostProcessed) environment::inform("Solving Problem (\"Aggregation\" Algorithm, Post-Decomposition III)..."); else environment::inform("Solving Problem (\"Aggregation\" Algorithm, Decomposition III)..."); }
lcClock=environment::currentClock();
if (lcCommand=="+aggregation2a") { if (lcDecompositionPostProcessed) lcNbIteration=clSolveAlgoII().run(lcLinearGraph,lcDecomposeAlgo1,lcTreeS,true); else lcNbIteration=clSolveAlgoI().run(lcLinearGraph,lcDecomposeAlgo1,lcTreeS,true); } else if (lcCommand=="+aggregation2b") { if (lcDecompositionPostProcessed) lcNbIteration=clSolveAlgoII().run(lcLinearGraph,lcDecomposeAlgo2,lcTreeS,true); else lcNbIteration=clSolveAlgoI().run(lcLinearGraph,lcDecomposeAlgo2,lcTreeS,true); } else { if (lcDecompositionPostProcessed) lcNbIteration=clSolveAlgoII().run(lcLinearGraph,lcDecomposeAlgo3,lcTreeS,true); else lcNbIteration=clSolveAlgoI().run(lcLinearGraph,lcDecomposeAlgo3,lcTreeS,true); }
lcClock=environment::currentClock()-lcClock; environment::out("Result = ",false,true);
if (lcSPTree) { while (lcTreeS->size()>0) { delete_object(lcTreeS->back()); lcTreeS->pop_back(); }
delete_object(lcTreeS); }
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Total Cost = ",false,true); environment::out(graphProblemMinCostTension::totalCost(lcLinearGraph),true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true); }
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcLinearGraph; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); lcError=false; } }
//-------------------------------------------------Aggregation3a & Aggregation3b & Aggregation3c else if (lcCommand=="+aggregation3a" or lcCommand=="+aggregation3b" or lcCommand=="+aggregation3c") { if (agCounter-lcCounter>2) { typedef graphProblemMinCostTensionAggregationBinary::clAggregationAlgoI<clBinaryArcData,clNodeData> clSolveAlgoI;
typedef graphProblemMinCostTensionAggregationBinary::clAggregationAlgoII<clBinaryArcData,clNodeData> clSolveAlgoII;
tyBoolean lcCaseElimination = (lcCommand=="+aggregation3c"); clGraphLayout lcGraphLayout;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcBinaryGraph; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
environment::inform("Solving Problem (\"Aggregation\" Algorithm, Binary Costs)...");
if (lcCommand=="+aggregation3a") environment::out("Raw Approach",true,true); else { environment::out("Case-Oriented Approach",true,true); environment::out("Redundant Cases Elimination = ",false,true); environment::out((lcCaseElimination ? "Yes" : "No"),true); }
lcClock=environment::currentClock();
if (lcCommand=="+aggregation3a") { environment::warn("Method not implemented yet."); lcNbIteration=clSolveAlgoI().run(lcBinaryGraph); } else lcNbIteration=clSolveAlgoII().run(lcBinaryGraph,lcCaseElimination,true);
lcClock=environment::currentClock()-lcClock; environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Total Cost = ",false,true); environment::out(graphProblemMinCostTension::totalCost(lcBinaryGraph),true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true); }
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcBinaryGraph; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); lcError=false; } }
//-----------------------------------------------------------------------------Bincut1 & Bincut2 else if (lcCommand=="+bincut1" or lcCommand=="+bincut2") { if (agCounter-lcCounter>2) { typedef graphProblemMinCostTensionBranchBound::clCuttingAlgo<clBinaryArcData,clNodeData> clSolveAlgo;
graphProblemMinCostTensionLinearSystem::clBinarySolveAlgoI<clBinaryArcData,clNodeData> lcLinearSolver;
clGraphLayout lcGraphLayout; tyReal lcLowerBound; tyBoolean lcUseMIP;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcBinaryGraph; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
environment::inform("Solving Problem (Cutting Algorithm, Binary Costs)..."); environment::out("Subproblem Resolution = ",false,true);
if (lcCommand=="+bincut1") { environment::out("Mixed Integer Programming",true); lcUseMIP=true; } else { environment::out("Aggregation Method",true); lcUseMIP=false; }
lcClock=environment::currentClock();
lcNbIteration=clSolveAlgo().run(lcBinaryGraph,lcLinearSolver,lcLowerBound, lcUseMIP,lcDisplayed);
lcClock=environment::currentClock()-lcClock; environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Total Cost = ",false,true); environment::out(graphProblemMinCostTension::totalCost(lcBinaryGraph),true); environment::out("Lower Bound = ",false,true); environment::out(lcLowerBound,true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true); }
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcBinaryGraph; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); lcError=false; } }
//------------------------------------------Bingreedy1a & Bingreedy1b & Bingreedy1c & Bingreedy2 else if (lcCommand=="+bingreedy1a" or lcCommand=="+bingreedy1b" or lcCommand=="+bingreedy1c" or lcCommand=="+bingreedy2") { if (agCounter-lcCounter>3) { typedef graphProblemMinCostTensionHeuristicBinary::clGreedyAlgoI<clBinaryArcData,clNodeData> clSolveAlgoI;
typedef graphProblemMinCostTensionHeuristicBinary::clGreedyAlgoII<clBinaryArcData,clNodeData> clSolveAlgoII;
graphProblemMinCostTensionLinearSystem::clBinarySolveAlgoI<clBinaryArcData,clNodeData> lcBinarySolveAlgo(true);
tyReal lcThreshold = real(agParameterS[++lcCounter]); tyBoolean lcOnesFixed = (lcCommand=="+bingreedy1a"); tyBoolean lcCycleScoreUsed = (lcCommand=="+bingreedy1c");
clGraphLayout lcGraphLayout;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcBinaryGraph; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
environment::inform("Solving Problem (Greedy Heuristic, Binary Costs)...");
if (lcCommand=="+bingreedy2") environment::out("Strategy II",true,true); else { environment::out("Strategy I",true,true); environment::out("Ones Fixed = ",false,true); environment::out((lcOnesFixed ? "Yes" : "No"),true); environment::out("Cycle Score Used = ",false,true); environment::out((lcCycleScoreUsed ? "Yes" : "No"),true); }
environment::out("Threshold = ",false,true); environment::out(lcThreshold,true); lcClock=environment::currentClock();
if (lcCommand=="+bingreedy2") lcNbIteration=clSolveAlgoII().run(lcBinaryGraph,lcBinarySolveAlgo,lcThreshold); else lcNbIteration=clSolveAlgoI().run(lcBinaryGraph,lcBinarySolveAlgo,lcThreshold, lcOnesFixed,lcCycleScoreUsed);
lcClock=environment::currentClock()-lcClock; environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Total Cost = ",false,true); environment::out(graphProblemMinCostTension::totalCost(lcBinaryGraph),true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true); }
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcBinaryGraph; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); lcError=false; } }
//------------------------------------------------------------------------------------Bingreedy3 else if (lcCommand=="+bingreedy3") { if (agCounter-lcCounter>2) { typedef graphProblemMinCostTensionHeuristicBinary::clLagrangeanAlgo<clBinaryArcData,clNodeData> clSolveAlgo;
clGraphLayout lcGraphLayout;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcBinaryGraph; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
environment::inform("Solving Problem (Lagrangean Heuristic, Binary Costs)..."); lcClock=environment::currentClock();
lcNbIteration=clSolveAlgo().run(lcBinaryGraph);
lcClock=environment::currentClock()-lcClock; environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Total Cost = ",false,true); environment::out(graphProblemMinCostTension::totalCost(lcBinaryGraph),true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true); }
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcBinaryGraph; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); lcError=false; } }
//-----------------------------------------------------------------------------------Binrelaxlag else if (lcCommand=="+binrelaxlag") { if (agCounter-lcCounter>2) { typedef graphProblemMinCostTensionLinearSystem::clBinarySolveAlgoI<clBinaryArcData,clNodeData> clSolveAlgo;
typedef graphProblemMinCostTension::clTensionSystemSolver tyLinearSolver;
tyReal lcLowerBound; clGraphLayout lcGraphLayout;
tyCardinal lcSubgradientIteration = cardinal(agParameterS[++lcCounter]);
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcBinaryGraph; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
environment::inform("Solving Lagrangean Relaxation (Binary Costs)...");
if (lcShortCycles) environment::out("Base = Short Cycles",true,true); else environment::out("Base = Long Cycles",true,true);
lcClock=environment::currentClock();
lcNbIteration=clSolveAlgo(lcShortCycles). solveLagrangeanRelaxation(lcBinaryGraph,tyLinearSolver::defaultSolver(), lcSubgradientIteration,lcLowerBound);
lcClock=environment::currentClock()-lcClock; environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Total Cost = ",false,true); environment::out(lcLowerBound,true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true); }
lcError=false; } }
//-----------------------------------------------------------------------------------Binrelaxlin else if (lcCommand=="+binrelaxlin") { if (agCounter-lcCounter>1) { typedef graphProblemMinCostTensionLinearSystem::clBinarySolveAlgoI<clBinaryArcData,clNodeData> clSolveAlgo;
typedef graphProblemMinCostTension::clTensionSystemSolver tyLinearSolver;
tyReal lcLowerBound; clGraphLayout lcGraphLayout;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcBinaryGraph; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
environment::inform("Solving Linear Relaxation (Binary Costs)...");
if (lcShortCycles) environment::out("Base = Short Cycles",true,true); else environment::out("Base = Long Cycles",true,true);
lcClock=environment::currentClock();
lcNbIteration=clSolveAlgo(lcShortCycles). solveLinearRelaxation(lcBinaryGraph,tyLinearSolver::defaultSolver(), lcLowerBound);
lcClock=environment::currentClock()-lcClock; environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Total Cost = ",false,true); environment::out(lcLowerBound,true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true); }
lcError=false; } }
//------------------------------------------------------------------------------------Ceconform1 else if (lcCommand=="+ceconform1") { if (agCounter-lcCounter>3) { typedef graphProblemMinCostTensionConformingConvex::clSolveAlgoI<clConvexArcData2,clNodeData> clSolveAlgo;
tyReal lcPrecision = real(agParameterS[++lcCounter]);
clGraphLayout lcGraphLayout;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcConvexGraph2; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading); environment::out(tyCardinal(lcConvexGraph2.nodes().size()),false,true); environment::out(" Nodes",true); environment::out(tyCardinal(lcConvexGraph2.arcs().size()),false,true); environment::out(" Arcs",true);
environment::inform("Solving Problem..."); environment::out("\"Conforming\" Algorithm, Convex Exponential Cost, Method I",true,true); lcClock=environment::currentClock(); lcNbIteration=clSolveAlgo().run(lcConvexGraph2,lcPrecision); lcClock=environment::currentClock()-lcClock; environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Total Cost = ",false,true); environment::out(graphProblemMinCostTension::totalCost(lcConvexGraph2),true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true); }
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcConvexGraph2; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); lcError=false; } }
//------------------------------------------------------------------------------------Ceconform2 else if (lcCommand=="+ceconform2") { if (agCounter-lcCounter>3) { typedef graphProblemMinCostTensionConformingConvex::clSolveAlgoII<clConvexArcData2,clNodeData> clSolveAlgo;
tyReal lcPrecision = real(agParameterS[++lcCounter]);
clGraphLayout lcGraphLayout;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcConvexGraph2; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading); environment::out(tyCardinal(lcConvexGraph2.nodes().size()),false,true); environment::out(" Nodes",true); environment::out(tyCardinal(lcConvexGraph2.arcs().size()),false,true); environment::out(" Arcs",true);
environment::inform("Solving Problem..."); environment::out("\"Conforming\" Algorithm, Convex Exponential Cost, Method II",true,true); lcClock=environment::currentClock(); lcNbIteration=clSolveAlgo().run(lcConvexGraph2,lcPrecision); lcClock=environment::currentClock()-lcClock; environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Total Cost = ",false,true); environment::out(graphProblemMinCostTension::totalCost(lcConvexGraph2),true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true); }
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcConvexGraph2; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); lcError=false; } }
//------------------------------------------------------------------------------------Ceconform3 else if (lcCommand=="+ceconform3") { if (agCounter-lcCounter>3) { typedef graphProblemMinCostTensionConformingConvex::clSolveAlgoIII<clConvexArcData2,clNodeData> clSolveAlgo;
tyReal lcPrecision = real(agParameterS[++lcCounter]);
clGraphLayout lcGraphLayout;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcConvexGraph2; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading); environment::out(tyCardinal(lcConvexGraph2.nodes().size()),false,true); environment::out(" Nodes",true); environment::out(tyCardinal(lcConvexGraph2.arcs().size()),false,true); environment::out(" Arcs",true);
environment::inform("Solving Problem..."); environment::out("\"Conforming\" Algorithm, Convex Exponential Cost, Method III",true,true); lcClock=environment::currentClock(); lcNbIteration=clSolveAlgo().run(lcConvexGraph2,lcPrecision,true); lcClock=environment::currentClock()-lcClock; environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Total Cost = ",false,true); environment::out(graphProblemMinCostTension::totalCost(lcConvexGraph2),true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true); }
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcConvexGraph2; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); lcError=false; } }
//------------------------------------------------------------------------------------Cqconform1 else if (lcCommand=="+cqconform1") { if (agCounter-lcCounter>3) { typedef graphProblemMinCostTensionConformingConvex::clSolveAlgoI<clConvexArcData1,clNodeData> clSolveAlgo;
tyReal lcPrecision = real(agParameterS[++lcCounter]);
clGraphLayout lcGraphLayout;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcConvexGraph1; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading); environment::out(tyCardinal(lcConvexGraph1.nodes().size()),false,true); environment::out(" Nodes",true); environment::out(tyCardinal(lcConvexGraph1.arcs().size()),false,true); environment::out(" Arcs",true);
environment::inform("Solving Problem..."); environment::out("\"Conforming\" Algorithm, Convex Quadratic Cost, Method I",true,true); lcClock=environment::currentClock(); lcNbIteration=clSolveAlgo().run(lcConvexGraph1,lcPrecision); lcClock=environment::currentClock()-lcClock; environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Total Cost = ",false,true); environment::out(graphProblemMinCostTension::totalCost(lcConvexGraph1),true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true); }
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcConvexGraph1; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); lcError=false; } }
//------------------------------------------------------------------------------------Cqconform2 else if (lcCommand=="+cqconform2") { if (agCounter-lcCounter>3) { typedef graphProblemMinCostTensionConformingConvex::clSolveAlgoII<clConvexArcData1,clNodeData> clSolveAlgo;
tyReal lcPrecision = real(agParameterS[++lcCounter]);
clGraphLayout lcGraphLayout;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcConvexGraph1; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading); environment::out(tyCardinal(lcConvexGraph1.nodes().size()),false,true); environment::out(" Nodes",true); environment::out(tyCardinal(lcConvexGraph1.arcs().size()),false,true); environment::out(" Arcs",true);
environment::inform("Solving Problem..."); environment::out("\"Conforming\" Algorithm, Convex Quadratic Cost, Method II",true,true); lcClock=environment::currentClock(); lcNbIteration=clSolveAlgo().run(lcConvexGraph1,lcPrecision); lcClock=environment::currentClock()-lcClock; environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Total Cost = ",false,true); environment::out(graphProblemMinCostTension::totalCost(lcConvexGraph1),true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true); }
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcConvexGraph1; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); lcError=false; } }
//------------------------------------------------------------------------------------Cqconform3 else if (lcCommand=="+cqconform3") { if (agCounter-lcCounter>3) { typedef graphProblemMinCostTensionConformingConvex::clSolveAlgoIII<clConvexArcData1,clNodeData> clSolveAlgo;
tyReal lcPrecision = real(agParameterS[++lcCounter]);
clGraphLayout lcGraphLayout;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcConvexGraph1; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading); environment::out(tyCardinal(lcConvexGraph1.nodes().size()),false,true); environment::out(" Nodes",true); environment::out(tyCardinal(lcConvexGraph1.arcs().size()),false,true); environment::out(" Arcs",true);
environment::inform("Solving Problem..."); environment::out("\"Conforming\" Algorithm, Convex Quadratic Cost, Method III",true,true); lcClock=environment::currentClock(); lcNbIteration=clSolveAlgo().run(lcConvexGraph1,lcPrecision,true); lcClock=environment::currentClock()-lcClock; environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Total Cost = ",false,true); environment::out(graphProblemMinCostTension::totalCost(lcConvexGraph1),true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true); }
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcConvexGraph1; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); lcError=false; } }
//----------------------------------------------------------------------Cfile1 & Cfile2 & Cfile3 else if (lcCommand=="+cfile1" or lcCommand=="+cfile2" or lcCommand=="+cfile3") { if (agCounter-lcCounter>2) { typedef graphProblemMinCostTensionLinearSystem::clLinearSolveAlgoI<clLinearArcData,clNodeData> clSolveAlgoI;
typedef graphProblemMinCostTensionLinearSystem::clLinearSolveAlgoII<clLinearArcData,clNodeData> clSolveAlgoII;
typedef graphProblemMinCostTensionLinearSystem::clLinearSolveAlgoIII<clLinearArcData,clNodeData> clSolveAlgoIII;
typedef linearSystemCplex::clCplexSolver<clVariableContent> clCplexSolver;
lcError=false; environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcLinearGraph; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
if (lcCommand=="+cfile1") { environment::inform("Linear Program Building (Modeling I)...");
if (lcShortCycles) environment::out("Base = Short Cycles",true,true); else environment::out("Base = Long Cycles",true,true);
clSolveAlgoI(lcShortCycles).buildLinearSystem(lcSystem,lcLinearGraph); } else if (lcCommand=="+cfile2") { environment::inform("Linear Program Building (Modeling II)...");
if (lcShortCycles) environment::out("Base = Short Cycles",true,true); else environment::out("Base = Long Cycles",true,true);
clSolveAlgoII(lcShortCycles).buildLinearSystem(lcSystem,lcLinearGraph); } else { environment::inform("Linear Program Building (Modeling III)..."); clSolveAlgoIII().buildLinearSystem(lcSystem,lcLinearGraph); }
environment::inform("CPLEX Model Generating..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); clCplexSolver().generateModel(lcFout,lcSystem); close(lcFout); } }
//-----------------------------------------------------------------------------Cfile1b & Cfile2b else if (lcCommand=="+cfile1b" or lcCommand=="+cfile2b") { if (agCounter-lcCounter>2) { typedef graphProblemMinCostTensionLinearSystem::clBinarySolveAlgoI<clBinaryArcData,clNodeData> clSolveAlgoI;
typedef graphProblemMinCostTensionLinearSystem::clBinarySolveAlgoII<clBinaryArcData,clNodeData> clSolveAlgoII;
typedef linearSystemCplex::clCplexSolver<clVariableContent> clCplexSolver;
lcError=false; environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcBinaryGraph; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
if (lcCommand=="+cfile1b") { environment::inform("Linear Program Building (Modeling I)...");
if (lcShortCycles) environment::out("Base = Short Cycles",true,true); else environment::out("Base = Long Cycles",true,true);
clSolveAlgoI(lcShortCycles).buildLinearSystem(lcSystem,lcBinaryGraph); } else { environment::inform("Linear Program Building (Modeling II)..."); clSolveAlgoII().buildLinearSystem(lcSystem,lcBinaryGraph); }
environment::inform("CPLEX Model Generating..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); clCplexSolver().generateModel(lcFout,lcSystem); close(lcFout); } }
//-----------------------------------------------------------------------------Cfile1d & Cfile2d else if (lcCommand=="+cfile1d" or lcCommand=="+cfile2d") { if (agCounter-lcCounter>2) { typedef graphProblemMinCostTensionLinearSystem::clDiscreteSolveAlgoI<clDiscreteArcData,clNodeData> clSolveAlgoI;
typedef graphProblemMinCostTensionLinearSystem::clDiscreteSolveAlgoII<clDiscreteArcData,clNodeData> clSolveAlgoII;
typedef linearSystemCplex::clCplexSolver<clVariableContent> clCplexSolver;
lcError=false; environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcDiscreteGraph; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
if (lcCommand=="+cfile1d") { environment::inform("Linear Program Building (Modeling I)...");
if (lcShortCycles) environment::out("Base = Short Cycles",true,true); else environment::out("Base = Long Cycles",true,true);
clSolveAlgoI(lcShortCycles).buildLinearSystem(lcSystem,lcDiscreteGraph); } else { environment::inform("Linear Program Building (Modeling II)..."); clSolveAlgoII().buildLinearSystem(lcSystem,lcDiscreteGraph); }
environment::inform("CPLEX Model Generating..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); clCplexSolver().generateModel(lcFout,lcSystem); close(lcFout); } }
//-----------------------------------------------------------------------------------------Check else if (lcCommand=="+check") { if (agCounter-lcCounter>1) { environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcLinearGraph; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
environment::inform("Checking Compatibility..."); lcLinearGraph.solved()=graphProblemTension::checkCompatibility(lcLinearGraph);
if (lcLinearGraph.solved()) environment::out("Compatible Tension",true,true); else environment::out("Incompatible Tension",true,true);
environment::inform("Computing Potential..."); lcLinearGraph.solved()=graphProblemTension::computePotential(lcLinearGraph);
if (lcLinearGraph.solved()) environment::out("Valid Tension",true,true); else environment::out("Invalid Tension",true,true);
lcError=false; } }
//----------------------------------------------------------------------------------------Checkb else if (lcCommand=="+checkb") { if (agCounter-lcCounter>1) { environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcBinaryGraph; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
environment::inform("Checking Compatibility..."); lcBinaryGraph.solved()=graphProblemTension::checkCompatibility(lcBinaryGraph);
if (lcBinaryGraph.solved()) environment::out("Compatible Tension",true,true); else environment::out("Incompatible Tension",true,true);
environment::inform("Computing Potential..."); lcBinaryGraph.solved()=graphProblemTension::computePotential(lcBinaryGraph);
if (lcBinaryGraph.solved()) environment::out("Valid Tension",true,true); else environment::out("Invalid Tension",true,true);
lcError=false; } }
//-----------------------------------------Compatible1 & Compatible2 & Compatible3 & Compatible4 else if (lcCommand=="+compatible1" or lcCommand=="+compatible2" or lcCommand=="+compatible3" or lcCommand=="+compatible4") { if (agCounter-lcCounter>2) { typedef graphProblemTensionAlgorithm::clCompatibleTensionAlgoI<clLinearArcData,clNodeData> clAlgoI;
typedef graphProblemTensionAlgorithm::clCompatibleTensionAlgoII<clLinearArcData,clNodeData> clAlgoII;
typedef graphProblemTensionAlgorithm::clCompatibleTensionAlgoIII<clLinearArcData,clNodeData> clAlgoIII;
typedef graphProblemTensionAlgorithm::clCompatibleTensionAlgoIV<clLinearArcData,clNodeData> clAlgoIV;
clGraphLayout lcGraphLayout;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcLinearGraph; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
if (lcCommand=="+compatible1") { environment::inform("Searching Compatible Tension (Method I)..."); lcClock=environment::currentClock(); lcNbIteration=clAlgoI().run(lcLinearGraph); lcClock=environment::currentClock()-lcClock; } else if (lcCommand=="+compatible2") { environment::inform("Searching Compatible Tension (Method II)..."); lcClock=environment::currentClock(); lcNbIteration=clAlgoII().run(lcLinearGraph); lcClock=environment::currentClock()-lcClock; } else if (lcCommand=="+compatible3") { environment::inform("Searching Compatible Tension (Method III)..."); lcClock=environment::currentClock(); lcNbIteration=clAlgoIII().run(lcLinearGraph); lcClock=environment::currentClock()-lcClock; } else { environment::inform("Searching Compatible Tension (Method IV)..."); lcClock=environment::currentClock(); lcNbIteration=clAlgoIV().run(lcLinearGraph); lcClock=environment::currentClock()-lcClock; }
if (not lcLinearGraph.solved()) environment::out("Inconsistent Constraints",true,true); else { environment::out("Consistent Constraints",true,true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true); }
environment::inform("Checking Compatibility..."); lcLinearGraph.solved()=graphProblemTension::checkCompatibility(lcLinearGraph);
if (lcLinearGraph.solved()) environment::out("Compatible Tension",true,true); else environment::out("Incompatible Tension",true,true);
environment::inform("Computing Potential..."); lcLinearGraph.solved()=graphProblemTension::computePotential(lcLinearGraph);
if (lcLinearGraph.solved()) environment::out("Valid Tension",true,true); else environment::out("Invalid Tension",true,true);
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcLinearGraph; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); lcError=false; } }
//---------------------------------------------------------------------------------Dualcostscale else if (lcCommand=="+dualcostscale") { if (agCounter-lcCounter>2) { typedef graphProblemMinCostTensionDualCostScaling::clSolveAlgo<clLinearArcData,clNodeData> clSolveAlgo;
clGraphLayout lcGraphLayout;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcLinearGraph; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
environment::inform("Solving Problem (Dual Cost-Scaling Algorithm, Linear Cost)..."); lcClock=environment::currentClock(); lcNbIteration=clSolveAlgo().run(lcLinearGraph); lcClock=environment::currentClock()-lcClock; environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Total Cost = ",false,true); environment::out(graphProblemMinCostTension::totalCost(lcLinearGraph),true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true); }
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcLinearGraph; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); lcError=false; } }
//------------------------------------------------------------------------------------Justcycles else if (lcCommand=="+justcycles") { if (agCounter-lcCounter>2) { clGraphLayout lcGraphLayout;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcLinearGraph; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
environment::inform("Eliminating Non Cycles..."); graph::eliminateNonCycles(lcLinearGraph);
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcLinearGraph; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); lcError=false; } }
//-------------------------------------------------------------------------------------Lcapscale else if (lcCommand=="+lcapscale") { if (agCounter-lcCounter>2) { typedef graphProblemMinCostTensionConformingLinear::clCapacityScaleAlgo<clLinearArcData,clNodeData> clSolveAlgo;
clGraphLayout lcGraphLayout;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcLinearGraph; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
environment::inform("Solving Problem (\"Conforming\" Algorithm, Linear Cost, Capacity-Scaling)..."); lcClock=environment::currentClock(); lcNbIteration=clSolveAlgo().run(lcLinearGraph); lcClock=environment::currentClock()-lcClock; environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Total Cost = ",false,true); environment::out(graphProblemMinCostTension::totalCost(lcLinearGraph),true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true); }
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcLinearGraph; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); lcError=false; } }
//-------------------------------------------------------------------------------------Lconform1 else if (lcCommand=="+lconform1") { if (agCounter-lcCounter>2) { typedef graphProblemMinCostTensionConformingLinear::clSolveAlgoI<clLinearArcData,clNodeData> clSolveAlgo;
clGraphLayout lcGraphLayout;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcLinearGraph; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
environment::inform("Solving Problem (\"Conforming\" Algorithm, Linear Cost, Method I)..."); lcClock=environment::currentClock(); lcNbIteration=clSolveAlgo().run(lcLinearGraph); lcClock=environment::currentClock()-lcClock; environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Total Cost = ",false,true); environment::out(graphProblemMinCostTension::totalCost(lcLinearGraph),true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true); }
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcLinearGraph; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); lcError=false; } }
//-------------------------------------------------------------------------------------Lconform2 else if (lcCommand=="+lconform2") { if (agCounter-lcCounter>2) { typedef graphProblemMinCostTensionConformingLinear::clSolveAlgoII<clLinearArcData,clNodeData> clSolveAlgo;
clGraphLayout lcGraphLayout;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcLinearGraph; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
environment::inform("Solving Problem (\"Conforming\" Algorithm, Linear Cost, Method II)..."); lcClock=environment::currentClock(); lcNbIteration=clSolveAlgo().run(lcLinearGraph); lcClock=environment::currentClock()-lcClock; environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Total Cost = ",false,true); environment::out(graphProblemMinCostTension::totalCost(lcLinearGraph),true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true); }
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcLinearGraph; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); lcError=false; } }
//------------------------------------------------------------------------------------Lcostscale else if (lcCommand=="+lcostscale") { if (agCounter-lcCounter>2) { typedef graphProblemMinCostTensionConformingLinear::clCostScaleAlgo<clLinearArcData,clNodeData> clSolveAlgo;
clGraphLayout lcGraphLayout;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcLinearGraph; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
environment::inform("Solving Problem (\"Conforming\" Algorithm, Linear Cost, Cost-Scaling)..."); lcClock=environment::currentClock(); lcNbIteration=clSolveAlgo().run(lcLinearGraph); lcClock=environment::currentClock()-lcClock; environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Total Cost = ",false,true); environment::out(graphProblemMinCostTension::totalCost(lcLinearGraph),true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true); }
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcLinearGraph; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); lcError=false; } }
//-------------------------------------------------------------------------------Lp1 & Lp2 & Lp3 else if (lcCommand=="+lp1" or lcCommand=="+lp2" or lcCommand=="+lp3") { if (agCounter-lcCounter>2) { typedef graphProblemMinCostTensionLinearSystem::clLinearSolveAlgoI<clLinearArcData,clNodeData> clSolveAlgoI;
typedef graphProblemMinCostTensionLinearSystem::clLinearSolveAlgoII<clLinearArcData,clNodeData> clSolveAlgoII;
typedef graphProblemMinCostTensionLinearSystem::clLinearSolveAlgoIII<clLinearArcData,clNodeData> clSolveAlgoIII;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcLinearGraph; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
if (lcCommand=="+lp1") { environment::inform("Translating Into Linear Program (Modeling I)...");
if (lcShortCycles) environment::out("Base = Short Cycles",true,true); else environment::out("Base = Long Cycles",true,true);
clSolveAlgoI(lcShortCycles).buildLinearSystem(lcSystem,lcLinearGraph); } else if (lcCommand=="+lp2") { environment::inform("Translating Into Linear Program (Modeling II)...");
if (lcShortCycles) environment::out("Base = Short Cycles",true,true); else environment::out("Base = Long Cycles",true,true);
clSolveAlgoII(lcShortCycles).buildLinearSystem(lcSystem,lcLinearGraph); } else { environment::inform("Translating Into Linear Program (Modeling III)..."); clSolveAlgoIII().buildLinearSystem(lcSystem,lcLinearGraph); }
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcSystem; close(lcFout); lcError=false; } }
//-----------------------------------------------------------------------------------Lp1b & Lp2b else if (lcCommand=="+lp1b" or lcCommand=="+lp2b") { if (agCounter-lcCounter>2) { typedef graphProblemMinCostTensionLinearSystem::clBinarySolveAlgoI<clBinaryArcData,clNodeData> clSolveAlgoI;
typedef graphProblemMinCostTensionLinearSystem::clBinarySolveAlgoII<clBinaryArcData,clNodeData> clSolveAlgoII;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcBinaryGraph; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
if (lcCommand=="+lp1b") { environment::inform("Translating Into Linear Program (Modeling I)...");
if (lcShortCycles) environment::out("Base = Short Cycles",true,true); else environment::out("Base = Long Cycles",true,true);
clSolveAlgoI(lcShortCycles).buildLinearSystem(lcSystem,lcBinaryGraph); } else { environment::inform("Translating Into Linear Program (Modeling II)..."); clSolveAlgoII().buildLinearSystem(lcSystem,lcBinaryGraph); }
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcSystem; close(lcFout); lcError=false; } }
//-----------------------------------------------------------------------------------Lp1d & Lp2d else if (lcCommand=="+lp1d" or lcCommand=="+lp2d") { if (agCounter-lcCounter>2) { typedef graphProblemMinCostTensionLinearSystem::clDiscreteSolveAlgoI<clDiscreteArcData,clNodeData> clSolveAlgoI;
typedef graphProblemMinCostTensionLinearSystem::clDiscreteSolveAlgoII<clDiscreteArcData,clNodeData> clSolveAlgoII;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcDiscreteGraph; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
if (lcCommand=="+lp1d") { environment::inform("Translating Into Linear Program (Modeling I)...");
if (lcShortCycles) environment::out("Base = Short Cycles",true,true); else environment::out("Base = Long Cycles",true,true);
clSolveAlgoI(lcShortCycles).buildLinearSystem(lcSystem,lcDiscreteGraph); } else { environment::inform("Translating Into Linear Program (Modeling II)..."); clSolveAlgoII().buildLinearSystem(lcSystem,lcDiscreteGraph); }
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcSystem; close(lcFout); lcError=false; } }
//-------------------------------------------------------------------Lsolve1 & Lsolve2 & Lsolve3 else if (lcCommand=="+lsolve1" or lcCommand=="+lsolve2" or lcCommand=="+lsolve3") { if (agCounter-lcCounter>2) { typedef graphProblemMinCostTensionLinearSystem::clLinearSolveAlgoI<clLinearArcData,clNodeData> clSolveAlgoI;
typedef graphProblemMinCostTensionLinearSystem::clLinearSolveAlgoII<clLinearArcData,clNodeData> clSolveAlgoII;
typedef graphProblemMinCostTensionLinearSystem::clLinearSolveAlgoIII<clLinearArcData,clNodeData> clSolveAlgoIII;
typedef graphProblemMinCostTension::clTensionSystemSolver tyLinearSolver;
clGraphLayout lcGraphLayout;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcLinearGraph; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
if (lcCommand=="+lsolve1") { environment::inform("Solving Problem (Linear Program Resolution, Modeling I)...");
if (lcShortCycles) environment::out("Base = Short Cycles",true,true); else environment::out("Base = Long Cycles",true,true);
lcClock=environment::currentClock(); lcNbIteration=clSolveAlgoI(lcShortCycles).run(lcLinearGraph,tyLinearSolver::defaultSolver()); lcClock=environment::currentClock()-lcClock; } else if (lcCommand=="+lsolve2") { environment::inform("Solving Problem (Linear Program Resolution, Modeling II)...");
if (lcShortCycles) environment::out("Base = Short Cycles",true,true); else environment::out("Base = Long Cycles",true,true);
lcClock=environment::currentClock();
lcNbIteration=clSolveAlgoII(lcShortCycles).run(lcLinearGraph, tyLinearSolver::defaultSolver());
lcClock=environment::currentClock()-lcClock; } else { environment::inform("Solving Problem (Linear Program Resolution, Modeling III)..."); lcClock=environment::currentClock(); lcNbIteration=clSolveAlgoIII().run(lcLinearGraph,tyLinearSolver::defaultSolver()); lcClock=environment::currentClock()-lcClock; }
environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Total Cost = ",false,true); environment::out(graphProblemMinCostTension::totalCost(lcLinearGraph),true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true); }
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcLinearGraph; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); }
lcError=false; }
//---------------------------------------------------------------------------Lsolve1b & Lsolve2b else if (lcCommand=="+lsolve1b" or lcCommand=="+lsolve2b") { if (agCounter-lcCounter>2) { typedef graphProblemMinCostTensionLinearSystem::clBinarySolveAlgoI<clBinaryArcData,clNodeData> clSolveAlgoI;
typedef graphProblemMinCostTensionLinearSystem::clBinarySolveAlgoII<clBinaryArcData,clNodeData> clSolveAlgoII;
typedef graphProblemMinCostTension::clTensionSystemSolver tyLinearSolver;
clGraphLayout lcGraphLayout; tyLinearSolver & lcSolver = tyLinearSolver::defaultSolver();
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcBinaryGraph; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
if (lcCommand=="+lsolve1b") { environment::inform("Solving Problem (Linear Program Resolution, Modeling I)...");
if (lcShortCycles) environment::out("Base = Short Cycles",true,true); else environment::out("Base = Long Cycles",true,true);
lcClock=environment::currentClock(); lcNbIteration=clSolveAlgoI(lcShortCycles).run(lcBinaryGraph,lcSolver); lcNbNode=lcSolver.lastBranchingNodesNumber(); lcClock=environment::currentClock()-lcClock; } else { environment::inform("Solving Problem (Linear Program Resolution, Modeling II)..."); lcClock=environment::currentClock(); lcNbIteration=clSolveAlgoII().run(lcBinaryGraph,lcSolver); lcNbNode=lcSolver.lastBranchingNodesNumber(); lcClock=environment::currentClock()-lcClock; }
environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Branching Nodes = ",false,true); environment::out(lcNbNode,true); environment::out("Total Cost = ",false,true); environment::out(graphProblemMinCostTension::totalCost(lcBinaryGraph),true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true); }
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcBinaryGraph; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); }
lcError=false; }
//---------------------------------------------------------------------------Lsolve1d & Lsolve2d else if (lcCommand=="+lsolve1d" or lcCommand=="+lsolve2d") { if (agCounter-lcCounter>2) { typedef graphProblemMinCostTensionLinearSystem::clDiscreteSolveAlgoI<clDiscreteArcData,clNodeData> clSolveAlgoI;
typedef graphProblemMinCostTensionLinearSystem::clDiscreteSolveAlgoII<clDiscreteArcData,clNodeData> clSolveAlgoII;
typedef graphProblemMinCostTension::clTensionSystemSolver tyLinearSolver;
clGraphLayout lcGraphLayout; tyLinearSolver & lcSolver = tyLinearSolver::defaultSolver();
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcDiscreteGraph; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
if (lcCommand=="+lsolve1d") { environment::inform("Solving Problem (Linear Program Resolution, Modeling I)...");
if (lcShortCycles) environment::out("Base = Short Cycles",true,true); else environment::out("Base = Long Cycles",true,true);
lcClock=environment::currentClock(); lcNbIteration=clSolveAlgoI(lcShortCycles).run(lcDiscreteGraph,lcSolver); lcNbNode=lcSolver.lastBranchingNodesNumber(); lcClock=environment::currentClock()-lcClock; } else { environment::inform("Solving Problem (Linear Program Resolution, Modeling II)..."); lcClock=environment::currentClock(); lcNbIteration=clSolveAlgoII().run(lcDiscreteGraph,lcSolver); lcNbNode=lcSolver.lastBranchingNodesNumber(); lcClock=environment::currentClock()-lcClock; }
environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Branching Nodes = ",false,true); environment::out(lcNbNode,true); environment::out("Total Cost = ",false,true); environment::out(graphProblemMinCostTension::totalCost(lcDiscreteGraph),true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true); }
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcDiscreteGraph; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); }
lcError=false; }
//-------------------------------------------------------------------------------------Pconform1 else if (lcCommand=="+pconform1") { if (agCounter-lcCounter>2) { typedef graphProblemMinCostTensionConformingPiecewise::clSolveAlgoI<clPiecewiseArcData,clNodeData> clSolveAlgo;
clGraphLayout lcGraphLayout;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcPiecewiseGraph; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
environment::inform("Solving Problem (\"Conforming\" Algorithm, Piecewise Cost, Method I)..."); lcClock=environment::currentClock(); lcNbIteration=clSolveAlgo().run(lcPiecewiseGraph); lcClock=environment::currentClock()-lcClock; environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Total Cost = ",false,true); environment::out(graphProblemMinCostTension::totalCost(lcPiecewiseGraph),true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true); }
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcLinearGraph; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); lcError=false; } }
//-------------------------------------------------------------------------------------Pconform2 else if (lcCommand=="+pconform2") { if (agCounter-lcCounter>2) { typedef graphProblemMinCostTensionConformingPiecewise::clSolveAlgoII<clPiecewiseArcData,clNodeData> clSolveAlgo;
clGraphLayout lcGraphLayout;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcPiecewiseGraph; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
environment::inform("Solving Problem (\"Conforming\" Algorithm, Piecewise Cost, Method II)..."); lcClock=environment::currentClock(); lcNbIteration=clSolveAlgo().run(lcPiecewiseGraph); lcClock=environment::currentClock()-lcClock; environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Total Cost = ",false,true); environment::out(graphProblemMinCostTension::totalCost(lcPiecewiseGraph),true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true); }
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcLinearGraph; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); lcError=false; } }
//-------------------------------------------------------------------------------------Restrict1 else if (lcCommand=="+restrict1") { if (agCounter-lcCounter>2) { typedef graphProblemMinCostTensionAlgorithm::clRestrictConstraintsAlgoI<clLinearArcData,clNodeData> clAlgoI;
tyReal lcCostOffset; clGraphLayout lcGraphLayout;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcLinearGraph; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
environment::inform("Restricting Constraints (Method I)..."); lcClock=environment::currentClock(); lcNbIteration=clAlgoI().run(lcLinearGraph); lcClock=environment::currentClock()-lcClock; environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true);
environment::inform("Adjusting Optimal Tensions..."); lcCostOffset=graphProblemMinCostTensionAlgorithm::adjustOptimalTensions(lcLinearGraph); environment::out("Cost Offset = ",false,true); environment::out(lcCostOffset,true);
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcLinearGraph.solved()=false; lcFout << lcLinearGraph; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); }
lcError=false; } }
//-------------------------------------------------------------------------------------Restrict2 else if (lcCommand=="+restrict2") { if (agCounter-lcCounter>2) { typedef graphProblemMinCostTensionAlgorithm::clRestrictConstraintsAlgoII<clLinearArcData,clNodeData> clAlgoII;
tyReal lcCostOffset; clGraphLayout lcGraphLayout;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcLinearGraph; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
environment::inform("Restricting Constraints (Method II)..."); lcClock=environment::currentClock(); lcNbIteration=clAlgoII().run(lcLinearGraph); lcClock=environment::currentClock()-lcClock; environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true);
environment::inform("Adjusting Optimal Tensions..."); lcCostOffset=graphProblemMinCostTensionAlgorithm::adjustOptimalTensions(lcLinearGraph); environment::out("Cost Offset = ",false,true); environment::out(lcCostOffset,true);
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcLinearGraph.solved()=false; lcFout << lcLinearGraph; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); }
lcError=false; } }
//-------------------------------------------------------------------Rsolve1 & Rsolve2 & Rsolve3 else if (lcCommand=="+rsolve1" or lcCommand=="+rsolve2" or lcCommand=="+rsolve3") { if (agCounter-lcCounter>2) { typedef graphProblemMinCostTensionAlgorithm::clRestrictConstraintsAlgo<clLinearArcData,clNodeData> clRestrictAlgo;
typedef graphProblemMinCostTensionLinearSystem::clLinearSolveAlgoI<clLinearArcData,clNodeData> clSolveAlgoI;
typedef graphProblemMinCostTensionLinearSystem::clLinearSolveAlgoII<clLinearArcData,clNodeData> clSolveAlgoII;
typedef graphProblemMinCostTensionLinearSystem::clLinearSolveAlgoIII<clLinearArcData,clNodeData> clSolveAlgoIII;
typedef graphProblemMinCostTension::clTensionSystemSolver tyLinearSolver;
clGraphLayout lcGraphLayout;
environment::nextLine(); environment::inform("Reading Input File..."); open(lcFin,agParameterS[++lcCounter],ios::in); lcFin >> lcLinearGraph; lcFin >> lcGraphLayout; close(lcFin); if (lcFin.fail()) send_error(erFileReading);
environment::inform("Restricting Constraints..."); lcNbIteration=clRestrictAlgo::defaultRun(lcLinearGraph); environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); }
if (lcCommand=="+rsolve1") { environment::inform("Solving Problem (Linear Program Resolution, Modeling I)...");
if (lcShortCycles) environment::out("Base = Short Cycles",true,true); else environment::out("Base = Long Cycles",true,true);
lcClock=environment::currentClock(); lcNbIteration=clSolveAlgoI(lcShortCycles).run(lcLinearGraph,tyLinearSolver::defaultSolver()); lcClock=environment::currentClock()-lcClock; } else if (lcCommand=="+rsolve2") { environment::inform("Solving Problem (Linear Program Resolution, Modeling II)...");
if (lcShortCycles) environment::out("Base = Short Cycles",true,true); else environment::out("Base = Long Cycles",true,true);
lcClock=environment::currentClock();
lcNbIteration=clSolveAlgoII(lcShortCycles).run(lcLinearGraph, tyLinearSolver::defaultSolver());
lcClock=environment::currentClock()-lcClock; } else { environment::inform("Solving Problem (Linear Program Resolution, Modeling III)..."); lcClock=environment::currentClock(); lcNbIteration=clSolveAlgoIII().run(lcLinearGraph,tyLinearSolver::defaultSolver()); lcClock=environment::currentClock()-lcClock; }
environment::out("Result = ",false,true);
if (lcNbIteration<0) environment::out("Inconsistent Constraints",true); else { environment::out("Consistent Constraints",true); environment::out("Iterations = ",false,true); environment::out(lcNbIteration,true); environment::out("Total Cost = ",false,true); environment::out(graphProblemMinCostTension::totalCost(lcLinearGraph),true); environment::out("Resolution Time = ",false,true); environment::out(tyInteger(lcClock),true); }
environment::inform("Writing Output File..."); open(lcFout,agParameterS[++lcCounter],ios::out|ios::trunc); lcFout << lcLinearGraph; if (lcGraphLayout.size()>0) lcFout << end_line << end_line; lcFout << lcGraphLayout; close(lcFout); }
lcError=false; }
if (lcError) send_error(erSyntax); lcCounter++; } }
program_catch; } }
namespace private_area {}
// X X X Implementation //------------------------------------------------------------------------- namespace {}
// I n i t i a l i z e r Implementation //--------------------------------------------------------- namespace private_area { //--------------------------------------------------------------------------------------------Start property void clInitializer::start(void) { if (atCounter++ == 0) { try { #include <bpp/modules.hpp> /*NEED*/ registerStop(this); environment::informInitialization(goModuleName);
erSyntax.create("Solve Tension - Use the '+help' parameter to get some help."); }
initializer_catch; } } //---------------------------------------------------------------------------------------------Stop property void clInitializer::stop(void) { environment::informTermination(goModuleName); } }
// End //------------------------------------------------------------------------------------------- } |
|