Ejemplo n.º 1
0
std::tuple<std::shared_ptr<terrama2::core::DataManager>, std::shared_ptr<terrama2::core::Service>, std::shared_ptr<terrama2::core::ProcessLogger> >
createService(const std::string& serviceType)
{
  if(serviceType == collectorType)
    return createCollector();
  if(serviceType == analysisType)
    return createAnalysis();
  if(serviceType == viewType)
    return createView();

  exit(SERVICE_LOAD_ERROR);
}
    MetronamicaOF2RandstadLargeCaseStudy3Obj(boost::filesystem::path & metro_exe,
                   boost::filesystem::path & mck_exe,
                   boost::filesystem::path & wine_exe,
                   boost::filesystem::path & java_exe,
                   boost::filesystem::path & geoproj_edit_jar,
                   boost::filesystem::path & template_path,
                   boost::filesystem::path & working_dir,
                                 boost::filesystem::path & save_dir,
                   std::string &_wine_work_dir,
                   std::string &_geoproj_name,
                   boost::filesystem::path & _logfile_name,
                   boost::filesystem::path & actual_map_path,
                   boost::filesystem::path & original_map_path,
                   boost::filesystem::path & masking_map_path,
                   boost::filesystem::path &  fks_coefficients_path,
                   boost::filesystem::path & wine_regedit_path,
                   int _id = 0,
                   bool _is_logging = false,
                   int _replicates = 10)
        :   num_objectives(3),
          num_real_decision_vars(238),
          num_int_decision_vars(0),
          num_constraints(0),
          replicates(_replicates),
          geo_cmd(metro_exe),
          java_geoproj_edit(geoproj_edit_jar),
          mck_cmd(mck_exe),
          wine_cmd(wine_exe),
          java_cmd(java_exe),
          template_dir(template_path),
          working_dir(working_dir),
          save_dir(save_dir),
          wine_temp_dir(_wine_work_dir),
          geoproject_name(_geoproj_name),
          metro_logfile_name(_logfile_name),
          actual_map(actual_map_path),
          original_map(original_map_path),
          masking_map(masking_map_path),
          fks_coefficients(fks_coefficients_path),
          wine_regedit(wine_regedit_path),
          int_lowerbounds(0, std::numeric_limits<int>::min()),
          int_upperbounds(0, std::numeric_limits<int>::max()),
          prob_defs(new ProblemDefinitions(min_dv_values, max_dv_values,  int_lowerbounds, int_upperbounds, minimise_or_maximise, num_constraints)),
          objectives_and_constrataints(std::piecewise_construct, std::make_tuple(num_objectives, std::numeric_limits<double>::max()), std::make_tuple(num_constraints)),
          evaluator_id(_id),
          is_logging(_is_logging),
          eval_count(0)
    {
        analysisNum = createAnalysis();
        loadMapActual(analysisNum, actual_map.c_str());
        loadOriginalMap(analysisNum, original_map.c_str());
        loadMaskingMap(analysisNum, masking_map.c_str());
        loadTransitionFuzzyWeights(analysisNum, fks_coefficients.c_str());
        numClasses(analysisNum, 9);

        std::string temp_dir_template = "Metro_Cal_OF_worker" + std::to_string(evaluator_id) + "_%%%%-%%%%";
        worker_dir = boost::filesystem::unique_path(working_dir / temp_dir_template);
        //            create_directories(ph);
        copyDir(template_dir, worker_dir);


        namespace fs = boost::filesystem;
        std::string metro_cp_log_name = "calibration_log_%%%%-%%%%.xml";
        boost::filesystem::path metro_cp_log_path = boost::filesystem::unique_path(worker_dir / metro_cp_log_name);
        fs::copy_file(
                    metro_logfile_name,
                    metro_cp_log_path
                    );
        cp_metro_log_name = metro_cp_log_path.filename().string();

        //        std::string filename = "logWorker" + std::to_string(evaluator_id) + "_WineRegEdit_" + boost::posix_time::to_simple_string(boost::posix_time::second_clock::local_time()) + ".log";
        //        boost::filesystem::path log_file_name = working_dir / filename;
        //        std::ofstream logging_file;
        //        if (is_logging)
        //        {
        //            logging_file.open(log_file_name.c_str(), std::ios_base::app);
        //            if (!logging_file.is_open()) is_logging = false;
        //        }

        //        std::stringstream cmd;
        //        cmd << wine_cmd << " regedit " << wine_regedit_path;
        //        if (is_logging) cmd << " >> \"" << log_file_name.c_str() << "\" 2>&1";
        //        if (is_logging) logging_file << "Running: " << cmd.str() << "\n";
        //        system(cmd.str().c_str());

        colour_mapper.push_back(std::make_tuple(255,   255,   160));
        colour_mapper.push_back(std::make_tuple(255,   128,     0));
        colour_mapper.push_back(std::make_tuple(255,     0,     0));
        colour_mapper.push_back(std::make_tuple( 78,     0,   192));
        colour_mapper.push_back(std::make_tuple(158,    12,   234));
        colour_mapper.push_back(std::make_tuple(255,    87,   255));
        colour_mapper.push_back(std::make_tuple(  0,   192,     0));
        colour_mapper.push_back(std::make_tuple(192,   157,     0));
        colour_mapper.push_back(std::make_tuple(  0,     0,     0));
        colour_mapper.push_back(std::make_tuple(  0,   128,   255));

        //Make sure the number of dv is correct
        BOOST_ASSERT(max_dv_values.size() == 520);
    }
Ejemplo n.º 3
0
/* This function builds up the netlist representation from the checked
   netlist input.  It creates circuit components as necessary. */
