Lesson sources have updated to use configuration files
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@958 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
9d9e5d4b3d
commit
01da681c6a
15 changed files with 305 additions and 79 deletions
|
|
@ -91,7 +91,7 @@ class moSimpleSolutionTabuList: public moTabuList < M >
|
|||
M move=(M)_move;
|
||||
EOT solution=(EOT) _solution;
|
||||
|
||||
_move(_solution);
|
||||
move(solution);
|
||||
|
||||
if (memory_size!=0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -33,22 +33,27 @@
|
|||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
#include <eo>
|
||||
#include <mo>
|
||||
#include <tsp>
|
||||
|
||||
void manage_configuration_file(eoParser & _parser);
|
||||
|
||||
int
|
||||
main (int _argc, char* _argv [])
|
||||
{
|
||||
if (_argc != 2)
|
||||
{
|
||||
std::string instancePath;
|
||||
unsigned int seed;
|
||||
|
||||
std :: cerr << "Usage : ./hill_climbing [instance]" << std :: endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
eoParser parser(_argc, _argv);
|
||||
|
||||
srand (1000);
|
||||
manage_configuration_file(parser);
|
||||
|
||||
Graph::load(_argv [1]);
|
||||
seed=atoi( (parser.getParamWithLongName("seed")->getValue()).c_str() );
|
||||
instancePath=parser.getParamWithLongName("instancePath")->getValue();
|
||||
|
||||
srand (seed);
|
||||
Graph::load(instancePath.c_str());
|
||||
|
||||
Route solution;
|
||||
|
||||
|
|
@ -82,3 +87,26 @@ main (int _argc, char* _argv [])
|
|||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void
|
||||
manage_configuration_file(eoParser & _parser)
|
||||
{
|
||||
std::ofstream os;
|
||||
|
||||
_parser.getORcreateParam(std::string("../examples/tsp/benchs/berlin52.tsp"), "instancePath", "Path to the instance.",
|
||||
0, "Configuration", false);
|
||||
_parser.getORcreateParam((unsigned int)time(0), "seed", "Seed for rand.", 0, "Configuration", false);
|
||||
|
||||
if (_parser.userNeedsHelp())
|
||||
{
|
||||
_parser.printHelp(std::cout);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
os.open("current_param");
|
||||
if(!os.is_open())
|
||||
{
|
||||
throw std::runtime_error("[hill_climbing.cpp]: the file current_param cannot be created.");
|
||||
}
|
||||
os <<_parser;
|
||||
os.close();
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
8
trunk/paradiseo-mo/tutorial/Lesson1/param
Normal file
8
trunk/paradiseo-mo/tutorial/Lesson1/param
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
###### General ######
|
||||
# --help=0 # -h : Prints this message
|
||||
# --stopOnUnknownParam=1 # Stop if unkown param entered
|
||||
|
||||
###### Configuration ######
|
||||
# --instancePath=../examples/tsp/benchs/berlin52.tsp # Path to the instance
|
||||
# --seed=1202916317 # Seed for rand
|
||||
Binary file not shown.
11
trunk/paradiseo-mo/tutorial/Lesson2/param
Normal file
11
trunk/paradiseo-mo/tutorial/Lesson2/param
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
###### General ######
|
||||
# --help=0 # -h : Prints this message
|
||||
# --stopOnUnknownParam=1 # Stop if unkown param entered
|
||||
|
||||
###### Configuration ######
|
||||
# --instancePath=../examples/tsp/benchs/berlin52.tsp # Path to the instance
|
||||
# --seed=1202917905 # Seed for rand
|
||||
# --tabuListSize=10 # Size of the tabu list
|
||||
# --maxIter=1000 # Maximum number of iterations
|
||||
# --tabuListType=TwoOpt # Type of the tabu list: 'TwoOpt', 'SimpleMove' or 'SimpleSolution'
|
||||
|
|
@ -34,19 +34,30 @@
|
|||
|
||||
*/
|
||||
|
||||
#include <eo>
|
||||
#include <mo>
|
||||
#include <tsp>
|
||||
|
||||
void manage_configuration_file(eoParser & _parser);
|
||||
|
||||
int
|
||||
main (int _argc, char* _argv [])
|
||||
{
|
||||
if (_argc != 2)
|
||||
{
|
||||
std :: cerr << "Usage : ./tabu_search [instance]" << std :: endl ;
|
||||
return 1 ;
|
||||
}
|
||||
std::string instancePath, value;
|
||||
unsigned int seed, maxIterations, tabuListSize;
|
||||
|
||||
Graph::load (_argv [1]);
|
||||
eoParser parser(_argc, _argv);
|
||||
|
||||
manage_configuration_file(parser);
|
||||
|
||||
seed=atoi( (parser.getParamWithLongName("seed")->getValue()).c_str() );
|
||||
maxIterations=atoi( (parser.getParamWithLongName("maxIter")->getValue()).c_str() );
|
||||
tabuListSize=atoi( (parser.getParamWithLongName("tabuListSize")->getValue()).c_str() );
|
||||
instancePath=parser.getParamWithLongName("instancePath")->getValue();
|
||||
value=parser.getParamWithLongName("tabuListType")->getValue();
|
||||
|
||||
srand (seed);
|
||||
Graph::load(instancePath.c_str());
|
||||
|
||||
Route solution;
|
||||
|
||||
|
|
@ -67,20 +78,67 @@ main (int _argc, char* _argv [])
|
|||
|
||||
TwoOptIncrEval two_opt_incremental_evaluation;
|
||||
|
||||
TwoOptTabuList tabu_list;
|
||||
//moSimpleMoveTabuList<TwoOpt> tabu_list(10);
|
||||
//moSimpleSolutionTabuList<TwoOpt> tabu_list(10);
|
||||
moTabuList<TwoOpt> *tabuList;
|
||||
|
||||
if(value.compare("TwoOpt")==0)
|
||||
{
|
||||
tabuList=new TwoOptTabuList();
|
||||
}
|
||||
else if (value.compare("SimpleMove")==0)
|
||||
{
|
||||
tabuList=new moSimpleMoveTabuList<TwoOpt>(tabuListSize);
|
||||
}
|
||||
else if (value.compare("SimpleSolution")==0)
|
||||
{
|
||||
tabuList=new moSimpleSolutionTabuList<TwoOpt>(tabuListSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("[tabu_search.cpp]: the type of tabu list '"+value+"' is not correct.");
|
||||
}
|
||||
|
||||
moNoAspirCrit <TwoOpt> aspiration_criterion;
|
||||
|
||||
moGenSolContinue <Route> continu (10000);
|
||||
moGenSolContinue <Route> continu (maxIterations);
|
||||
|
||||
moTS <TwoOpt> tabu_search (two_opt_initializer, two_opt_next_move_generator,
|
||||
two_opt_incremental_evaluation, tabu_list, aspiration_criterion, continu, full_evaluation);
|
||||
two_opt_incremental_evaluation, *tabuList, aspiration_criterion, continu, full_evaluation);
|
||||
tabu_search(solution);
|
||||
|
||||
std :: cout << "[To] " << solution << std :: endl;
|
||||
|
||||
delete(tabuList);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void
|
||||
manage_configuration_file(eoParser & _parser)
|
||||
{
|
||||
std::ofstream os;
|
||||
|
||||
_parser.getORcreateParam(std::string("../examples/tsp/benchs/berlin52.tsp"), "instancePath", "Path to the instance.",
|
||||
0, "Configuration", false);
|
||||
_parser.getORcreateParam((unsigned int)time(0), "seed", "Seed for rand.", 0, "Configuration", false);
|
||||
|
||||
_parser.getORcreateParam((unsigned int)10, "tabuListSize", "Size of the tabu list.", 0, "Configuration", false);
|
||||
|
||||
_parser.getORcreateParam((unsigned int)1000, "maxIter", "Maximum number of iterations.", 0, "Configuration", false);
|
||||
|
||||
_parser.getORcreateParam(std::string("TwoOpt"), "tabuListType", "Type of the tabu list: 'TwoOpt', 'SimpleMove' or 'SimpleSolution'.",
|
||||
0, "Configuration", false);
|
||||
|
||||
if (_parser.userNeedsHelp())
|
||||
{
|
||||
_parser.printHelp(std::cout);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
os.open("current_param");
|
||||
if(!os.is_open())
|
||||
{
|
||||
throw std::runtime_error("[tabu_search.cpp]: the file current_param cannot be created.");
|
||||
}
|
||||
os <<_parser;
|
||||
os.close();
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
14
trunk/paradiseo-mo/tutorial/Lesson3/param
Normal file
14
trunk/paradiseo-mo/tutorial/Lesson3/param
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
###### General ######
|
||||
# --help=0 # -h : Prints this message
|
||||
# --stopOnUnknownParam=1 # Stop if unkown param entered
|
||||
|
||||
###### Configuration ######
|
||||
# --instancePath=../examples/tsp/benchs/berlin52.tsp # Path to the instance.
|
||||
# --seed=1202919978 # Seed for rand.
|
||||
# --maxIter=1000 # Maximum number of iterations.
|
||||
# --initialTemp=1000 # Initial temperature.
|
||||
# --threshold=0.1 # Minimum temperature allowed.
|
||||
# --expoRatio=0.98 # Ratio used if exponential cooling schedule is chosen.
|
||||
# --lineaRatio=0.5 # Ratio used if linear cooling schedule is chosen.
|
||||
# --coolSchedType=Expo # Type the cooling schedule: 'Expo' or 'Linear'.
|
||||
|
|
@ -33,19 +33,34 @@
|
|||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
#include <eo>
|
||||
#include <mo>
|
||||
#include <tsp>
|
||||
|
||||
void manage_configuration_file(eoParser & _parser);
|
||||
|
||||
int
|
||||
main (int _argc, char* _argv [])
|
||||
{
|
||||
if (_argc != 2)
|
||||
{
|
||||
std :: cerr << "Usage : ./simulated_annealing [instance]" << std :: endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
std::string instancePath, value;
|
||||
unsigned int seed, maxIterations;
|
||||
double threshold, exponentialRatio, linearRatio, initialTemperature;
|
||||
|
||||
Graph::load (_argv [1]);
|
||||
eoParser parser(_argc, _argv);
|
||||
|
||||
manage_configuration_file(parser);
|
||||
|
||||
seed=atoi( (parser.getParamWithLongName("seed")->getValue()).c_str() );
|
||||
instancePath=parser.getParamWithLongName("instancePath")->getValue();
|
||||
maxIterations=atoi( (parser.getParamWithLongName("maxIter")->getValue()).c_str() );
|
||||
initialTemperature=atof( (parser.getParamWithLongName("initialTemp")->getValue()).c_str() );
|
||||
threshold=atof( (parser.getParamWithLongName("threshold")->getValue()).c_str() );
|
||||
exponentialRatio=atof( (parser.getParamWithLongName("expoRatio")->getValue()).c_str() );
|
||||
linearRatio=atof( (parser.getParamWithLongName("lineaRatio")->getValue()).c_str() );
|
||||
value=parser.getParamWithLongName("coolSchedType")->getValue();
|
||||
|
||||
srand (seed);
|
||||
Graph::load(instancePath.c_str());
|
||||
|
||||
Route solution;
|
||||
|
||||
|
|
@ -66,19 +81,67 @@ main (int _argc, char* _argv [])
|
|||
|
||||
TwoOpt move;
|
||||
|
||||
moExponentialCoolingSchedule cooling_schedule (0.1, 0.98);
|
||||
//moLinearCoolingSchedule cooling_schedule (0.1, 0.5);
|
||||
moCoolingSchedule* coolingSchedule;
|
||||
|
||||
moGenSolContinue <Route> continu (1000); /* Temperature Descreasing
|
||||
will occur each 1000
|
||||
iterations */
|
||||
if(value.compare("Expo")==0)
|
||||
{
|
||||
coolingSchedule=new moExponentialCoolingSchedule(threshold, exponentialRatio);
|
||||
}
|
||||
else if (value.compare("Linear")==0)
|
||||
{
|
||||
coolingSchedule=new moLinearCoolingSchedule(threshold, linearRatio);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("[simulated_annealing.cpp]: the type of cooling schedule '"+value+"' is not correct.");
|
||||
}
|
||||
|
||||
moGenSolContinue <Route> continu (maxIterations);
|
||||
|
||||
moSA <TwoOpt> simulated_annealing (two_opt_random_move_generator, two_opt_incremental_evaluation,
|
||||
continu, 1000, cooling_schedule, full_evaluation);
|
||||
continu, initialTemperature, *coolingSchedule, full_evaluation);
|
||||
simulated_annealing (solution);
|
||||
|
||||
std :: cout << "[To] " << solution << std :: endl;
|
||||
|
||||
delete(coolingSchedule);
|
||||
|
||||
return EXIT_SUCCESS ;
|
||||
}
|
||||
|
||||
void
|
||||
manage_configuration_file(eoParser & _parser)
|
||||
{
|
||||
std::ofstream os;
|
||||
|
||||
_parser.getORcreateParam(std::string("../examples/tsp/benchs/berlin52.tsp"), "instancePath", "Path to the instance.",
|
||||
0, "Configuration", false);
|
||||
_parser.getORcreateParam((unsigned int)time(0), "seed", "Seed for rand.", 0, "Configuration", false);
|
||||
|
||||
_parser.getORcreateParam((unsigned int)1000, "maxIter", "Maximum number of iterations.", 0, "Configuration", false);
|
||||
|
||||
_parser.getORcreateParam((double)1000, "initialTemp", "Initial temperature.", 0, "Configuration", false);
|
||||
|
||||
_parser.getORcreateParam((double)0.1, "threshold", "Minimum temperature allowed.", 0, "Configuration", false);
|
||||
|
||||
_parser.getORcreateParam((double)0.98, "expoRatio", "Ratio used if exponential cooling schedule is chosen.", 0, "Configuration", false);
|
||||
|
||||
_parser.getORcreateParam((double)0.5, "lineaRatio", "Ratio used if linear cooling schedule is chosen.", 0, "Configuration", false);
|
||||
|
||||
_parser.getORcreateParam(std::string("Expo"), "coolSchedType", "Type the cooling schedule: 'Expo' or 'Linear'.",
|
||||
0, "Configuration", false);
|
||||
|
||||
if (_parser.userNeedsHelp())
|
||||
{
|
||||
_parser.printHelp(std::cout);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
os.open("current_param");
|
||||
if(!os.is_open())
|
||||
{
|
||||
throw std::runtime_error("[simulated_annealing.cpp]: the file current_param cannot be created.");
|
||||
}
|
||||
os <<_parser;
|
||||
os.close();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,19 +33,28 @@
|
|||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
#include <eo>
|
||||
#include <mo>
|
||||
#include <tsp>
|
||||
|
||||
void manage_configuration_file(eoParser & _parser);
|
||||
|
||||
int
|
||||
main (int _argc, char* _argv [])
|
||||
{
|
||||
if (_argc != 2)
|
||||
{
|
||||
std :: cerr << "Usage : ./iterated_local_search [instance]" << std :: endl ;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
std::string instancePath;
|
||||
unsigned int seed, maxIterations;
|
||||
|
||||
Graph::load (_argv [1]);
|
||||
eoParser parser(_argc, _argv);
|
||||
|
||||
manage_configuration_file(parser);
|
||||
|
||||
seed=atoi( (parser.getParamWithLongName("seed")->getValue()).c_str() );
|
||||
instancePath=parser.getParamWithLongName("instancePath")->getValue();
|
||||
maxIterations=atoi( (parser.getParamWithLongName("maxIter")->getValue()).c_str() );
|
||||
|
||||
srand(seed);
|
||||
Graph::load (instancePath.c_str());
|
||||
|
||||
Route solution;
|
||||
|
||||
|
|
@ -65,7 +74,7 @@ main (int _argc, char* _argv [])
|
|||
|
||||
moBestImprSelect <TwoOpt> two_opt_selection;
|
||||
|
||||
moGenSolContinue <Route> continu(1000);
|
||||
moGenSolContinue <Route> continu(maxIterations);
|
||||
|
||||
moFitComparator<Route> comparator;
|
||||
|
||||
|
|
@ -80,3 +89,28 @@ main (int _argc, char* _argv [])
|
|||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void
|
||||
manage_configuration_file(eoParser & _parser)
|
||||
{
|
||||
std::ofstream os;
|
||||
|
||||
_parser.getORcreateParam(std::string("../examples/tsp/benchs/berlin52.tsp"), "instancePath", "Path to the instance.",
|
||||
0, "Configuration", false);
|
||||
_parser.getORcreateParam((unsigned int)time(0), "seed", "Seed for rand.", 0, "Configuration", false);
|
||||
|
||||
_parser.getORcreateParam((unsigned int)1000, "maxIter", "Maximum number of iterations.", 0, "Configuration", false);
|
||||
|
||||
if (_parser.userNeedsHelp())
|
||||
{
|
||||
_parser.printHelp(std::cout);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
os.open("current_param");
|
||||
if(!os.is_open())
|
||||
{
|
||||
throw std::runtime_error("[iterated_local_search.cpp]: the file current_param cannot be created.");
|
||||
}
|
||||
os <<_parser;
|
||||
os.close();
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
9
trunk/paradiseo-mo/tutorial/Lesson4/param
Normal file
9
trunk/paradiseo-mo/tutorial/Lesson4/param
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
###### General ######
|
||||
# --help=0 # -h : Prints this message
|
||||
# --stopOnUnknownParam=1 # Stop if unkown param entered
|
||||
|
||||
###### Configuration ######
|
||||
# --instancePath=../examples/tsp/benchs/berlin52.tsp # Path to the instance.
|
||||
# --seed=1203080388 # Seed for rand.
|
||||
# --maxIter=1000 # Maximum number of iterations.
|
||||
|
|
@ -40,6 +40,9 @@
|
|||
|
||||
#include "graph.h"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
namespace Graph
|
||||
{
|
||||
|
||||
|
|
@ -70,103 +73,103 @@ namespace Graph
|
|||
{
|
||||
double distX = (double)(vectCoord [i].first - vectCoord [j].first) ;
|
||||
double distY = (double)(vectCoord [i].second - vectCoord [j].second) ;
|
||||
dist [i] [j] = dist [j] [i] = (unsigned) (sqrt ((float) (distX * distX + distY * distY)) + 0.5) ;
|
||||
dist [i] [j] = dist [j] [i] = (unsigned int) (sqrt ((float) (distX * distX + distY * distY)) + 0.5) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void load (const char * __fileName)
|
||||
void load (const char * _fileName)
|
||||
{
|
||||
unsigned int i, dimension;
|
||||
|
||||
std::string string_read, buffer;
|
||||
|
||||
std :: ifstream file (__fileName) ;
|
||||
std :: ifstream file (_fileName) ;
|
||||
|
||||
std :: cout << ">> Loading [" << __fileName << "]" << std :: endl ;
|
||||
cout << endl << "\tLoading [" << _fileName << "]" << endl << endl;
|
||||
|
||||
if (file)
|
||||
if( file.is_open() )
|
||||
{
|
||||
// Read NAME:
|
||||
file >> string_read;
|
||||
if (string_read.compare("NAME:")!=0)
|
||||
{
|
||||
std::cout << "ERROR: \'NAME:\' espected, \'" << string_read << "\' found" << std::endl;
|
||||
exit(1);
|
||||
cout << "ERROR: \'NAME:\' espected, \'" << string_read << "\' found" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// Read instance name
|
||||
file >> string_read;
|
||||
std::cout << "\t Instance Name = " << string_read << std::endl;
|
||||
cout << "\t\tInstance Name = " << string_read << endl;
|
||||
// Read TYPE:
|
||||
file >> string_read;
|
||||
if (string_read.compare("TYPE:")!=0)
|
||||
{
|
||||
std::cout << "ERROR: \'TYPE:\' espected, \'" << string_read << "\' found" << std::endl;
|
||||
exit(1);
|
||||
cout << "ERROR: \'TYPE:\' espected, \'" << string_read << "\' found" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// Read instance type;
|
||||
file >> string_read;
|
||||
std::cout << "\t Instance type = " << string_read << std::endl;
|
||||
cout << "\t\tInstance type = " << string_read << endl;
|
||||
if (string_read.compare("TSP")!=0)
|
||||
{
|
||||
std::cout << "ERROR: only TSP type instance can be loaded" << std::endl;
|
||||
exit(1);
|
||||
cout << "ERROR: only TSP type instance can be loaded" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// Read COMMENT:
|
||||
file >> string_read;
|
||||
if (string_read.compare("COMMENT:")!=0)
|
||||
{
|
||||
std::cout << "ERROR: \'COMMENT:\' espected, \'" << string_read << "\' found" << std::endl;
|
||||
exit(1);
|
||||
cout << "ERROR: \'COMMENT:\' espected, \'" << string_read << "\' found" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// Read comments
|
||||
std::cout << "\t Instance comments = ";
|
||||
cout << "\t\tInstance comments = ";
|
||||
file >> string_read;
|
||||
buffer = string_read+"_first";
|
||||
while((string_read.compare("DIMENSION:")!=0) && (string_read.compare(buffer)!=0))
|
||||
{
|
||||
if(string_read.compare("COMMENT:")!=0)
|
||||
{
|
||||
std::cout << string_read << " ";
|
||||
cout << string_read << " ";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << std::endl << "\t ";
|
||||
cout << endl << "\t ";
|
||||
}
|
||||
buffer = string_read;
|
||||
file >> string_read;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
cout << endl;
|
||||
|
||||
// Read dimension;
|
||||
file >> dimension ;
|
||||
std::cout << "\t Instance dimension = " << dimension << std::endl;
|
||||
cout << "\t\tInstance dimension = " << dimension << endl;
|
||||
vectCoord.resize (dimension) ;
|
||||
|
||||
// Read EDGE_WEIGHT_TYPE
|
||||
file >> string_read;
|
||||
if (string_read.compare("EDGE_WEIGHT_TYPE:")!=0)
|
||||
{
|
||||
std::cout << "ERROR: \'EDGE_WEIGHT_TYPE:\' espected, \'" << string_read << "\' found" << std::endl;
|
||||
exit(1);
|
||||
cout << "ERROR: \'EDGE_WEIGHT_TYPE:\' espected, \'" << string_read << "\' found" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Read edge weight type
|
||||
file >> string_read;
|
||||
std::cout << "\t Instance edge weight type = " << string_read << std::endl;
|
||||
cout << "\t\tInstance edge weight type = " << string_read << endl;
|
||||
if (string_read.compare("EUC_2D")!=0)
|
||||
{
|
||||
std::cout << "ERROR: only EUC_2D edge weight type instance can be loaded" << std::endl;
|
||||
exit(1);
|
||||
cout << "ERROR: only EUC_2D edge weight type instance can be loaded" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Read NODE_COORD_SECTION
|
||||
file >> string_read;
|
||||
if (string_read.compare("NODE_COORD_SECTION")!=0)
|
||||
{
|
||||
std::cout << "ERROR: \'NODE_COORD_SECTION\' espected, \'" << string_read << "\' found" << std::endl;
|
||||
exit(1);
|
||||
cout << "ERROR: \'NODE_COORD_SECTION\' espected, \'" << string_read << "\' found" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Read coordonates.
|
||||
|
|
@ -182,11 +185,11 @@ namespace Graph
|
|||
file >> string_read;
|
||||
if(string_read.compare("EOF")!=0)
|
||||
{
|
||||
std::cout << "ERROR: \'EOF\' espected, \'" << string_read << "\' found" << std::endl;
|
||||
exit(1);
|
||||
cout << "ERROR: \'EOF\' espected, \'" << string_read << "\' found" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
cout << endl;
|
||||
|
||||
file.close () ;
|
||||
|
||||
|
|
@ -194,16 +197,14 @@ namespace Graph
|
|||
}
|
||||
else
|
||||
{
|
||||
|
||||
std :: cout << __fileName << " does not exist !!!" << std :: endl ;
|
||||
// Bye !!!
|
||||
exit (1) ;
|
||||
cout << _fileName << " does not exist !!!" << endl ;
|
||||
exit(EXIT_FAILURE) ;
|
||||
}
|
||||
}
|
||||
|
||||
float distance (unsigned int __from, unsigned int __to)
|
||||
float distance (unsigned int _from, unsigned int _to)
|
||||
{
|
||||
return (float)(dist [__from] [__to]) ;
|
||||
return (float)(dist [_from] [_to]) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,14 +41,14 @@
|
|||
#include <utility>
|
||||
|
||||
namespace Graph
|
||||
{
|
||||
void load (const char * __file_name) ;
|
||||
{
|
||||
void load (const char * _file_name) ;
|
||||
/* Loading cities
|
||||
(expressed by their coordinates)
|
||||
from the given file name */
|
||||
|
||||
float distance (unsigned int __from, unsigned int __to) ;
|
||||
|
||||
|
||||
float distance (unsigned int _from, unsigned int _to) ;
|
||||
|
||||
unsigned int size () ; // How many cities ?
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue