[Avida-SVN] r1783 - in branches/uml: Avida.xcodeproj source/main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Tue Jul 10 14:26:49 PDT 2007
Author: hjg
Date: 2007-07-10 17:26:48 -0400 (Tue, 10 Jul 2007)
New Revision: 1783
Modified:
branches/uml/Avida.xcodeproj/project.pbxproj
branches/uml/source/main/cBirthChamber.cc
branches/uml/source/main/cOrganism.cc
branches/uml/source/main/cOrganism.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:
bug fix
Modified: branches/uml/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/uml/Avida.xcodeproj/project.pbxproj 2007-07-10 21:13:31 UTC (rev 1782)
+++ branches/uml/Avida.xcodeproj/project.pbxproj 2007-07-10 21:26:48 UTC (rev 1783)
@@ -2708,7 +2708,7 @@
70B393DF0944CA6F0018F09D /* Profile */,
);
defaultConfigurationIsVisible = 0;
- defaultConfigurationName = "Deployment-G4";
+ defaultConfigurationName = Development;
};
702442D20859E0B00059BD9B /* Build configuration list for PBXNativeTarget "avida" */ = {
isa = XCConfigurationList;
@@ -2720,7 +2720,7 @@
70B393DD0944CA6F0018F09D /* Profile */,
);
defaultConfigurationIsVisible = 0;
- defaultConfigurationName = "Deployment-G4";
+ defaultConfigurationName = Development;
};
702442D70859E0B00059BD9B /* Build configuration list for PBXProject "Avida" */ = {
isa = XCConfigurationList;
@@ -2732,7 +2732,7 @@
70B393E10944CA6F0018F09D /* Profile */,
);
defaultConfigurationIsVisible = 0;
- defaultConfigurationName = "Deployment-G4";
+ defaultConfigurationName = Development;
};
70AA942509D48715006A24C8 /* Build configuration list for PBXNativeTarget "tcmalloc" */ = {
isa = XCConfigurationList;
@@ -2744,7 +2744,7 @@
70AA942909D48715006A24C8 /* Profile */,
);
defaultConfigurationIsVisible = 0;
- defaultConfigurationName = "Deployment-G4";
+ defaultConfigurationName = Development;
};
70B651570BEA700B002472ED /* Build configuration list for PBXNativeTarget "unit-tests" */ = {
isa = XCConfigurationList;
@@ -2756,7 +2756,7 @@
70B6515C0BEA700B002472ED /* Profile */,
);
defaultConfigurationIsVisible = 0;
- defaultConfigurationName = "Deployment-G4";
+ defaultConfigurationName = Development;
};
70DCAD17097AF7CC002F8733 /* Build configuration list for PBXNativeTarget "avida-s" */ = {
isa = XCConfigurationList;
@@ -2768,7 +2768,7 @@
70DCAD1B097AF7CC002F8733 /* Profile */,
);
defaultConfigurationIsVisible = 0;
- defaultConfigurationName = "Deployment-G4";
+ defaultConfigurationName = Development;
};
/* End XCConfigurationList section */
};
Modified: branches/uml/source/main/cBirthChamber.cc
===================================================================
--- branches/uml/source/main/cBirthChamber.cc 2007-07-10 21:13:31 UTC (rev 1782)
+++ branches/uml/source/main/cBirthChamber.cc 2007-07-10 21:26:48 UTC (rev 1783)
@@ -166,7 +166,9 @@
child_genotype->IncDeferAdjust();
// FOR UML branch - hjg
-// child_array[0]->setParentModel(parent.getUMLModel());
+ child_array[0]->setParentXMI(parent.getUMLModel()->getXMI());
+ child_array[0]->setParentBonus(parent.getParentBonus());
+
return true;
}
Modified: branches/uml/source/main/cOrganism.cc
===================================================================
--- branches/uml/source/main/cOrganism.cc 2007-07-10 21:13:31 UTC (rev 1782)
+++ branches/uml/source/main/cOrganism.cc 2007-07-10 21:26:48 UTC (rev 1783)
@@ -96,8 +96,8 @@
m_guard_index = 0;
m_action_index = 0;*/
m_model.seedDiagrams();
+ m_parent_xmi = "";
-
}
@@ -575,11 +575,8 @@
void cOrganism::modelCheck(cAvidaContext& ctx)
{
if(GetCellID()==-1) return;
+ m_model.printXMI();
-
-// printStats();
-
-
assert(m_interface);
const tArray<double> & resource_count = m_interface->GetResources();
Modified: branches/uml/source/main/cOrganism.h
===================================================================
--- branches/uml/source/main/cOrganism.h 2007-07-10 21:13:31 UTC (rev 1782)
+++ branches/uml/source/main/cOrganism.h 2007-07-10 21:26:48 UTC (rev 1783)
@@ -148,9 +148,11 @@
int m_trigger_index;
int m_guard_index;
int m_action_index;*/
- cUMLModel m_model; // Used when not running as deme
-// cUMLModel* m_parent_model; // Used when not running as deme
+ cUMLModel m_model;
+ std::string m_parent_xmi;
+ std::map<std::string, float> m_parent_bonus;
+
class cNetSupport
{
public:
@@ -311,6 +313,7 @@
void modelCheck(cAvidaContext& ctx);
cUMLModel* getUMLModel();
// cUMLModel* getParentUMLModel() { return m_parent_model; }
+ std::string getParentXMI() { return m_parent_xmi; }
int getStateDiagramIndex() { return m_state_diag; }
// bool lastStateDiagram () { m_state_diag = getUMLModel()->getStateDiagramSize(); }
// bool firstStateDiagram() { m_state_diag = 0; }
@@ -318,6 +321,10 @@
cUMLStateDiagram* getStateDiagram();
// void printStats();
// void setParentModel(cUMLModel* m) { m_parent_model = m; }
+ void setParentXMI(std::string s) { m_parent_xmi = s; }
+ 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; }
Modified: branches/uml/source/main/cTaskLib.cc
===================================================================
--- branches/uml/source/main/cTaskLib.cc 2007-07-10 21:13:31 UTC (rev 1782)
+++ branches/uml/source/main/cTaskLib.cc 2007-07-10 21:26:48 UTC (rev 1783)
@@ -2832,7 +2832,6 @@
ctx.task_success_complete = ctx.task_success_complete && bonus;
return bonus;
-
}
double cTaskLib::Task_Scenario1(cTaskContext& ctx) const
@@ -2840,16 +2839,27 @@
double bonus = 0.0;
std::deque<std::string> path1;
+ // Check if the tasks are complete so far...
+ // This provides a basic ordering mechanism for the tasks.
if (!ctx.task_success_complete) {
return 0;
}
- // create the scenario
- path1.push_back("^TempSensor.getOpState()");
- path1.push_back("setTempOpState");
+ // Check if this model is different than the organism's parent's model
+ if (ctx.organism->getParentXMI() != ctx.organism->getUMLModel()->getXMI()) {
+
+ // create the scenario
+ path1.push_back("^TempSensor.getOpState()");
+ path1.push_back("setTempOpState");
- // check for scneario
- bonus = ctx.organism->getUMLModel()->getStateDiagram(1)->findPath(path1);
+ // check for scneario
+ bonus = ((ctx.organism->getUMLModel()->getStateDiagram(1)->findPath(path1)) / path1.size());
+ } else {
+ bonus = ctx.organism->getParentBonus("scenario1");
+ }
+
+ // Set bonus info for current model
+ ctx.organism->getUMLModel()->setBonusInfo("scenario1", bonus);
if (bonus == 1) {
ctx.task_success_complete = true;
@@ -2889,29 +2899,27 @@
{
cOrganism* organism = ctx.organism;
std::string temp;
+ double bonus = 0.0;
+
temp = organism->getUMLModel()->getXMI();
-/*
- if (temp == organism->getParentXMI()) {
- ctx.task_success_complete += organism->getParentBonusInfo("hydra");
- organism->setBonusInfo("hydra", organism->getParentBonusInfo("hydra"));
- return organism->getParentBonusInfo("hydra");
- }
- */
-
-// Check for task success...
-
-
+
if (!ctx.task_success_complete) {
return 0;
- }
+ }
+
+ m_world->GetStats().HydraAttempt();
+ if (ctx.organism->getParentXMI() == temp) {
+ bonus = ctx.organism->getParentBonus("hydra");
+ if (bonus) ctx.task_success_complete = true;
+ ctx.organism->getUMLModel()->setBonusInfo("hydra", bonus);
+ return bonus;
+ }
- m_world->GetStats().HydraAttempt();
- double bonus = 0.0;
unsigned int status_total = 0;
int status=0;
@@ -2975,16 +2983,17 @@
if(status != 0) {
// organism->setBonusInfo("hydra", 0.0);
ctx.task_success_complete = false;
-
- return 0.0;
+ bonus = 0.0;
} else {
m_world->GetStats().HydraPassed();
// organism->setBonusInfo("hydra", 1.0);
ctx.task_success_complete = true;
-
- return 1.0;
+ bonus = 1.0;
}
+ ctx.organism->getUMLModel()->setBonusInfo("hydra", bonus);
+ return bonus;
+
}
@@ -3053,39 +3062,54 @@
}
double cTaskLib::Task_SpinN1(cTaskContext& ctx) const {
- cOrganism* organism = ctx.organism;
- double temp1 = 0.0;
+ //cOrganism* organism = ctx.organism;
+ double bonus = 0.0;
-/* if (temp == organism->getParentXMI()) {
- ctx.task_success_complete += organism->getParentBonusInfo("spinn1");
- organism->setBonusInfo("spinn1", organism->getParentBonusInfo("spinn1"));
- return organism->getParentBonusInfo("spinn1");
+ if (!ctx.task_success_complete) return bonus;
+
+ if (ctx.organism->getParentXMI() == ctx.organism->getUMLModel()->getXMI()) {
+
+ bonus = ctx.organism->getParentBonus("spinn1");
+// return bonus;
+ } else {
+
+ bonus = SpinCoprocess(ctx, "N1");
}
-*/
- // check if the trigger is present
- if (ctx.task_success_complete) {
- // checkproperty
- temp1 += SpinCoprocess(ctx, "N1");
+ if (bonus) {
+ ctx.task_success_complete = true;
+ } else {
+ ctx.task_success_complete = false;
}
-
-// organism->setBonusInfo("spinn1", temp1);
- return temp1;
+ ctx.organism->getUMLModel()->setBonusInfo("spinn1", bonus);
+
+ return bonus;
}
double cTaskLib::Task_SpinW1(cTaskContext& ctx) const {
- cOrganism* organism = ctx.organism;
- double temp1 = 0.0;
+// cOrganism* organism = ctx.organism;
+// double temp1 = 0.0;
+ double bonus = 0.0;
+ if (!ctx.task_success_complete) return bonus;
- // check property
- if (ctx.task_success_complete) {
- temp1 += SpinWitnessCoprocess(ctx, "W1");
- }
+ if (ctx.organism->getParentXMI() == ctx.organism->getUMLModel()->getXMI()) {
+ bonus = ctx.organism->getParentBonus("spinw1");
+// return bonus;
+ } else {
- return temp1;
+ bonus = SpinWitnessCoprocess(ctx, "W1");
+ }
+
+ if (bonus) {
+ ctx.task_success_complete = true;
+ } else {
+ ctx.task_success_complete = false;
+ }
+ ctx.organism->getUMLModel()->setBonusInfo("spinw1", bonus);
+ return bonus;
}
double cTaskLib::Task_MultTrans(cTaskContext& ctx) const {
Modified: branches/uml/source/main/cUMLModel.cc
===================================================================
--- branches/uml/source/main/cUMLModel.cc 2007-07-10 21:13:31 UTC (rev 1782)
+++ branches/uml/source/main/cUMLModel.cc 2007-07-10 21:26:48 UTC (rev 1783)
@@ -137,6 +137,7 @@
// xmi += xmi_class1;
// xmi += state_diagrams[0].getXMI();
// xmi += xmi_class2;
+// state_diagrams[1].printXMI();
xmi += state_diagrams[1].getXMI();
xmi += xmi_end;
@@ -145,7 +146,7 @@
std::string cUMLModel::getXMI()
{
- printXMI();
+// printXMI();
return xmi;
}
Modified: branches/uml/source/main/cUMLModel.h
===================================================================
--- branches/uml/source/main/cUMLModel.h 2007-07-10 21:13:31 UTC (rev 1782)
+++ branches/uml/source/main/cUMLModel.h 2007-07-10 21:26:48 UTC (rev 1783)
@@ -2,8 +2,6 @@
#define _C_UMLMODEL_H_
#include "cUMLStateDiagram.h"
-//#include "cWorld.h"
-//#include "cStats.h"
#include <string>
#include <iostream>
@@ -19,13 +17,22 @@
cUMLModel();
~cUMLModel();
- void seedDiagrams(); // add the building blocks for the diagrams.
+ // Read in from file seed-model.cfg and add the building blocks for the diagrams.
+ void seedDiagrams();
+ // Used to generate and access the XMI version of the model.
std::string getXMI(); // get the XMI version of the model.
void printXMI(); // create the XMI version of the model.
+ // Access the size of the state diagrams and also a specific state diagram
int getStateDiagramSize() { return state_diagrams.size(); }
cUMLStateDiagram* getStateDiagram (int);
+
+ // Set and access the bonus info for a model. Should be used by the tasks
+ bool setBonusInfo (std::string s, float f) { bonus_info[s] = f; }
+ float getBonusInfo (std::string s) { return bonus_info[s]; }
+
+ // Get the number of, well, everything
int numStates();
int numTrans();
int numTriggers();
@@ -36,11 +43,12 @@
protected:
static std::string xmi_begin;
- std::string xmi; // the XMI created by the model
+ std::string xmi;
static std::string xmi_end;
static std::string xmi_class1;
static std::string xmi_class2;
std::vector<cUMLStateDiagram> state_diagrams;
+ std::map<std::string, float> bonus_info;
};
Modified: branches/uml/source/main/cUMLStateDiagram.cc
===================================================================
--- branches/uml/source/main/cUMLStateDiagram.cc 2007-07-10 21:13:31 UTC (rev 1782)
+++ branches/uml/source/main/cUMLStateDiagram.cc 2007-07-10 21:26:48 UTC (rev 1783)
@@ -25,59 +25,59 @@
{
}
-float cUMLStateDiagram::findPath(std::deque<std::string> p) {
- bool res = false;
+
+// This function accepts a path throught the state diagram as a deque and returns the length
+// of the longest path segment that the diagram satisfies.
+// The function is complicated by the fact that the longest path segment could start at the
+// beginning, middle, or end of the path itself AND the path could begin at any reachable vertex.
+int cUMLStateDiagram::findPath(std::deque<std::string> p) {
+ int path_dist = 0; // the current path distance satisfied is 0.
+// int path_total_length = p.size();
+ int path_longest_length = 0;
+ int len = 0;
int num_vert = num_vertices(sd0);
std::deque<std::string> p_temp = p;
- int possible_length = p.size();
- int current_length = 0;
- int len = 0;
- float val;
-
+
+
+
+ // Must start at state 0.
+ // Must check each state.
while (!p.empty()) {
- for (int i = 0; i<num_vert; i++) {
- checkForPath(p_temp, vertex(i, sd0), res, len);
+
+ for (int i = 0; i<num_vert; i++) {
+ len = checkForPathStep(p, vertex(i, sd0), 0);
// check to see if this path is longer than other paths....
- if (len > current_length) {
- current_length = len;
- }
+ if (len > path_dist) {
+ path_dist = len;
+ }
}
- p.pop_front();
- p_temp = p;
- res = false;
- len = 0;
- }
+ p.pop_front();
+
+ if (len > p.size()) break;
+ }
+ return path_dist;
-// std::cout << "Longest path length: " << current_length << std::endl;
-// std::cout << "Possible path length: " << possible_length << std::endl;
- val = current_length / possible_length;
- return (val);
+
}
-
-void cUMLStateDiagram::checkForPath(std::deque<std::string> path,
- boost::graph_traits<state_diagram>::vertex_descriptor v, bool& result,
- int& dist) {
+int cUMLStateDiagram::checkForPathStep(std::deque<std::string> path,
+ boost::graph_traits<state_diagram>::vertex_descriptor v,
+ int curr_dist) {
- // declare temp strings for triggers, guards, and actions
- std::string tt, tg, ta, ts;
-
- // If the path is empty or the result is already true, then
- // return true to indicate that the path has been found.
- if ((path.empty()) || (result == true)) {
- result = true;
- return;
- }
-
- // Get all outgoing edges
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 longest_dist = curr_dist;
+ int temp;
- // Check to see if any have the same label as the first element of path
- // If so, then call this function on them with the tail of the path
+ if (path.empty()) return curr_dist;
+
+ // 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)];
@@ -88,21 +88,25 @@
if (ta == "<null>") ta = "";
ts = tt + tg + ta;
-// std::cout << "Looking for an edge with " << path.front() << std::endl;
-// std::cout << "Found an edge with " << ts << std::endl;
+
if (ts == path.front()) {
-// std::cout << "Found an edge with " << ts << std::endl;
- dist++;
-// path.pop_front();
-// checkForPath(path, target(ed, sd0), result, dist);
- checkForPath(std::deque<std::string>(++path.begin(), path.end()), target(ed,sd0), result, dist);
+ //std::cout << "Looking for and found a path named: " << ts << std::endl;
+ //std::cout << "Searching vertex " << target(ed, sd0) << "with distance " << curr_dist+1 << std::endl;
+ temp = checkForPathStep(std::deque<std::string>(++path.begin(), path.end()), target(ed,sd0), curr_dist+1);
+ if (temp > longest_dist) longest_dist = temp;
}
- }
-}
+ }
+
+ //std::cout << "Returning longest_dist " << longest_dist << std::endl;
+ return longest_dist;
+}
+
+
+
bool cUMLStateDiagram::findTrans(int origin, int destination, int trig, int gu, int act)
{
Modified: branches/uml/source/main/cUMLStateDiagram.h
===================================================================
--- branches/uml/source/main/cUMLStateDiagram.h 2007-07-10 21:13:31 UTC (rev 1782)
+++ branches/uml/source/main/cUMLStateDiagram.h 2007-07-10 21:26:48 UTC (rev 1783)
@@ -129,8 +129,9 @@
// Implement a scenario check.
- void checkForPath(std::deque<std::string>, boost::graph_traits<state_diagram>::vertex_descriptor, bool&, int&);
- float findPath(std::deque<std::string> p);
+// void checkForPath(std::deque<std::string>, boost::graph_traits<state_diagram>::vertex_descriptor, bool&, int&);
+ int findPath(std::deque<std::string> p);
+ int checkForPathStep(std::deque<std::string>, boost::graph_traits<state_diagram>::vertex_descriptor, int);
// The get functions get the value of the index of various vectors
int getTriggerIndex();
More information about the Avida-cvs
mailing list