ometah-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[oMetah-devel] ometah/interface ometah.cpp


From: Jean-Philippe Aumasson
Subject: [oMetah-devel] ometah/interface ometah.cpp
Date: Wed, 01 Jun 2005 09:49:03 -0400

CVSROOT:        /cvsroot/ometah
Module name:    ometah
Branch:         
Changes by:     Jean-Philippe Aumasson <address@hidden> 05/06/01 13:49:03

Modified files:
        interface      : ometah.cpp 

Log message:
        * read command line entry, and partially check it. Introduce some 
options (communication mode, output file, debug key...)

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/interface/ometah.cpp.diff?tr1=1.18&tr2=1.19&r1=text&r2=text

Patches:
Index: ometah/interface/ometah.cpp
diff -u ometah/interface/ometah.cpp:1.18 ometah/interface/ometah.cpp:1.19
--- ometah/interface/ometah.cpp:1.18    Tue May 31 13:42:56 2005
+++ ometah/interface/ometah.cpp Wed Jun  1 13:49:02 2005
@@ -1,7 +1,8 @@
 /***************************************************************************
- *  $Id: ometah.cpp,v 1.18 2005/05/31 13:42:56 nojhan Exp $
+ *  $Id: ometah.cpp,v 1.19 2005/06/01 13:49:02 jpa Exp $
  *  Copyright : Université Paris 12 Val-de-Marne
  *  Author : Johann Dréo <address@hidden>
+ *  Author : Jean-Philippe Aumasson <address@hidden>
  ****************************************************************************/
 
 /*  Open Metaheuristic is a Library aimed at the conception of metaheuristics 
@@ -23,164 +24,240 @@
  */
  
  
-#include <hash_map.h>
+#include "ometah.hpp"
 
