[Avida-SVN] r1509 - branches/uml/source/main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Sun Apr 29 16:51:53 PDT 2007
Author: hjg
Date: 2007-04-29 19:51:53 -0400 (Sun, 29 Apr 2007)
New Revision: 1509
Modified:
branches/uml/source/main/cBirthChamber.cc
branches/uml/source/main/cOrganism.cc
branches/uml/source/main/cOrganism.h
branches/uml/source/main/cTaskLib.cc
Log:
checkpoint
Modified: branches/uml/source/main/cBirthChamber.cc
===================================================================
--- branches/uml/source/main/cBirthChamber.cc 2007-04-29 21:44:48 UTC (rev 1508)
+++ branches/uml/source/main/cBirthChamber.cc 2007-04-29 23:51:53 UTC (rev 1509)
@@ -152,7 +152,7 @@
child_genotype->IncDeferAdjust();
// FOR UML branch - hjg
- child_array[0]->setParentXMI(parent.getXMI());
+ child_array[0]->setParentInfo(parent.getXMI(), parent.getBonus());
return true;
}
Modified: branches/uml/source/main/cOrganism.cc
===================================================================
--- branches/uml/source/main/cOrganism.cc 2007-04-29 21:44:48 UTC (rev 1508)
+++ branches/uml/source/main/cOrganism.cc 2007-04-29 23:51:53 UTC (rev 1509)
@@ -115,16 +115,16 @@
trig.label = "<null>";
trig.operation_id = "<null>";
triggers.push_back(trig);
- trig.label = "setTempOpState(temp_op_state)";
+ trig.label = "setTempOpState";
trig.operation_id = "XDE-4437EBF1-9C42-4EB4-B7CF-415697B567CD";
triggers.push_back(trig);
- trig.label = "setTempData(temp_data)";
+ trig.label = "setTempData";
trig.operation_id = "XDE-9517D6BA-8666-4A82-AFEA-62D60FE37B07";
triggers.push_back(trig);
guards.push_back("<null>");
actions.push_back("<null>");
- actions.push_back("/^TempSensor.getOpState()");
- actions.push_back("/^TempSensor.getTempData()");
+ actions.push_back("^TempSensor.getOpState()");
+ actions.push_back("^TempSensor.getTempData()");
// initialize w/ 10 states
@@ -156,7 +156,7 @@
states[2].num_incoming += 1;
t.trans.trigger = 0;
t.trans.guard = "<null>";
- t.trans.action = "/^TempSensor.getTempData()";
+ t.trans.action = "^TempSensor.getTempData()";
transitions.push_back(t);
// State 2->1
@@ -164,7 +164,7 @@
t.dest_state = 1;
states[2].num_outgoing += 1;
states[1].num_incoming += 1;
- t.trans.trigger = 1;
+ t.trans.trigger = 2;
t.trans.guard = "<null>";
t.trans.action = "<null>";
transitions.push_back(t);
@@ -592,6 +592,24 @@
return false;
}
+bool cOrganism::findTrans(int orig, int dest, int trig, std::string gu, std::string act)
+{
+ // the wild cards for there are
+ // -1 for orig, dest & trigger
+ // "*" for guard, and action
+
+ for(std::vector<transition>::iterator i=transitions.begin(); i!=transitions.end(); ++i){
+ if (((orig == -1) || (orig == i->orig_state)) &&
+ ((dest == -1) || (dest == i->dest_state)) &&
+ ((trig == -1) || (trig == i->trans.trigger)) &&
+ ((gu == "*") || (gu == i->trans.guard)) &&
+ ((act == "*") || (act == i->trans.action))) {
+ return true;
+ }
+ }
+ return false;
+}
+/*
bool cOrganism::findTrans(int orig, int dest)
{
for(std::vector<transition>::iterator i=transitions.begin(); i!=transitions.end(); ++i){
@@ -632,26 +650,11 @@
return false;
}
+*/
template <typename T>
bool cOrganism::absoluteMoveIndex (T x, int &index, int amount )
{
-/* if (x.size() == 0) {
- return false;
- }
-
- if (amount > 0) {
-// index += (amount % x.size()); // this provides relative jumping
- index = (amount % x.size());
-
- // index is greater than vector
- if (index >= x.size()) {
- index -= x.size();
- } else if(index < 0) {
- index += x.size();
- }
- }
- */
index = 0;
return relativeMoveIndex(x, index, amount);
}
@@ -782,16 +785,8 @@
return transition_labels[trans_label_index];
}
-// State manipulation - currently not used.
bool cOrganism::addState()
-{
-/* if (states.size() < 11) {
- states.push_back(states.size());
- dest_state_index = states.size() - 1;
- } else {
- return false;
- }*/
-
+{
state s;
s.identifier = states.size();
s.num_incoming = 0;
@@ -803,7 +798,6 @@
bool cOrganism::addTransitionLabel()
{
-
transition_label t;
t.trigger = getTriggerIndex();
t.guard = getGuard();
@@ -840,7 +834,7 @@
t.trans = getTransLabel();
// no dupes
- if (findTrans(t)) {
+ if (findTrans(t.orig_state, t.dest_state, t.trans.trigger, t.trans.guard, t.trans.action)) {
return false;
}
@@ -864,7 +858,7 @@
// Do not create transition if the origin state is unreachable.
- if (states[getOrigStateIndex()].num_incoming == 0) {
+ if ((t.orig_state != 0) && (states[t.orig_state].num_incoming == 0)) {
return false;
}
@@ -881,7 +875,7 @@
// no dupes
- if (findTrans(t)) {
+ if (findTrans(t.orig_state, t.dest_state, t.trans.trigger, t.trans.guard, t.trans.action)) {
return false;
}
Modified: branches/uml/source/main/cOrganism.h
===================================================================
--- branches/uml/source/main/cOrganism.h 2007-04-29 21:44:48 UTC (rev 1508)
+++ branches/uml/source/main/cOrganism.h 2007-04-29 23:51:53 UTC (rev 1509)
@@ -148,8 +148,11 @@
static std::string xmi_begin; // what comes before the organism generated xmi
std::string xmi; // the xmi created by pretty-printing the diagram generated by the organism
static std::string xmi_end; // what comes after the organism generated xmi
+
std::string parent_xmi;
-
+ std::map <std::string, double> parent_bonus;
+ std::map <std::string, double> self_bonus;
+
std::vector<state> states;
std::vector<trigger_info> triggers;
std::vector<std::string> guards;
@@ -239,12 +242,23 @@
int numStates();
int numTrans();
void seedModel();
- void setParentXMI(std::string x) {parent_xmi = x;}
+ // UML parent information tracking
+ void setParentInfo(std::string x, std::map <std::string, double> pb) {parent_xmi = x; parent_bonus = pb;}
+// void setParentHyBonus (double y) {parent_hy_bonus = y;}
+// void setParentSp1Bonus (double y) {parent_sp1_bonus = y;}
+ double getParentBonusInfo(std::string x) {return parent_bonus[x];}
+ std::map <std::string, double> getBonus() {return self_bonus;}
+ void setBonusInfo(std::string x, double y) {self_bonus[x] = y;}
+ //double getParentSp1Bonus() {return parent_sp1_bonus;}
+ //void addBonus (double y) {bonus += y;}
+ //double getBonus () {return bonus;}
+
// find functions
- bool findTrans(int, int); // find a transition between two states
- bool findTrans(int, int, std::string); // find a transition between two states with a specific label.
- bool findTrans(transition); // find a transition between two states with a specific label.
+// bool findTrans(int, int); // find a transition between two states
+// bool findTrans(int, int, std::string); // find a transition between two states with a specific label.
+// bool findTrans(transition); // find a transition between two states with a specific label.
+ bool findTrans(int, int, int, std::string, std::string) ;
bool findTransLabel(transition_label); // find a specific transition label
template <typename T>
Modified: branches/uml/source/main/cTaskLib.cc
===================================================================
--- branches/uml/source/main/cTaskLib.cc 2007-04-29 21:44:48 UTC (rev 1508)
+++ branches/uml/source/main/cTaskLib.cc 2007-04-29 23:51:53 UTC (rev 1509)
@@ -1856,10 +1856,11 @@
return 0.0;
}
+
double cTaskLib::Task_Trans1(cTaskContext* ctx) const
{
double bonus = 0.0;
- if (ctx->organism->findTrans(0,1, "tagaaa")) {
+ if (ctx->organism->findTrans(0,1,1, "ga", "aa")) {
ctx->task_success_complete = 1;
bonus = 1.0;
}
@@ -1871,7 +1872,7 @@
double cTaskLib::Task_Trans2(cTaskContext* ctx) const
{
double bonus = 0.0;
- if (ctx->organism->findTrans(1,2, "tagdab")){
+ if (ctx->organism->findTrans(1,2,1,"gd", "ab")){
ctx->task_success_complete += 1;
bonus = 1.0;
}
@@ -1883,7 +1884,7 @@
double cTaskLib::Task_Trans3(cTaskContext* ctx) const
{
double bonus = 0.0;
- if (ctx->organism->findTrans(2,3, "tcgbac")){
+ if (ctx->organism->findTrans(2,3,3,"gb", "ac")){
bonus = 1.0;
ctx->task_success_complete += 1;
}
@@ -1895,7 +1896,7 @@
double cTaskLib::Task_Trans4(cTaskContext* ctx) const
{
double bonus = 0.0;
- if (ctx->organism->findTrans(3,4, "tbgcad")){
+ if (ctx->organism->findTrans(3,4,2,"gc", "ad")){
ctx->task_success_complete += 1;
bonus = 1.0;
}
@@ -1907,7 +1908,7 @@
double cTaskLib::Task_Trans5(cTaskContext* ctx) const
{
double bonus = 0.0;
- if (ctx->organism->findTrans(4,0, "tdgaac")){
+ if (ctx->organism->findTrans(4,0,4,"ga","ac")){
ctx->task_success_complete += 1;
bonus = 1.0;
}
@@ -1949,7 +1950,9 @@
temp = organism->getXMI();
if (temp == organism->getParentXMI()) {
- return 0;
+ ctx->task_success_complete += organism->getParentBonusInfo("hydra");
+ organism->setBonusInfo("hydra", organism->getParentBonusInfo("hydra"));
+ return organism->getParentBonusInfo("hydra");
}
// Check for task success...
@@ -2022,11 +2025,13 @@
// if there are no errors, return 0 from hydraulic. otherwise, return non-zero.
if(status != 0) {
// ctx->task_failed = 0;
+ organism->setBonusInfo("hydra", 0.0);
return 0.0;
} else {
// ctx->task_failed = ctx->task_failed && 1;
ctx->task_success_complete += 1;
m_world->GetStats().HydraPassed();
+ organism->setBonusInfo("hydra", 1.0);
return 1.0;
}
@@ -2045,7 +2050,9 @@
if(system("/usr/bin/gcc -DMEMLIM=512 pan.c -o pan &> /dev/null")!=0) return 0.0;
if(system("./pan -a &> ./pan.out")!=0) return 0.0;
if(system("cat pan.out | perl -e 'while(<STDIN>) { if(/errors:\\s(\\d+)/) {exit($1);}}'")!=0) return 0.0;
+ if(system("cat pan.out | perl -e 'while(<STDIN>) { if(/unreached/) {exit(1);}}'")!=0) return 0.0;
+
std::ostringstream strstrm;
strstrm << "cp tmp.xmi " << m_world->GetStats().GetUpdate() << "." << organism->GetID();
strstrm << ".xml";
@@ -2056,10 +2063,28 @@
}
double cTaskLib::Task_SpinN1(cTaskContext* ctx) const {
- if (ctx->task_success_complete) {
- return SpinCoprocess(ctx, "N1");
- }
- return 0.0;
+ cOrganism* organism = ctx->organism;
+ std::string temp = organism->getXMI();
+ double temp1 = 0.0;
+
+ if (temp == organism->getParentXMI()) {
+ ctx->task_success_complete += organism->getParentBonusInfo("spinn1");
+ organism->setBonusInfo("spinn1", organism->getParentBonusInfo("spinn1"));
+ return organism->getParentBonusInfo("spinn1");
+ }
+
+ // check if the trigger is present
+ if (organism->findTrans(-1,-1,1,"*","*")){
+ temp += 1;
+
+ // check property
+ if (ctx->task_success_complete) {
+ temp1 += SpinCoprocess(ctx, "N1");
+ }
+ }
+
+ organism->setBonusInfo("spinn1", temp1);
+ return temp1;
}
double cTaskLib::Task_MultTrans(cTaskContext* ctx) const {
More information about the Avida-cvs
mailing list