[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: |
Fri, 03 Jun 2005 03:57:24 -0400 |
CVSROOT: /cvsroot/ometah
Module name: ometah
Branch:
Changes by: Jean-Philippe Aumasson <address@hidden> 05/06/03 07:57:24
Modified files:
interface : itsArgument.cpp itsArgument.hpp ometah.cpp
ometah.hpp
Log message:
* modifs of flags name, and usage strings
* exceptions in getValue functions
* exception if no value for a parameter
* usage() function, printing from vector<itsArgument>
* debug messages added
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/interface/itsArgument.cpp.diff?tr1=1.8&tr2=1.9&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/interface/itsArgument.hpp.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/interface/ometah.cpp.diff?tr1=1.26&tr2=1.27&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/interface/ometah.hpp.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
Patches:
Index: ometah/interface/itsArgument.cpp
diff -u ometah/interface/itsArgument.cpp:1.8
ometah/interface/itsArgument.cpp:1.9
--- ometah/interface/itsArgument.cpp:1.8 Thu Jun 2 21:59:39 2005
+++ ometah/interface/itsArgument.cpp Fri Jun 3 07:57:23 2005
@@ -1,5 +1,5 @@
/***************************************************************************
- * $Id: itsArgument.cpp,v 1.8 2005/06/02 21:59:39 nojhan Exp $
+ * $Id: itsArgument.cpp,v 1.9 2005/06/03 07:57:23 jpa Exp $
* Copyright : Université Paris 12 Val-de-Marne
* Author : Johann Dréo <address@hidden>
* Author : Jean-Philippe Aumasson <address@hidden>
@@ -70,6 +70,12 @@
return "";
}
+string itsArgument::getUsage()
+{
+
+ return this->usage;
+}
+
// ITSPARSER
// destructor
@@ -89,7 +95,7 @@
// termination flags : if there, don't execute program
// following order <=> flags' priorities
- if (this->defArg("-v","--version","check version", false, "", "")){
+ if (this->defArg("-V","--version","check version", false, "", "")){
throw VERSION;
}
if (this->defArg("-h","--help","show help", false, "", "")){
@@ -115,8 +121,12 @@
if ((++i) < this->argv.size())
value = this->argv.at(i);
- else; // EXCEPTION ! ( valeur attendue absente )
- }
+ else { // ONLY CASE OF LAST PARAM !!
+ stringstream s;
+ s << "parameter value missing for " << flagShort << endl;
+ throw (s.str()).c_str();
+ }
+ }
else { // no value associated => arg has boolean value
value = "true";
}
@@ -130,10 +140,9 @@
arguments.push_back(newArgument);
#ifdef DEBUG
- cout << "Argument defined:";
- cout << "\n flagshort: " << flagShort << "\n flagLong: " << flagLong
- << "\n usage : " << usage << "\n hasValue: " << hasValue
- << "\n type: " << type << "\n value: " << value << endl;
+ cout << "(" << flagShort << ", " << flagLong
+ << ", " << usage << ", " << hasValue
+ << ", " << type << ", " << value << ")" << endl;
#endif
return found;
@@ -149,6 +158,9 @@
return iter->getValue();
iter++;
}
+ stringstream s;
+ s << "getStringValue error with " << key << endl;
+ throw (s.str()).c_str();
return "";
}
@@ -162,6 +174,9 @@
}
iter++;
}
+ stringstream s;
+ s << "getDoubleValue error with " << key << endl;
+ throw (s.str()).c_str();
return -1.;
}
@@ -178,6 +193,9 @@
}
iter++;
}
+ stringstream s;
+ s << "getIntValue error with " << key << endl;
+ throw (s.str()).c_str();
return i;
}
@@ -190,5 +208,20 @@
return (iter->getValue() != "");
iter++;
}
+ stringstream s;
+ s << "getBoolValue error with " << key << endl;
+ throw (s.str()).c_str();
return false;
}
+
+// return the vector of arguments, so as to be printed in usage()
+vector<itsArgument> itsArgumentParser::getArguments(){
+
+ return this->arguments;
+}
+
+// return the name of argv's first word ( ~ ometah )
+string itsArgumentParser::getCommand(){
+
+ return this->argv.at(0);
+}
Index: ometah/interface/itsArgument.hpp
diff -u ometah/interface/itsArgument.hpp:1.7
ometah/interface/itsArgument.hpp:1.8
--- ometah/interface/itsArgument.hpp:1.7 Thu Jun 2 21:59:39 2005
+++ ometah/interface/itsArgument.hpp Fri Jun 3 07:57:23 2005
@@ -1,5 +1,5 @@
/***************************************************************************
- * $Id: itsArgument.hpp,v 1.7 2005/06/02 21:59:39 nojhan Exp $
+ * $Id: itsArgument.hpp,v 1.8 2005/06/03 07:57:23 jpa Exp $
* Copyright : Université Paris 12 Val-de-Marne
* Author : Johann Dréo <address@hidden>
* Author : Jean-Philippe Aumasson <address@hidden>
@@ -33,7 +33,7 @@
#define DEBUG 1
#define VERSION "OpenMetaheuristics version pre-alpha -10"
-#define USAGE "Usage"
+#define USAGE "usage" // string value doesn't matter
using namespace std;
@@ -65,7 +65,7 @@
~itsArgument();
//! Constructor
- itsArgument(string flaShort, string flagLong, string usage,
+ itsArgument(string flagShort, string flagLong, string usage,
bool hasValue=false, string type="", string valueDefault="");
string getKey();
@@ -73,6 +73,8 @@
string getLongKey();
string getValue();
+
+ string getUsage();
};
@@ -96,6 +98,8 @@
//! Constructor
itsArgumentParser(int, vector<string>);
+ void searchEndFlags();
+
bool defArg(string flagShort, string flagLong, string usage,
bool hasValue=false, string type="", string valueDefault="");
@@ -107,6 +111,7 @@
bool getBoolValue(string flag);
- void searchEndFlags();
+ vector<itsArgument> getArguments();
+ string getCommand();
};
Index: ometah/interface/ometah.cpp
diff -u ometah/interface/ometah.cpp:1.26 ometah/interface/ometah.cpp:1.27
--- ometah/interface/ometah.cpp:1.26 Thu Jun 2 21:59:39 2005
+++ ometah/interface/ometah.cpp Fri Jun 3 07:57:23 2005
@@ -1,5 +1,5 @@
/***************************************************************************
- * $Id: ometah.cpp,v 1.26 2005/06/02 21:59:39 nojhan Exp $
+ * $Id: ometah.cpp,v 1.27 2005/06/03 07:57:23 jpa Exp $
* Copyright : Université Paris 12 Val-de-Marne
* Author : Johann Dréo <address@hidden>
* Author : Jean-Philippe Aumasson <address@hidden>
@@ -29,9 +29,19 @@
using namespace std;
-void usage(){
+void usage(string cmd, vector<itsArgument> arguments){
- cout << "Usage:" << endl;
+ cout << "Usage: " << cmd << "[options]" << endl; // TODO
+ vector<itsArgument>::iterator iter;
+ iter = arguments.begin();
+ while (iter != arguments.end()){
+ cout << "\t" << iter->getKey()
+ << ", " << iter->getLongKey()
+ << "\t\t" << iter->getUsage()
+ << endl;
+ iter++;
+ }
+
}
int main(int argc, char ** argv)
@@ -96,26 +106,30 @@
// create a parser
itsArgumentParser argumentParser(argc, argumentsVector);
-
+ try {
// arguments definitions
argumentParser.defArg("-p", "--problem",
- "the name of the problem", true, "string", "Rosenbrock");
+ "problem's name", true, "string", "Rosenbrock");
argumentParser.defArg("-m", "--metah",
- "metaheuristic name", true, "string", "CEDA");
- argumentParser.defArg("-c", "--com-client",
+ "metaheuristic's name", true, "string", "CEDA");
+ argumentParser.defArg("-C", "--com-client",
"communication client mode" ,true, "string", "Embedded");
- argumentParser.defArg("-s", "--com-server",
+ argumentParser.defArg("-S", "--com-server",
"communication server mode" ,true, "string", "Embedded");
- argumentParser.defArg("-d", "--debug",
+ argumentParser.defArg("-D", "--debug",
"debug key" ,true, "string", "");
argumentParser.defArg("-i", "--iterations",
"maximum number of iterations" ,true, "int", "10");
- argumentParser.defArg("-a", "--sample-size",
+ argumentParser.defArg("-s", "--sample-size",
"number of points in the sample" ,true, "int", "10");
- argumentParser.defArg("-m", "--dimension",
+ argumentParser.defArg("-d", "--dimension",
"dimension of the problem" ,true, "int", "1");
-
+ }
+ catch(const char * s) {
+ cerr << s;
+ return -1;
+ }
// look for end flags (-v, -h, etc...)
@@ -123,21 +137,27 @@
argumentParser.searchEndFlags();
}
catch (const char * s){
- if (s==VERSION){
+ if (!strcmp(VERSION, s)){
cerr << s << endl;
return -1;
}
- else if (s==USAGE){
- usage();
+ else if (!strcmp(USAGE, s)){
+ usage(argumentParser.getCommand(), argumentParser.getArguments());
return -1;
}
}
-
#ifdef DEBUG
- cout << "\ngetValues :" << "\n problem: " <<
argumentParser.getStringValue("-p")
- << "\nmetah: "<< argumentParser.getStringValue("-m") << endl;
+ cout << "\ngetValues :\n-----" << "\n problem: " <<
argumentParser.getStringValue("-p")
+ << "\n metah: "<< argumentParser.getStringValue("-m");
+ cout << "\n client: " << argumentParser.getStringValue("-C")
+ << "\n server " << argumentParser.getStringValue("-S")
+ << "\n debug: "<< argumentParser.getStringValue("-D")
+ << "\n iterations: " << argumentParser.getIntValue("-i")
+ << "\n sample size: " << argumentParser.getIntValue("-s")
+ << "\n dimension: " << argumentParser.getIntValue("-d")
+ << endl << endl;
#endif
@@ -145,12 +165,20 @@
* Choose the items
*/
- setMetaheuristic.choose(argumentParser.getStringValue("-m"));
- setProblem.choose(argumentParser.getStringValue("-p"));
- setCommunicationClient.choose(argumentParser.getStringValue("-c"));
- setCommunicationServer.choose(argumentParser.getStringValue("-s"));
-
-
+ try {
+ setMetaheuristic.choose(argumentParser.getStringValue("-m"));
+ setProblem.choose(argumentParser.getStringValue("-p"));
+ setCommunicationClient.choose(argumentParser.getStringValue("-C"));
+ setCommunicationServer.choose(argumentParser.getStringValue("-S"));
+ }
+ catch (const char * s){
+ cerr << s;
+ return -1;
+ }
+#ifdef DEBUG
+ cout << "items chosen" << endl;
+#endif
+
/*
* Links
* Warning : be sure to do the "choose" step before
@@ -163,11 +191,15 @@
setCommunicationServer.item()->problem = setProblem.item();
// Special case for the embedded protocol : we must link client and server
- if( setCommunicationClient.item()->getKey() ==
argumentParser.getStringValue("-c") &&
- setCommunicationServer.item()->getKey() ==
argumentParser.getStringValue("-s")) {
+ if( setCommunicationClient.item()->getKey() ==
argumentParser.getStringValue("-C") &&
+ setCommunicationServer.item()->getKey() ==
argumentParser.getStringValue("-S")) {
setCommunicationClient.item()->problem = setCommunicationServer.item();
}
+
+#ifdef DEBUG
+ cout << "links done" << endl;
+#endif
/*
* Parameter setting
@@ -176,7 +208,13 @@
// giving parameters
hash_map<string,string, eqstr> parameters;
setCommunicationClient.item()->initialization( parameters );
+
+
+#ifdef DEBUG
+ cout << "initialization communication client done" << endl;
+#endif
+
/*
* Launch the optimization
@@ -192,10 +230,15 @@
//setMetaheuristic.item()->setLogLevel(0);
// parameters
- setProblem.item()->setDimension( argumentParser.getIntValue("-m") );
- setMetaheuristic.item()->setSampleSize( argumentParser.getIntValue("-a") );
+ setProblem.item()->setDimension( argumentParser.getIntValue("-d") );
+ setMetaheuristic.item()->setSampleSize( argumentParser.getIntValue("-s") );
setMetaheuristic.item()->setIterationsMaxNumber(
argumentParser.getIntValue("-i") );
+#ifdef DEBUG
+ cout << "parameters ok, starting optimization..." << endl;
+#endif
+
+
// Starting the optimization
Index: ometah/interface/ometah.hpp
diff -u ometah/interface/ometah.hpp:1.5 ometah/interface/ometah.hpp:1.6
--- ometah/interface/ometah.hpp:1.5 Thu Jun 2 19:19:12 2005
+++ ometah/interface/ometah.hpp Fri Jun 3 07:57:23 2005
@@ -1,5 +1,5 @@
/***************************************************************************
- * $Id: ometah.hpp,v 1.5 2005/06/02 19:19:12 jpa Exp $
+ * $Id: ometah.hpp,v 1.6 2005/06/03 07:57:23 jpa Exp $
* Copyright : Université Paris 12 Val-de-Marne
* Author : Johann Dréo <address@hidden>
* Author : Jean-Philippe Aumasson <address@hidden>
@@ -52,4 +52,4 @@
using namespace std;
-void usage();
+void usage(string, vector<itsArgument>);
- [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, 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