-// common stuff
-#include "../common/logic.hpp"
-#include "../common/itsSet.hpp"
-
-// basic classes
-#include "../metaheuristic/itsMetaheuristic.hpp"
-#include "../problem/itsProblem.hpp"
-#include "../communication/itsCommunicationClient.hpp"
-#include "../communication/itsCommunicationServer.hpp"
-
-// metaheuristics
-#include "../metaheuristic/itsEstimationOfDistribution.hpp"
-
-// problems
-#include "../problem/itsRosenbrock.hpp"
-
-// communication
-#include "../communication/itsCommunicationServer_embedded.hpp"
-#include "../communication/itsCommunicationClient_embedded.hpp"
+using namespace std;
 
 
-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\tROSE\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 (default: none)\n";
+  cerr << "\t-o\tfile\t\tOutput to the given file (default: stdout)\n";  
+  exit(-1);
+}
+
+
+void fatal(char * msg){
+  /* when an error in cmd line entries occurs, ie problem unknown... */
+  cout << "Fatal error: " << msg << "\n";
+  exit(-1);
+} 
+
+
+/*
+  Parameters in cmd line :
+  -----------------------
+  required : 
+  problem (key)
+  metaheuristic (key)
+  
+  not required :
+  debugkey (default = none)
+  ComClient (default = Embedded)
+  ComServer (default = Embedded)
+  output (default = stdout )  
+*/
+
+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)
+void display_cmd(cmdargs_t * cmd){
+
+  cout << "\nproblem:  " << cmd->problem_key;
+  cout << "\nmetaheur: " << cmd->metaheur_key;
+  cout << "\nclient:   " << cmd->cc_mode;
+  cout << "\nserver:   " << cmd->cs_mode;
+  cout << "\ndebug:    " << cmd->debug_key;
+  cout << "\noutput:   " << cmd->output;
+  cout << "\n";
+}
+
+
+int main(int argc, char ** argv)
 {
 
-    // differents sets of objects
-    itsSet<itsMetaheuristic*> setMetaheuristic;
-    itsSet<itsProblem*> setProblem;
-    itsSet<itsCommunicationClient*> setCommunicationClient;
-    itsSet<itsCommunicationServer*> setCommunicationServer;
+  cmdargs_t cmd;
+
+  // check cmd line correctness and alter cmd_args
+  if (!get_args(argc, argv, &cmd))
+    usage(argv[0]);
+
+  display_cmd(&cmd);
 
+  // differents sets of objects
+  itsSet<itsMetaheuristic*> setMetaheuristic;
+  itsSet<itsProblem*> setProblem;
+  itsSet<itsCommunicationClient*> setCommunicationClient;
+  itsSet<itsCommunicationServer*> setCommunicationServer;
 
-    /*
-     *  Metaheuristics part
-     */
+
+  /*
+   *  Metaheuristics part
+   */
     
-    // the factory for metaheuristics
-    itsMetaheuristicFactory* factoryMetaheuristics;
+  // the factory for metaheuristics
+  itsMetaheuristicFactory* factoryMetaheuristics;
 
-    // add the estimation of distribution algorithm
-    factoryMetaheuristics = new itsEstimationOfDistributionFactory;
-    setMetaheuristic.add( factoryMetaheuristics->create() );
+  // add the estimation of distribution algorithm
+  factoryMetaheuristics = new itsEstimationOfDistributionFactory;
+  setMetaheuristic.add( factoryMetaheuristics->create() );
 
 
-    /*
-     *  Problems part
-     */
+  /*
+   *  Problems part
+   */
     
-    // the factory for problems
-    itsProblemFactory* factoryProblems;
+  // the factory for problems
+  itsProblemFactory* factoryProblems;
     
-    // add Rosenbrock
-    factoryProblems = new itsRosenbrockFactory;
-    setProblem.add( factoryProblems->create() );
+  // add Rosenbrock
+  factoryProblems = new itsRosenbrockFactory;
+  setProblem.add( factoryProblems->create() );
     
     
-    /*
-     *  Communication part
-     */
+  /*
+   *  Communication part
+   */
       
-    // the factory for communication client
-    itsCommunicationClientFactory * factoryClient;
-    itsCommunicationServerFactory * factoryServer;
+  // the factory for communication client
+  itsCommunicationClientFactory * factoryClient;
+  itsCommunicationServerFactory * factoryServer;
     
-    // add the embedded protocol
-    factoryClient = new itsCommunicationClientFactory_embedded;
-    setCommunicationClient.add( factoryClient->create() );
+  // add the embedded protocol
+  factoryClient = new itsCommunicationClientFactory_embedded;
+  setCommunicationClient.add( factoryClient->create() );
     
-    factoryServer = new itsCommunicationServerFactory_embedded;
-    setCommunicationServer.add( factoryServer->create() );
+  factoryServer = new itsCommunicationServerFactory_embedded;
+  setCommunicationServer.add( factoryServer->create() );
 
 
-    /* 
-     *  Choose the items
-     */
+  /* 
+   *  Choose the items
+   */
     
-    setMetaheuristic.choose("CEDA");
-    setProblem.choose("Rosenbrock");
-    setCommunicationClient.choose("Embedded");
-    setCommunicationServer.choose("Embedded");
+  setMetaheuristic.choose("CEDA");
+  setProblem.choose("Rosenbrock");
+  setCommunicationClient.choose("Embedded");
+  setCommunicationServer.choose("Embedded");
     
     
-    /*
-     *  Links
-     *  Warning : be sure to do the "choose" step before
-     */
+  /*
+   *  Links
+   *  Warning : be sure to do the "choose" step before
+   */
     
-    // metaheuristic -> client
-    setMetaheuristic.item()->problem = setCommunicationClient.item();
+  // metaheuristic -> client
+  setMetaheuristic.item()->problem = setCommunicationClient.item();
     
-    // server -> problem
-    setCommunicationServer.item()->problem = setProblem.item();
+  // server -> problem
+  setCommunicationServer.item()->problem = setProblem.item();
     
     
-    /*
-     *  Parameter setting
-     */
+  /*
+   *  Parameter setting
+   */
     
-    // Special case for the embedded protocol : we must link client and server
-    if( setCommunicationClient.item()->getKey() == "Embedded" && 
-        setCommunicationServer.item()->getKey() == "Embedded" ) {
-        setCommunicationClient.item()->problem = setCommunicationServer.item();
-    }
+  // Special case for the embedded protocol : we must link client and server
+  if( setCommunicationClient.item()->getKey() == "Embedded" && 
+      setCommunicationServer.item()->getKey() == "Embedded" ) {
+    setCommunicationClient.item()->problem = setCommunicationServer.item();
+  }
 
-    // giving parameters
-    hash_map<string,string, eqstr> parameters;
-    setCommunicationClient.item()->initialization( parameters );
+  // giving parameters
+  hash_map<string,string, eqstr> parameters;
+  setCommunicationClient.item()->initialization( parameters );
     
     
-    /*
-     *  Launch the optimization
-     */
+  /*
+   *  Launch the optimization
+   */
     
-    //setMetaheuristic.item()->start();
-
+  // TESTS
 
-    // TESTS
+  // Debug keys
+  setMetaheuristic.item()->addDebugKey("sample_solutions");
+  //setMetaheuristic.item()->addDebugKey("selectNumber");
 
-    // Debug keys
-    setMetaheuristic.item()->addDebugKey("sample_solutions");
-    //setMetaheuristic.item()->addDebugKey("selectNumber");
+  // Log
+  setMetaheuristic.item()->setLogLevel(0);
 
-    // Log
-    setMetaheuristic.item()->setLogLevel(0);
+  // parameters
+  setProblem.item()->setDimension(2);
+  setMetaheuristic.item()->setSampleSize(100);
+  setMetaheuristic.item()->setIterationsMaxNumber(100);
 
-    // parameters
-    setProblem.item()->setDimension(2);
-    setMetaheuristic.item()->setSampleSize(100);
-    setMetaheuristic.item()->setIterationsMaxNumber(100);
 
-
-    // Starting the optimization
-    /*
+  // Starting the optimization
+  /*
     clog << "Launching " << setMetaheuristic.item()->getName() 
-         << " on " << setProblem.item()->getName() 
-         << " using " << setCommunicationClient.item()->getKey() << endl;
-    */
+    << " on " << setProblem.item()->getName() 
+    << " using " << setCommunicationClient.item()->getKey() << endl;
+  */
 
-    //clog << setProblem.item()->getName() << " description:" << endl;
-    //clog << setProblem.item()->getInformations() << endl;
+  //clog << setProblem.item()->getName() << " description:" << endl;
+  //clog << setProblem.item()->getInformations() << endl;
 
+  /*
     try {
-        setMetaheuristic.item()->start();
+    setMetaheuristic.item()->start();
     }
     catch(const char * str) {
-        cerr << str << endl;
+    cerr << str << endl;
     }
     catch(string str) {
-        cerr << str << endl;
+    cerr << str << endl;
     }
     catch (...) {
-        cerr << "Unknown error" << endl;
+    cerr << "Unknown error" << endl;
     }
-
+  */
     
     
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]