[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[oMetah-devel] ometah ./SConstruct interface/itsArgument.cpp i...
From: |
NoJhan |
Subject: |
[oMetah-devel] ometah ./SConstruct interface/itsArgument.cpp i... |
Date: |
Thu, 02 Jun 2005 06:59:30 -0400 |
CVSROOT: /cvsroot/ometah
Module name: ometah
Branch:
Changes by: NoJhan <address@hidden> 05/06/02 10:59:30
Modified files:
. : SConstruct
interface : itsArgument.cpp itsArgument.hpp ometah.cpp
ometah.hpp
Log message:
* some minor corrections on itsArgument
* tests in ometah.cpp
* compilation tag in SConstruct for itsArgument
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/SConstruct.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/interface/itsArgument.cpp.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/interface/itsArgument.hpp.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/interface/ometah.cpp.diff?tr1=1.21&tr2=1.22&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/interface/ometah.hpp.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
Patches:
Index: ometah/SConstruct
diff -u ometah/SConstruct:1.9 ometah/SConstruct:1.10
--- ometah/SConstruct:1.9 Wed May 25 15:33:15 2005
+++ ometah/SConstruct Thu Jun 2 10:59:29 2005
@@ -33,7 +33,7 @@
'itsCommunicationClient_embedded.cpp',
'itsCommunicationServer_embedded.cpp']
communication = ['communication/'+i for i in communication]
-interface = ['ometah.cpp']
+interface = ['ometah.cpp','itsArgument.cpp']
interface = ['interface/'+i for i in interface]
env.Program( target = 'ometah', source =
common+metaheuristic+problem+communication+interface )
Index: ometah/interface/itsArgument.cpp
diff -u ometah/interface/itsArgument.cpp:1.3
ometah/interface/itsArgument.cpp:1.4
--- ometah/interface/itsArgument.cpp:1.3 Thu Jun 2 09:41:56 2005
+++ ometah/interface/itsArgument.cpp Thu Jun 2 10:59:30 2005
@@ -1,5 +1,5 @@
/***************************************************************************
- * $Id: itsArgument.cpp,v 1.3 2005/06/02 09:41:56 jpa Exp $
+ * $Id: itsArgument.cpp,v 1.4 2005/06/02 10:59:30 nojhan Exp $
* Copyright : Université Paris 12 Val-de-Marne
* Author : Johann Dréo <address@hidden>
* Author : Jean-Philippe Aumasson <address@hidden>
@@ -38,31 +38,33 @@
}
// constructor...
-itsArgument::itsArgument(string flagShort, string flagLong, bool hasValue,
string usage, string type, string value){
+itsArgument::itsArgument(string flaShort, string flagLong, string usage,
+ bool hasValue, string type, string valueDefault)
+{
this->flagShort = flagShort;
this->flagLong = flagLong;
- this->hasValue = hasValue;
this->usage = usage;
+ this->hasValue = hasValue;
this->type = type;
- this->value = value;
+ this->value = valueDefault;
}
// return default key (ie -v )
-string itsArgument::getKey(){
-
+string itsArgument::getKey()
+{
return this->flagShort;
}
// return long key (ie --version)
-string itsArgument::getLongKey(){
-
+string itsArgument::getLongKey()
+{
return this->flagLong;
}
// return the argument as a string
-string itsArgument::getValue(){
-
+string itsArgument::getValue()
+{
if (this->hasValue)
return this->value;
return "";
@@ -71,39 +73,40 @@
// ITSPARSER
// destructor
-itsParser::~itsParser(){
+itsParser::~itsParser()
+{
}
// constructor, with argv as the command line values
-itsParser::itsParser(vector<string> argv){
-
+itsParser::itsParser(vector<string> argv)
+{
this->argv = argv;
-
}
// parse argv searching the given flag, then update the vector with a new
argument
-int itsParser::defArg(string flagShort, string flagLong,
- bool hasValue, string desc, string type){
+bool itsParser::defArg(string flagShort, string flagLong, string usage,
+ bool hasValue, string type, string valueDefault)
+{
int i =1;
- int found = 0;
+ bool found = false;
string value = "";
- while ((i < this->argc) && (!found)){
+ while ((i < this->argc) && (!found)) {
if ( (flagShort == this->argv[i]) || (flagLong == this->argv[i]) ){
i = this->argc;
- if (hasValue){
- value = argv[i+1];
+ if (hasValue) {
+ value = argv[i+1];
}
- found = 1;
+ found = true;
}
}
- itsArgument newArgument(flagShort, flagLong, hasValue, desc, type, value);
+ 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.3
ometah/interface/itsArgument.hpp:1.4
--- ometah/interface/itsArgument.hpp:1.3 Thu Jun 2 09:41:57 2005
+++ ometah/interface/itsArgument.hpp Thu Jun 2 10:59:30 2005
@@ -1,5 +1,5 @@
/***************************************************************************
- * $Id: itsArgument.hpp,v 1.3 2005/06/02 09:41:57 jpa Exp $
+ * $Id: itsArgument.hpp,v 1.4 2005/06/02 10:59:30 nojhan Exp $
* Copyright : Université Paris 12 Val-de-Marne
* Author : Johann Dréo <address@hidden>
* Author : Jean-Philippe Aumasson <address@hidden>
@@ -50,18 +50,18 @@
// type of the associated value, if there
string type;
-
-
+ // default value
+ string value;
-public:
-string value;
+public:
// destructor
~itsArgument();
// constructor
- itsArgument(string, string, bool, string, string, string);
+ itsArgument(string flaShort, string flagLong, string usage,
+ bool hasValue=false, string type="", string valueDefault="");
string getKey();
@@ -91,14 +91,15 @@
// constructor
itsParser(vector<string>);
- int defArg(string, string, bool, string, string);
+ bool defArg(string flagShort, string flagLong, string usage,
+ bool hasValue=false, string type="", string valueDefault="");
- string getStringValue(string);
+ string getStringValue(string flag);
- double getDoubleValue(string);
+ double getDoubleValue(string flag);
- int getIntValue(string);
+ int getIntValue(string flag);
- bool getBoolValue(string);
+ bool getBoolValue(string flag);
};
Index: ometah/interface/ometah.cpp
diff -u ometah/interface/ometah.cpp:1.21 ometah/interface/ometah.cpp:1.22
--- ometah/interface/ometah.cpp:1.21 Thu Jun 2 09:41:57 2005
+++ ometah/interface/ometah.cpp Thu Jun 2 10:59:30 2005
@@ -1,5 +1,5 @@
/***************************************************************************
- * $Id: ometah.cpp,v 1.21 2005/06/02 09:41:57 jpa Exp $
+ * $Id: ometah.cpp,v 1.22 2005/06/02 10:59:30 nojhan Exp $
* Copyright : Université Paris 12 Val-de-Marne
* Author : Johann Dréo <address@hidden>
* Author : Jean-Philippe Aumasson <address@hidden>
@@ -29,80 +29,15 @@
using namespace std;
-void usage(char * argv){
- /* show usage instructions when bad parameters in cmd line */
- cerr << "Usage: " << argv << " [options] metaheuristic problem\n";
- cerr << "\twhere metaheuristic can be :\n";
- cerr << "\t\tCEDA\t\tCEDA metaheuristic\n";
- cerr << "\twhere problem can be :\n";
- cerr << "\t\tRosenbrock\t\tRosenbrock problem\n";
- cerr << "Options:\n";
- cerr << "\t-cC\tmode\t\tCommunication client mode (default: Embedded)\n";
- cerr << "\t-cS\tmode\t\tCommunication server mode (default: Embedded)\n";
- cerr << "\t-D\tmode\t\tDebug key (sample_solutions...default: none)\n";
- cerr << "\t-o\tfile\t\tOutput to the given file (default: stdout)\n";
- exit(-1);
-}
-
-
-int get_args(int argc, char ** argv, cmdargs_t *cmd){
- /* from the cmd line arguments, return a vector of string parameters */
- int i = 1;
- if ((argc < MIN_ARGS) || ( argc > MAX_ARGS))
- usage(argv[0]);
-
- // initialize with default values
- cmd->cc_mode = "Embedded";
- cmd->cs_mode = "Embedded";
- cmd->debug_key = "none";
- cmd->output = "stdout";
-
- while (i < argc){
-
- if (i == argc-2){
- cmd->metaheur_key = argv[i];
- }
- else if (i == argc-1){
- cmd->problem_key = argv[i];
- }
- else if (argv[i][0] == '-'){
- if (!strcmp(argv[i], "-cC")){
- cmd->cc_mode = argv[++i];
- }
- else if (!strcmp(argv[i], "-cS")){
- cmd->cs_mode = argv[++i];
- }
- else if (!strcmp(argv[i], "-D")){
- cmd->debug_key = argv[++i];
- }
- else if (!strcmp(argv[i], "-o")){
- cmd->output = argv[++i];
- }
- }
- i++;
- }
-
- // TODO ! check parameters !
-
- return 1;
-}
-
-
int main(int argc, char ** argv)
{
- vector<string> v;
+ vector<string> argumentsVector;
for(int i=0; i<argc; i++){
- v.push_back(argv[i]);
+ argumentsVector.push_back(argv[i]);
}
- cmdargs_t cmd;
-
- // check cmd line correctness and alter cmd_args
- if (!get_args(argc, argv, &cmd))
- usage(argv[0]);
-
// differents sets of objects
itsSet<itsMetaheuristic*> setMetaheuristic;
@@ -151,14 +86,21 @@
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(cmd.metaheur_key);
- setProblem.choose(cmd.problem_key);
- setCommunicationClient.choose(cmd.cc_mode);
- setCommunicationServer.choose(cmd.cs_mode);
+ setMetaheuristic.choose("CEDA");
+ setProblem.choose("Rosenbrock");
+ setCommunicationClient.choose("Embedded");
+ setCommunicationServer.choose("Embedded");
/*
@@ -178,8 +120,8 @@
*/
// Special case for the embedded protocol : we must link client and server
- if( setCommunicationClient.item()->getKey() == cmd.cc_mode &&
- setCommunicationServer.item()->getKey() == cmd.cs_mode ) {
+ if( setCommunicationClient.item()->getKey() == "Embedded" &&
+ setCommunicationServer.item()->getKey() == "Embedded" ) {
setCommunicationClient.item()->problem = setCommunicationServer.item();
}
@@ -195,16 +137,16 @@
// TESTS
// Debug keys
- setMetaheuristic.item()->addDebugKey(cmd.debug_key);
+ //setMetaheuristic.item()->addDebugKey(cmd.debug_key);
//setMetaheuristic.item()->addDebugKey("selectNumber");
// Log
- setMetaheuristic.item()->setLogLevel(0);
+ //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
Index: ometah/interface/ometah.hpp
diff -u ometah/interface/ometah.hpp:1.2 ometah/interface/ometah.hpp:1.3
--- ometah/interface/ometah.hpp:1.2 Wed Jun 1 15:50:57 2005
+++ ometah/interface/ometah.hpp Thu Jun 2 10:59:30 2005
@@ -1,5 +1,5 @@
/***************************************************************************
- * $Id: ometah.hpp,v 1.2 2005/06/01 15:50:57 jpa Exp $
+ * $Id: ometah.hpp,v 1.3 2005/06/02 10:59:30 nojhan Exp $
* Copyright : Université Paris 12 Val-de-Marne
* Author : Johann Dréo <address@hidden>
* Author : Jean-Philippe Aumasson <address@hidden>
@@ -46,58 +46,7 @@
#include "../communication/itsCommunicationServer_embedded.hpp"
#include "../communication/itsCommunicationClient_embedded.hpp"
-// argc min value
-#define MIN_ARGS 3
-// argc max value
-#define MAX_ARGS 12
+// interfaces
+#include "itsArgument.hpp"
using namespace std;
-
-struct cmdargs {
- string problem_key;
- string metaheur_key;
- string cc_mode;
- string cs_mode;
- string debug_key;
- string output;
-};
-
-typedef struct cmdargs cmdargs_t;
-
-void usage (char *);
-int get_args(int, char **, cmdargs_t *);
-
-
-/*
- class commandLine
- {
- protected:
-
- // required !
- string problem_key;
-
- // required !
- string metaheur_key;
-
- // communication client mode (default = Embedded)
- string cc_mode;
-
- // communication server mode (default = Embedded)
- string cs_mode;
-
- string debug_key;
-
- // stdout or file name
- string output;
- public:
- // ~ destructor
- ~commandLine();
-
- // constructor, set default values
- commandLine();
-
- int getArg(string, string, int, char **);
-
- void display();
- };
-*/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [oMetah-devel] ometah ./SConstruct interface/itsArgument.cpp i...,
NoJhan <=