[Avida-SVN] r1921 - branches/uml/source/main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Thu Aug 9 12:55:10 PDT 2007
Author: hjg
Date: 2007-08-09 15:55:10 -0400 (Thu, 09 Aug 2007)
New Revision: 1921
Modified:
branches/uml/source/main/cBirthChamber.cc
branches/uml/source/main/cOrganism.h
branches/uml/source/main/cStats.cc
branches/uml/source/main/cStats.h
branches/uml/source/main/cTaskLib.cc
branches/uml/source/main/cUMLModel.cc
branches/uml/source/main/cUMLModel.h
branches/uml/source/main/cUMLStateDiagram.cc
branches/uml/source/main/cUMLStateDiagram.h
Log:
Changes made to:
- support stats for a variable number of scenarios
- use a config option in the seed-model.cfg file to support different options
for calling Hydra
Modified: branches/uml/source/main/cBirthChamber.cc
===================================================================
--- branches/uml/source/main/cBirthChamber.cc 2007-08-09 19:05:07 UTC (rev 1920)
+++ branches/uml/source/main/cBirthChamber.cc 2007-08-09 19:55:10 UTC (rev 1921)
@@ -213,6 +213,7 @@
// FOR UML branch - hjg
child_array[0]->setParentXMI(parent.getUMLModel()->getXMI());
child_array[0]->setParentBonus(parent.getParentBonus());
+ child_array[0]->setParentScenarioCompletion(parent.getUMLModel()->getScenarioCompletion());
return true;
}
Modified: branches/uml/source/main/cOrganism.h
===================================================================
--- branches/uml/source/main/cOrganism.h 2007-08-09 19:05:07 UTC (rev 1920)
+++ branches/uml/source/main/cOrganism.h 2007-08-09 19:55:10 UTC (rev 1921)
@@ -149,6 +149,7 @@
cUMLModel m_model;
std::string m_parent_xmi;
std::map<std::string, float> m_parent_bonus;
+ std::vector<double> m_parent_scenario_completion;
cOrganism(); // @not_implemented
cOrganism(const cOrganism&); // @not_implemented
@@ -323,7 +324,8 @@
void setParentBonus (std::map<std::string, float> v) { m_parent_bonus = v; }
float getParentBonus (std::string s) { return m_parent_bonus[s]; }
std::map<std::string, float> getParentBonus() { return m_parent_bonus; }
-
+ std::vector<double> getParentScenarioCompletion() { return m_parent_scenario_completion; }
+ void setParentScenarioCompletion (std::vector<double> s) { m_parent_scenario_completion = s; }
// The jump functions jump the index of the various vectors either forward (+ int) or backwards (- int)
Modified: branches/uml/source/main/cStats.cc
===================================================================
--- branches/uml/source/main/cStats.cc 2007-08-09 19:05:07 UTC (rev 1920)
+++ branches/uml/source/main/cStats.cc 2007-08-09 19:55:10 UTC (rev 1921)
@@ -38,8 +38,10 @@
#include <cfloat>
#include <cmath>
+#include <vector>
+
cStats::cStats(cWorld* world)
: m_world(world)
, m_update(-1)
@@ -205,7 +207,6 @@
}
}
// End sense tracking initialization
-
genotype_map.Resize( m_world->GetConfig().WORLD_X.Get() * m_world->GetConfig().WORLD_Y.Get() );
SetupPrintDatabase();
@@ -997,7 +998,16 @@
df.Endl();
}
+void cStats::addScenarioCompletion(std::vector<double> s)
+{
+ m_scenario_completion.resize(s.size());
+ for(unsigned int i=0; i<s.size(); ++i) {
+ m_scenario_completion[i].Add(s[i]);
+ }
+
+}
+
void cStats::PrintUMLData(const cString& filename)
{
cDataFile& df = m_world->GetDataFile(filename);
@@ -1025,14 +1035,19 @@
df.Write( m_N2Passed.Sum(), "total number of spin N2 passes" );
df.Write( m_N1andN2Passed.Sum(), "total number of spin N1 & N2 passes");
*/
- df.Write( m_scenario5.Sum(), "total number of scenario 5 all transitions");
+/* df.Write( m_scenario5.Sum(), "total number of scenario 5 all transitions");
df.Write( m_scenario6.Sum(), "total number of scenario 6 all transitions");
df.Write( m_scenario7.Sum(), "total number of scenario 7 all transitions");
df.Write( m_scenario8.Sum(), "total number of scenario 8 all transitions");
df.Write( m_scenario5loop.Sum(), "total number of scenario 5 all transitions - might loop");
df.Write( m_scenario6loop.Sum(), "total number of scenario 6 all transitions - might loop");
- df.Write( m_scenario7loop.Sum(), "total number of scenario 7 all transitions - might loop");
+ df.Write( m_scenario7loop.Sum(), "total number of scenario 7 all transitions - might loop");*/
+
+ for (unsigned int i = 0; i < m_scenario_completion.size(); i++) {
+ df.Write ( m_scenario_completion[i].Sum(), "total number of scenario passes");
+ m_scenario_completion[i].Clear();
+ }
av_number_of_states.Clear();
@@ -1054,14 +1069,14 @@
m_W1Passed.Clear();
m_W2Passed.Clear();
m_N1andN2Passed.Clear();
- m_scenario5.Clear();
+ /* m_scenario5.Clear();
m_scenario6.Clear();
m_scenario7.Clear();
m_scenario8.Clear();
m_scenario5loop.Clear();
m_scenario6loop.Clear();
- m_scenario7loop.Clear();
+ m_scenario7loop.Clear();*/
df.Endl();
Modified: branches/uml/source/main/cStats.h
===================================================================
--- branches/uml/source/main/cStats.h 2007-08-09 19:05:07 UTC (rev 1920)
+++ branches/uml/source/main/cStats.h 2007-08-09 19:55:10 UTC (rev 1921)
@@ -29,7 +29,9 @@
#include <cassert>
#include <fstream>
#include <iostream>
+#include <vector>
+
#ifndef defs_h
#include "defs.h"
#endif
@@ -269,6 +271,7 @@
cDoubleSum m_W2Attempt;
cDoubleSum m_W2Passed;
cDoubleSum m_N1andN2Passed;
+/*
cDoubleSum m_scenario5;
cDoubleSum m_scenario6;
cDoubleSum m_scenario7;
@@ -277,7 +280,9 @@
cDoubleSum m_scenario5loop;
cDoubleSum m_scenario6loop;
cDoubleSum m_scenario7loop;
+*/
+ std::vector<cDoubleSum> m_scenario_completion;
cStats(); // @not_implemented
cStats(const cStats&); // @not_implemented
cStats& operator=(const cStats&); // @not_implemented
@@ -657,13 +662,17 @@
void W2Attempt() { m_W2Attempt.Add(1); }
void W2Passed() { m_W2Passed.Add(1); }
void N1andN2Passed() { m_N1andN2Passed.Add(1); }
- void scenario5Complete() { m_scenario5.Add(1); }
+/* void scenario5Complete() { m_scenario5.Add(1); }
void scenario6Complete() { m_scenario6.Add(1); }
void scenario7Complete() { m_scenario7.Add(1); }
void scenario8Complete() { m_scenario8.Add(1); }
void scenario5Loop() { m_scenario5loop.Add(1); }
void scenario6Loop() { m_scenario6loop.Add(1); }
- void scenario7Loop() { m_scenario7loop.Add(1); }
+ void scenario7Loop() { m_scenario7loop.Add(1); } */
+ void addScenarioCompletion(std::vector<double>); // { m_scenario_bonus[i].Add(j); }
+ /*void resizeScenarioBonus(int i) { m_scenario_bonus.resize(i); }
+ void resetScenarioBonus() {
+ for (unsigned int i = 0; i< m_scenario_bonus.size(); i++) m_scenario_bonus[i].Clear(); }*/
};
Modified: branches/uml/source/main/cTaskLib.cc
===================================================================
--- branches/uml/source/main/cTaskLib.cc 2007-08-09 19:05:07 UTC (rev 1920)
+++ branches/uml/source/main/cTaskLib.cc 2007-08-09 19:55:10 UTC (rev 1921)
@@ -2934,6 +2934,8 @@
double cTaskLib::Task_Scenarios(cTaskContext& ctx) const
{
double bonus = 0.0;
+// double temp_bonus = 0;
+ std::string sc_name;
cOrganism* org = ctx.getOrganism();
// Check if this model is different than the organism's parent's model
@@ -2941,11 +2943,14 @@
bonus = org->getUMLModel()->checkForScenarios();
} else {
bonus = org->getParentBonus("scenarios");
+ org->getUMLModel()->setScenarioCompletion(org->getParentScenarioCompletion());
}
// Set bonus info for current model
org->getUMLModel()->setBonusInfo("scenarios", bonus);
+ m_world->GetStats().addScenarioCompletion(org->getUMLModel()->getScenarioCompletion());
+
return bonus;
}
@@ -2982,27 +2987,15 @@
temp = organism->getUMLModel()->getXMI();
- float temp1, temp2, temp3, temp4;
- temp1= organism->getUMLModel()->getBonusInfo("scenario1");
- temp2= organism->getUMLModel()->getBonusInfo("scenario2");
- temp3= organism->getUMLModel()->getBonusInfo("scenario3");
- temp4= organism->getUMLModel()->getBonusInfo("scenario4");
-
- if ((organism->getUMLModel()->getBonusInfo("scenario1") != 2) ||
- (organism->getUMLModel()->getBonusInfo("scenario2") != 2) ||
- (organism->getUMLModel()->getBonusInfo("scenario3") != 3) //||
-// (organism->getUMLModel()->getBonusInfo("scenario4") != 3)
- ) {
+ // call hydra when a // all scenario hits its max?
+ // all are non-zero?
+ if (!organism->getUMLModel()->readyForHydra()) {
organism->getUMLModel()->setBonusInfo("hydra", bonus);
return 0;
}
- /*if (!ctx.m_task_success_complete) {
- return 0;
- }*/
-
-
+
m_world->GetStats().HydraAttempt();
if (organism->getParentXMI() == temp) {
@@ -3099,10 +3092,10 @@
// Commented out to remove overhead...
-// std::ostringstream strstrm;
-// strstrm << "cp tmp.xmi " << neverclaimFile << "." << m_world->GetStats().GetUpdate() << "." << organism->GetID();
-// strstrm << ".xml";
-// if(system(strstrm.str().c_str())!=0) return 0.0;
+ std::ostringstream strstrm;
+ strstrm << "cp tmp.xmi " << neverclaimFile << "." << m_world->GetStats().GetUpdate() << "." << ctx.getOrganism()->GetID();
+ strstrm << ".xml";
+ if(system(strstrm.str().c_str())!=0) return 0.0;
return 5.0;
}
@@ -3160,10 +3153,7 @@
double bonus = 0.0;
- if ((organism->getUMLModel()->getBonusInfo("scenario1") != 2) ||
- (organism->getUMLModel()->getBonusInfo("scenario3") != 3) ||
-// (organism->getUMLModel()->getBonusInfo("scenario4") != 3) ||
- (organism->getUMLModel()->getBonusInfo("hydra") == 0))
+ if (organism->getUMLModel()->getBonusInfo("hydra") == 0)
{
return bonus;
}
@@ -3219,8 +3209,7 @@
cOrganism* organism = ctx.getOrganism();
double bonus = 0.0;
- if ((organism->getUMLModel()->getBonusInfo("scenario2") != 2) ||
- (organism->getUMLModel()->getBonusInfo("hydra") == 0))
+ if (organism->getUMLModel()->getBonusInfo("hydra") == 0)
{
return bonus;
}
@@ -3265,11 +3254,15 @@
/* if ((organism->getUMLModel()->getBonusInfo("spinw1") == 0) &&
(organism->getUMLModel()->getBonusInfo("spinw2") == 0)) {
return bonus;
- } */
+ }
if ((organism->getUMLModel()->getBonusInfo("scenario5") != 9) ||
(organism->getUMLModel()->getBonusInfo("scenario6") != 4)) {
return bonus;
+ }*/
+ if (organism->getUMLModel()->getBonusInfo("hydra") == 0){
+ return bonus;
}
+
// Ok. Subtract the number of edges from the maximum number of edges seen so far.
mt = mod->getMaxTrans();
Modified: branches/uml/source/main/cUMLModel.cc
===================================================================
--- branches/uml/source/main/cUMLModel.cc 2007-08-09 19:05:07 UTC (rev 1920)
+++ branches/uml/source/main/cUMLModel.cc 2007-08-09 19:55:10 UTC (rev 1921)
@@ -117,6 +117,9 @@
line.erase();
infile >> num_states;
// Read in number of state diagrams
+ } else if (line == "=HYDRA=====================") {
+ line.erase();
+ infile >> hydraMode;
} else if (line == "=STATE-DIAGRAM=============") {
line.erase();
infile >> num_sd;
@@ -260,24 +263,81 @@
return state_diagrams.size();
}
+int cUMLModel::numSCs()
+{
+ return scenarios.size();
+}
+
double cUMLModel::checkForScenarios()
{
double total_bonus = 0;
double temp_bonus = 0;
+ double complete_bonus;
scenario_info s;
// Should check to see if each scenario is satisfied.
// Iterate through list of scnearios; Call each scenario on the appropriate state diagram
// Accrue results.
// Save bonus info.
+ scenario_completion.resize(scenarios.size());
for (unsigned int i=0; i< scenarios.size(); i++) {
s = scenarios[i];
temp_bonus = getStateDiagram(s.stateDiagramID)->findPath(s.path, s.shouldLoop, s.startState);
// std::cout << "TEMP BONUS: " << temp_bonus << std::endl;
total_bonus += temp_bonus;
+
+ complete_bonus = s.path.size() + s.shouldLoop;
+ if (s.startState > 0) complete_bonus++;
+
+ if (temp_bonus == complete_bonus) {
+// bonus_info["scenario"+i] = 1;
+ scenario_completion[i] = 1;
+// std::cout << "scenario complete " << std::endl;
+ } else {
+// bonus_info["scenario"+i] = 0;
+ scenario_completion[i] = 0;
+// std::cout << "scenario incomplete " << std::endl;
+
+ }
}
-
+
return total_bonus;
}
+bool cUMLModel::readyForHydra()
+{
+ // options: (0) ALL_COMPLETE, (1) ONE_COMPLETE, (2) ONE_NON_EMPTY, (3) ALL_NON_EMPTY
+ // check which option was selected in the seed-model.cfg
+ // check to see if this condition is true. If so, return 1; otherwise, return 0.
+
+ bool ret_val = 0;
+// double complete_bonus = 0;
+ switch (hydraMode){
+ case 0:
+ ret_val = 1;
+ for (unsigned int i=0; i< scenario_completion.size(); i++) {
+ //ret_val &= scenario_completion[i];
+ if (scenario_completion[i] != 1) ret_val &= 0;
+ }
+ break;
+ case 1:
+ ret_val = 0;
+ for (unsigned int i=0; i< scenario_completion.size(); i++) {
+ if (scenario_completion[i] == 1) ret_val = 1;
+ }
+ break;
+ case 2:
+ ret_val = 0;
+ break;
+ case 3:
+ ret_val = 0;
+ break;
+ default:
+ ret_val = 0;
+ }
+
+ return ret_val;
+}
+
+
Modified: branches/uml/source/main/cUMLModel.h
===================================================================
--- branches/uml/source/main/cUMLModel.h 2007-08-09 19:05:07 UTC (rev 1920)
+++ branches/uml/source/main/cUMLModel.h 2007-08-09 19:55:10 UTC (rev 1921)
@@ -51,6 +51,8 @@
// Set and access the bonus info for a model. Should be used by the tasks
void setBonusInfo (std::string s, float f) { bonus_info[s] = f; }
float getBonusInfo (std::string);
+ std::vector<double> getScenarioCompletion() { return scenario_completion; }
+ void setScenarioCompletion(std::vector<double> s) { scenario_completion = s; }
// Get the number of, well, everything
int numStates();
@@ -59,7 +61,10 @@
int numGuards();
int numActions();
int numSDs();
+ int numSCs();
+ // check if the model is ready for hydra
+ bool readyForHydra();
protected:
static xmi_info xi;
@@ -68,7 +73,8 @@
std::vector<cUMLStateDiagram> state_diagrams;
std::map<std::string, float> bonus_info;
std::vector<scenario_info> scenarios;
-
+ std::vector<double> scenario_completion;
+ int hydraMode;
};
Modified: branches/uml/source/main/cUMLStateDiagram.cc
===================================================================
--- branches/uml/source/main/cUMLStateDiagram.cc 2007-08-09 19:05:07 UTC (rev 1920)
+++ branches/uml/source/main/cUMLStateDiagram.cc 2007-08-09 19:55:10 UTC (rev 1921)
@@ -38,6 +38,7 @@
int num_vert = num_vertices(sd0);
std::deque<std::string> p_temp = p;
int actual_path_start;
+ int bonus = 0;
// Entire path must start at state 0.
// len = checkForPathStep(p, vertex(0, sd0), 0);
@@ -64,18 +65,23 @@
//}
-
+ bonus = path_dist;
if (start_state != -1) {
if (start_state == actual_path_start) {
- path_dist += 1;
+ bonus += 1;
}
}
+ if (should_loop == 1 && (path_dist == p_temp.size())) {
+ int y = getEndState(p_temp, actual_path_start);
+ if (actual_end_state == actual_path_start) bonus +=1;
+ }
- return path_dist;
+ return bonus;
}
+
int cUMLStateDiagram::checkForPathStep(std::deque<std::string> path,
boost::graph_traits<state_diagram>::vertex_descriptor v,
int curr_dist) {
@@ -126,9 +132,53 @@
}
+// Given a path and a start state, check if the end state is the same as the start state.
+int cUMLStateDiagram::getEndState(std::deque<std::string> path,
+ boost::graph_traits<state_diagram>::vertex_descriptor v) {
+
+ boost::graph_traits<state_diagram>::out_edge_iterator out_edge_start, out_edge_end;
+ boost::graph_traits<state_diagram>::edge_descriptor ed;
+ std::string tt, tg, ta, ts;
+ int temp;
+
+ if (path.empty()) {
+ actual_end_state = v;
+ return v;
+ }
+ // Get the outgoing edges of v
+ for(tie(out_edge_start, out_edge_end) = out_edges(v, sd0);
+ out_edge_start != out_edge_end; ++out_edge_start) {
+ ed = *out_edge_start;
+
+ // Get the label of the edge
+ tt = triggers[(sd0[ed]._tr)].operation_id;
+ tg = guards[(sd0[ed]._gu)];
+ ta = actions[(sd0[ed]._act)];
+
+ // eliminate nulls
+ if (tt == "<null>") tt = "";
+ if (tg == "<null>") tg = "";
+ if (ta == "<null>") ta = "";
+
+ ts = tt + "[" + tg + "]" + "/" + ta;
+// std::cout << "transition named: " << ts << std::endl;
+
+
+ if (ts == path.front()) {
+ //std::cout << "Searching vertex " << target(ed, sd0) << "with distance " << curr_dist+1 << std::endl;
+ temp = getEndState(std::deque<std::string>(++path.begin(), path.end()), target(ed,sd0));
+ }
+ }
+
+ //std::cout << "Returning longest_dist " << longest_dist << std::endl;
+ return v;
+}
+
+
+
bool cUMLStateDiagram::findTrans(int origin, int destination, int trig, int gu, int act)
{
@@ -466,7 +516,7 @@
return o.str();
}
-void cUMLStateDiagram::executeVisitor() {
+/*void cUMLStateDiagram::executeVisitor() {
PathVisitor visitor;
boost::graph_traits<state_diagram>::vertex_descriptor o_temp;
@@ -493,7 +543,7 @@
boost::write_graphviz(outfile, sd0); //, transition_writer(sd0)); //, topo_vertex_writer(_topo_last_network));
outfile.close();
-}
+}*/
std::string cUMLStateDiagram::getXMI(std::string name)
{
Modified: branches/uml/source/main/cUMLStateDiagram.h
===================================================================
--- branches/uml/source/main/cUMLStateDiagram.h 2007-08-09 19:05:07 UTC (rev 1920)
+++ branches/uml/source/main/cUMLStateDiagram.h 2007-08-09 19:55:10 UTC (rev 1921)
@@ -91,7 +91,7 @@
// pass in the path; state to know path step; examine_edge
// Issue: the need to revisit the same node.
//! A BGL breadth-first visitor used to see if a path is included in a state diagram.
-class PathVisitor : public boost::bfs_visitor< > {
+/*class PathVisitor : public boost::bfs_visitor< > {
public:
PathVisitor() {}
template <class state_diagram>
@@ -116,8 +116,8 @@
state_diagram& _sd;
};
+ */
-
// The jump functions jump the index of the various vectors either forward (+ int) or backwards (- int)
bool absoluteJumpGuard(int);
bool absoluteJumpAction(int);
@@ -131,6 +131,7 @@
int findPath(std::deque<std::string>, bool, int);
int checkForPathStep(std::deque<std::string>,
boost::graph_traits<state_diagram>::vertex_descriptor, int);
+ int getEndState (std::deque<std::string>, boost::graph_traits<state_diagram>::vertex_descriptor);
// The get functions get the value of the index of various vectors
@@ -140,8 +141,8 @@
transition_label getTransLabel();
// Visit graph
- void executeVisitor();
- void printGraphViz();
+// void executeVisitor();
+// void printGraphViz();
// Add functions
@@ -158,6 +159,7 @@
state_diagram sd0;
boost::graph_traits<state_diagram>::vertex_descriptor orig;
boost::graph_traits<state_diagram>::vertex_descriptor dest;
+ int actual_end_state;
};
More information about the Avida-cvs
mailing list