static char* _project_info = "tspgen : Genetic Algorithms for the Traveling Salesman Problem";
static char* _project_version = "tspgen - v0.32 - 07/04/2002";
static char* _project_author = "Alexandre Aupetit <aaupetit@club-internet.fr>\nMichaël Trabbia <michael.trabbia@enst.fr>\n -- http://home.alex.tuxfamily.org/pvc.html";
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <math.h>
#include "tspgen.h"
int main (int argc, char *argv[])
{
int i;
char sInfo[255];
char sIniFilename[255];
char sTestLogName[255];
int iNbTests;
int iTestCount;
srand (time (NULL));
if (GetLineParams(argc, argv, sIniFilename, &iNbTests))
{
Config *pConfig;
pConfig = new Config (sIniFilename);
for (iTestCount=0; iTestCount<iNbTests; iTestCount++)
{
if (iNbTests>1)
{
sprintf(sTestLogName, "%s-%03d", pConfig->GetParamByName ("LogBasename")->GetStringValue (), iTestCount);
}
else
{
strcpy(sTestLogName, pConfig->GetParamByName ("LogBasename")->GetStringValue ());
}
TspLog *pTspLog;
pTspLog = new TspLog (pConfig->GetParamByName ("LogLevel")->GetIntValue (),
pConfig->GetParamByName ("ScreenLogLevel")->GetIntValue (),
pConfig->GetParamByName ("LogDir")->GetStringValue (),
sTestLogName);
pTspLog->StartFunction ("tspgen", 0, LEVEL_DEBUG, 0);
pTspLog->ProjectInfoMsg(_project_info, _project_version, _project_author);
for (i=1; i<pConfig->iNbParam; i++)
{
sprintf(sInfo, "%s=%s", pConfig->GetParam(i)->GetName(), pConfig->GetParam(i)->GetStringValue());
pTspLog->InfoMsg(sInfo);
}
TSP *pTSP;
pTSP = new TSP (0,
pConfig->GetParamByName ("Problem")->GetStringValue (),
pConfig->GetParamByName ("NbNeighbour")->GetIntValue (),
pTspLog);
Population *pP;
pP = new Population (0,
pConfig->GetParamByName ("NbGroup")->GetIntValue (),
pConfig->GetParamByName ("NbIndividual")->GetIntValue (),
pTSP,
pTspLog,
pConfig->GetParamByName ("LogDir")->GetStringValue (),
pConfig->GetParamByName ("LogBasename")->GetStringValue ());
pP->Init (pConfig->GetParamByName ("Init")->GetStringValue ());
pP->Evolve (pConfig->GetParamByName ("Evol")->GetStringValue (),
pConfig->GetParamByName ("NbEvol")->GetIntValue (),
pConfig->GetParamByName ("GroupRepartition")->GetBoolValue ());
delete pP;
delete pTSP;
pTspLog->EndFunction ("tspgen", 0);
delete pTspLog;
}
delete pConfig;
}
return 0;
}
bool GetLineParams (int argc, char *argv[], char *sIniFilename, int *iNbTests)
{
bool bOk;
int iPosIni, iPosTest;
strcpy(sIniFilename, "tspgen.ini");
bOk = false;
*iNbTests = 1;
iPosIni = -1;
iPosTest = -1;
if (argc == 1)
{
bOk = true;
}
if ( (argc == 3) && (strcmp(argv[1], "-i")==0) )
{
bOk = true;
iPosIni = 2;
}
if ( (argc == 3) && (strcmp(argv[1], "-t")==0) )
{
bOk = true;
iPosTest = 2;
}
if ( (argc == 5) && (strcmp(argv[1], "-i")==0) && (strcmp(argv[3], "-t")==0))
{
bOk = true;
iPosIni = 2;
iPosTest = 4;
}
if ( (argc == 5) && (strcmp(argv[1], "-t")==0) && (strcmp(argv[3], "-i")==0))
{
bOk = true;
iPosIni = 4;
iPosTest = 2;
}
if (bOk)
{
if (iPosIni>0)
{
strcpy(sIniFilename, argv[iPosIni]);
}
if (iPosTest>0)
{
*iNbTests = atoi(argv[iPosTest]);
}
}
if (!bOk)
{
Usage();
}
return bOk;
}
void Usage(void)
{
printf("Usage :\n");
printf(" tspgen [-i <inifilename>] [-t <nbtests>]\n");
}