[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[oMetah-devel] ometah/interface itsArgument.cpp itsArgument.hp...
From: |
Jean-Philippe Aumasson |
Subject: |
[oMetah-devel] ometah/interface itsArgument.cpp itsArgument.hp... |
Date: |
Thu, 02 Jun 2005 15:19:12 -0400 |
CVSROOT: /cvsroot/ometah
Module name: ometah
Branch:
Changes by: Jean-Philippe Aumasson <address@hidden> 05/06/02 19:19:12
Modified files:
interface : itsArgument.cpp itsArgument.hpp ometah.cpp
ometah.hpp
Log message:
* defArgs and get*Values working, some new options defined, and used in
program config..
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/interface/itsArgument.cpp.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/interface/itsArgument.hpp.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/interface/ometah.cpp.diff?tr1=1.24&tr2=1.25&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/interface/ometah.hpp.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
Patches:
Index: ometah/interface/itsArgument.cpp
diff -u ometah/interface/itsArgument.cpp:1.6
ometah/interface/itsArgument.cpp:1.7
--- ometah/interface/itsArgument.cpp:1.6 Thu Jun 2 15:42:06 2005
+++ ometah/interface/itsArgument.cpp Thu Jun 2 19:19:12 2005
@@ -1,5 +1,5 @@
/***************************************************************************
- * $Id: itsArgument.cpp,v 1.6 2005/06/02 15:42:06 jpa Exp $
+ * $Id: itsArgument.cpp,v 1.7 2005/06/02 19:19:12 jpa Exp $
* Copyright : Université Paris 12 Val-de-Marne
* Author : Johann Dréo <address@hidden>
* Author : Jean-Philippe Aumasson <address@hidden>
@@ -38,8 +38,8 @@
}
// constructor...
-itsArgument::itsArgument(string flagShort, string flagLong, string usage,
- bool hasValue, string type, string value)
+itsArgument::itsArgument(string flagShort, string flagLong, string usage,
+ bool hasValue, string type, string value)
{
this->flagShort = flagShort;
@@ -83,30 +83,25 @@
{
this->argv = argv;
this->argc = argc;
+}
+void itsParser::searchEndFlags() {
// termination flags : if there, don't execute program
// following order <=> flags' priorities
- if (this->defArg("-v","--version","check version", false, "", ""))
- cout << "current version is ..."; // EXCEPTION ! (show version and quit)
-
- if (this->defArg("-h","--help","show help", false, "", ""))
- cout << "help infos..."; // EXCEPTIOn (show help instructions and quit)
+ if (this->defArg("-v","--version","check version", false, "", "")){
+ throw VERSION;
+ }
+ if (this->defArg("-h","--help","show help", false, "", "")){
+ throw USAGE;
+ }
}
+
// parse argv searching the given flag, then update the vector with a new
argument
bool itsParser::defArg(string flagShort, string flagLong, string usage,
bool hasValue, string type, string valueDefault)
{
-
-
-#ifdef DEBUG
- cout << "Enter defArg: ";
- cout << "\n flagshort: " << flagShort << "\n flagLong: " << flagLong
- << "\n usage : " << usage << "\n hasValue: " << hasValue
- << "\n type: " << type << "\n valueDef: " << valueDefault << "\n";
-#endif
-
unsigned i = 1;
bool found = false;
string value = valueDefault;
@@ -130,15 +125,16 @@
i++;
}
+
+ itsArgument newArgument(flagShort, flagLong, usage, hasValue, type, value);
+ arguments.push_back(newArgument);
+
#ifdef DEBUG
- cout << "Argument final:";
+ cout << "Argument defined:";
cout << "\n flagshort: " << flagShort << "\n flagLong: " << flagLong
<< "\n usage : " << usage << "\n hasValue: " << hasValue
- << "\n type: " << type << "\n value: " << value;
+ << "\n type: " << type << "\n value: " << value << endl;
#endif
-
- itsArgument newArgument(flagShort, flagLong, usage, hasValue, type, value);
- arguments.push_back(newArgument);
return found;
}
Index: ometah/interface/itsArgument.hpp
diff -u ometah/interface/itsArgument.hpp:1.5
ometah/interface/itsArgument.hpp:1.6
--- ometah/interface/itsArgument.hpp:1.5 Thu Jun 2 12:42:47 2005
+++ ometah/interface/itsArgument.hpp Thu Jun 2 19:19:12 2005
@@ -1,5 +1,5 @@
/***************************************************************************
- * $Id: itsArgument.hpp,v 1.5 2005/06/02 12:42:47 jpa Exp $
+ * $Id: itsArgument.hpp,v 1.6 2005/06/02 19:19:12 jpa Exp $
* Copyright : Université Paris 12 Val-de-Marne
* Author : Johann Dréo <address@hidden>
* Author : Jean-Philippe Aumasson <address@hidden>
@@ -30,7 +30,10 @@
#include "../common/logic.hpp"
-// #define DEBUG 1
+#define DEBUG 1
+
+#define VERSION "OpenMetaheuristics version pre-alpha -10"
+#define USAGE "Usage"
using namespace std;
@@ -104,4 +107,6 @@
bool getBoolValue(string flag);
+ void searchEndFlags();
+
};
Index: ometah/interface/ometah.cpp
diff -u ometah/interface/ometah.cpp:1.24 ometah/interface/ometah.cpp:1.25
--- ometah/interface/ometah.cpp:1.24 Thu Jun 2 15:42:06 2005
+++ ometah/interface/ometah.cpp Thu Jun 2 19:19:12 2005
@@ -1,5 +1,5 @@
/***************************************************************************
- * $Id: ometah.cpp,v 1.24 2005/06/02 15:42:06 jpa Exp $
+ * $Id: ometah.cpp,v 1.25 2005/06/02 19:19:12 jpa Exp $
* Copyright : Université Paris 12 Val-de-Marne
* Author : Johann Dréo <address@hidden>
* Author : Jean-Philippe Aumasson <address@hidden>
@@ -29,20 +29,60 @@
using namespace std;
+void usage(){
+
+ cout << "Usage:" << endl;
+}
+
int main(int argc, char ** argv)
{
-
+
+ // fill the argv vector
vector<string> argumentsVector;
for(int i=0; i<argc; i++){
argumentsVector.push_back(argv[i]);
}
-
+
+ // create a parser
itsParser theParser(argc, argumentsVector);
- theParser.defArg("-p","--problem","problem name", true, "string",
"Rosenbrock");
-
- cout << "\ngetValue : " << theParser.getStringValue("-p") << endl;
+ // arguments definitions
+ theParser.defArg("-p", "--problem",
+ "the name of the problem", true, "string", "Rosenbrock");
+ theParser.defArg("-m", "--metah",
+ "metaheuristic name", true, "string", "CEDA");
+ theParser.defArg("-cC", "--com-client",
+ "communication client mode" ,true, "string", "Embedded");
+ theParser.defArg("-cS", "--com-client",
+ "communication server mode" ,true, "string", "Embedded");
+ theParser.defArg("-d", "--debug",
+ "debug key" ,true, "string", "");
+
+
+
+
+ // look for end flags (-v, -h, etc...)
+ try{
+ theParser.searchEndFlags();
+ }
+ catch (const char * s){
+ if (!strcmp(s, VERSION)){
+ cerr << s << endl;
+ return -1;
+ }
+ else if (!strcmp(s, USAGE)){
+ usage();
+ return -1;
+ }
+ }
+
+
+
+#ifdef DEBUG
+ cout << "\ngetValues :" << "\n problem: " << theParser.getStringValue("-p")
+ << "\nmetah: "<< theParser.getStringValue("-m") << endl;
+#endif
// differents sets of objects
itsSet<itsMetaheuristic*> setMetaheuristic;
@@ -63,7 +103,6 @@
setMetaheuristic.add( factoryMetaheuristics->create() );
-
/*
* Problems part
*/
@@ -91,23 +130,14 @@
factoryServer = new itsCommunicationServerFactory_embedded;
setCommunicationServer.add( factoryServer->create() );
- /*
- itsParser argumentsParser(argumentsVector);
-
- argumentsParser.defArg("i","iterations","Maximum number of
iterations",true,"int","2");
-
- int i = argumentsParser.getIntValue("i");
- cout << "test i :" << i << endl;
- */
-
/*
* Choose the items
*/
- setMetaheuristic.choose("CEDA");
- setProblem.choose("Rosenbrock");
- setCommunicationClient.choose("Embedded");
- setCommunicationServer.choose("Embedded");
+ setMetaheuristic.choose(theParser.getStringValue("-m"));
+ setProblem.choose(theParser.getStringValue("-p"));
+ setCommunicationClient.choose(theParser.getStringValue("-cC"));
+ setCommunicationServer.choose(theParser.getStringValue("-cS"));
/*
@@ -127,8 +157,8 @@
*/
// Special case for the embedded protocol : we must link client and server
- if( setCommunicationClient.item()->getKey() == "Embedded" &&
- setCommunicationServer.item()->getKey() == "Embedded" ) {
+ if( setCommunicationClient.item()->getKey() ==
theParser.getStringValue("-cC") &&
+ setCommunicationServer.item()->getKey() ==
theParser.getStringValue("-cS")) {
setCommunicationClient.item()->problem = setCommunicationServer.item();
}
@@ -151,22 +181,22 @@
//setMetaheuristic.item()->setLogLevel(0);
// parameters
- //setProblem.item()->setDimension(2);
- //setMetaheuristic.item()->setSampleSize(100);
- //setMetaheuristic.item()->setIterationsMaxNumber(100);
+ setProblem.item()->setDimension(2);
+ setMetaheuristic.item()->setSampleSize(100);
+ setMetaheuristic.item()->setIterationsMaxNumber(100);
// Starting the optimization
- /*
+
clog << "Launching " << setMetaheuristic.item()->getName()
<< " on " << setProblem.item()->getName()
<< " using " << setCommunicationClient.item()->getKey() << endl;
- */
+
//clog << setProblem.item()->getName() << " description:" << endl;
//clog << setProblem.item()->getInformations() << endl;
- /*
+
try {
setMetaheuristic.item()->start();
}
@@ -179,7 +209,7 @@
catch (...) {
cerr << "Unknown error" << endl;
}
- */
+
}
Index: ometah/interface/ometah.hpp
diff -u ometah/interface/ometah.hpp:1.4 ometah/interface/ometah.hpp:1.5
--- ometah/interface/ometah.hpp:1.4 Thu Jun 2 12:42:47 2005
+++ ometah/interface/ometah.hpp Thu Jun 2 19:19:12 2005
@@ -1,5 +1,5 @@
/***************************************************************************
- * $Id: ometah.hpp,v 1.4 2005/06/02 12:42:47 jpa Exp $
+ * $Id: ometah.hpp,v 1.5 2005/06/02 19:19:12 jpa Exp $
* Copyright : Université Paris 12 Val-de-Marne
* Author : Johann Dréo <address@hidden>
* Author : Jean-Philippe Aumasson <address@hidden>
@@ -51,3 +51,5 @@
using namespace std;
+
+void usage();
- [oMetah-devel] ometah/interface itsArgument.cpp itsArgument.hp..., Jean-Philippe Aumasson, 2005/06/02
- [oMetah-devel] ometah/interface itsArgument.cpp itsArgument.hp..., Jean-Philippe Aumasson, 2005/06/02
- [oMetah-devel] ometah/interface itsArgument.cpp itsArgument.hp...,
Jean-Philippe Aumasson <=
- [oMetah-devel] ometah/interface itsArgument.cpp itsArgument.hp..., Jean-Philippe Aumasson, 2005/06/03
- [oMetah-devel] ometah/interface itsArgument.cpp itsArgument.hp..., Jean-Philippe Aumasson, 2005/06/03
- [oMetah-devel] ometah/interface itsArgument.cpp itsArgument.hp..., Jean-Philippe Aumasson, 2005/06/03
- [oMetah-devel] ometah/interface itsArgument.cpp itsArgument.hp..., Jean-Philippe Aumasson, 2005/06/03