void input::factory (void) {

  struct definition_t * def, * next;
  struct node_t * nodes;
  struct pair_t * pairs;
  circuit * c;
  object * o;
  analysis * a;
  substrate * s;
  nodeset * n;
  int i;

  // go through the list of input definitions
  for (def = definition_root; def != NULL; def = next) {
    next = def->next;
    // handle actions
    if (def->action) {
      if ((a = createAnalysis (def->type)) != NULL) {
	a->setName (def->instance);

	// add the properties to analysis
	for (pairs = def->pairs; pairs != NULL; pairs = pairs->next)
	  if (pairs->value->ident) {
	    if (pairs->value->var && strcmp (pairs->key, "Param")) {
	      variable * v;
	      if ((v = def->env->getVariable (pairs->value->ident)) != NULL) {
		// equation variable reference in analysis property
		a->addProperty (pairs->key, v);
	      }
	      else {
		// should not be reached!
		a->addProperty (pairs->key, pairs->value->ident);
	      }
	    }
	    else {
	      // ususal string property
	      a->addProperty (pairs->key, pairs->value->ident);
	    }
	  } else {
	    if (pairs->value->var) {
	      // add list sweeps and constants to the properties
	      variable * v = new variable (pairs->key);
	      constant * c = new constant (TAG_VECTOR);
	      c->v = createVector (pairs->value);
	      v->setConstant (c);
	      a->addProperty (pairs->key, v);
	    }
	    else {
	      a->addProperty (pairs->key, pairs->value->value);
	    }
	  }
	// additionally add missing optional properties
	assignDefaultProperties (a, def->define);
	a->setEnv (def->env);
	subnet->insertAnalysis (a);
      }
      // remove this definition from the list
      definition_root = netlist_unchain_definition (definition_root, def);
    }
  }

  // go through the list of input definitions
  for (def = definition_root; def != NULL; def = next) {
    next = def->next;
    // handle substrate definitions
    if (!def->action && def->substrate) {
      if ((s = createSubstrate (def->type)) != NULL) {
	s->setName (def->instance);

	// add the properties to substrate
	for (pairs = def->pairs; pairs != NULL; pairs = pairs->next)
	  if (pairs->value->ident) {
	    // a variable
	    if (pairs->value->var) {
	      // at this stage it should be ensured that the variable is
	      // already in the root environment
	      variable * v = def->env->getVariable (pairs->value->ident);
	      s->addProperty (pairs->key, v);
	    }
	    // a usual string property
	    else {
	      s->addProperty (pairs->key, pairs->value->ident);
	    }
	  } else {
	    s->addProperty (pairs->key, pairs->value->value);
	  }
	// additionally add missing optional properties
	assignDefaultProperties (s, def->define);

	// put new substrate definition into environment
	char * n = strrchr (def->instance, '.');
	variable * v = new variable (n ? n + 1 : def->instance);
	v->setSubstrate (s);
	def->env->addVariable (v);
      }
      // remove this definition from the list
      definition_root = netlist_unchain_definition (definition_root, def);
    }
    // handle nodeset definitions
    else if (!def->action && def->nodeset) {
      n = new nodeset ();
      n->setName (def->nodes->node);
      n->setValue (def->pairs->value->value);
      subnet->addNodeset (n);
      // remove this definition from the list
      definition_root = netlist_unchain_definition (definition_root, def);
    }
  }

  // go through the list of input definitions
  for (def = definition_root; def != NULL; def = next) {
    next = def->next;
    // handle component definitions
    if (!def->action && !def->substrate && !def->nodeset) {
      c = createCircuit (def->type);
      assert (c != NULL);
      o = (object *) c;
      c->setName (def->instance);
      c->setNonLinear (def->nonlinear != 0);
      c->setSubcircuit (def->subcircuit);

      // change size (number of ports) of variable sized components
      if (c->isVariableSized ()) {
	c->setSize (def->ncount);
      }
      // add appropriate nodes to circuit
      for (i = 0, nodes = def->nodes; nodes; nodes = nodes->next, i++)
	if (i < c->getSize ())
	  c->setNode (i, nodes->node);

      // add the properties to circuit
      for (pairs = def->pairs; pairs != NULL; pairs = pairs->next) {
	if (pairs->value == NULL) {
	  // zero-length value lists
	  variable * v = new variable (pairs->key);
	  constant * c = new constant (TAG_VECTOR);
	  c->v = new vector ();
	  v->setConstant (c);
	  o->addProperty (pairs->key, v);
	}
	else if (pairs->value->ident) {
	  if (pairs->value->var) {
	    // at this stage it should be ensured that the variable is
	    // already in the root environment
	    variable * v = def->env->getVariable (pairs->value->ident);
	    o->addProperty (pairs->key, v);
	  } else {
	    if (pairs->value->subst) {
	      variable * v = def->env->getVariable (pairs->value->ident);
	      c->setSubstrate (v->getSubstrate ());
	    }
	    o->addProperty (pairs->key, pairs->value->ident);
	  }
	} else {
	  if (pairs->value->var) {
	    // add value lists to the properties
	    variable * v = new variable (pairs->key);
	    constant * c = new constant (TAG_VECTOR);
	    c->v = createVector (pairs->value);
	    v->setConstant (c);
	    o->addProperty (pairs->key, v);
	  } else {
	    o->addProperty (pairs->key, pairs->value->value);
	  }
	}
      }
      // set local circuit environment
      c->setEnv (def->env);

      // additionally add missing optional properties
      assignDefaultProperties (c, def->define);

      // insert the circuit into the netlist object
      subnet->insertCircuit (c);

      // remove this definition from the list
      definition_root = netlist_unchain_definition (definition_root, def);
    }
  }
}