[Avida-SVN] r1491 - branches/uml/source/main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Thu Apr 19 08:01:01 PDT 2007
Author: hjg
Date: 2007-04-19 11:01:01 -0400 (Thu, 19 Apr 2007)
New Revision: 1491
Modified:
branches/uml/source/main/cBirthChamber.cc
branches/uml/source/main/cOrganism.cc
branches/uml/source/main/cOrganism.h
branches/uml/source/main/cPopulation.h
branches/uml/source/main/cTaskLib.cc
Log:
- Added Hydra & Spin back in
- Prior to running Hydra or Spin, the organism's model is checked to see if it is different than its parent's model. This *should* help performance a bit.
Modified: branches/uml/source/main/cBirthChamber.cc
===================================================================
--- branches/uml/source/main/cBirthChamber.cc 2007-04-19 13:26:37 UTC (rev 1490)
+++ branches/uml/source/main/cBirthChamber.cc 2007-04-19 15:01:01 UTC (rev 1491)
@@ -133,6 +133,7 @@
// This is asexual who doesn't need to wait in the birth chamber
// just build the child and return.
child_array.Resize(1);
+// child_array[0] = new cOrganism(m_world, ctx, child_genome);
child_array[0] = new cOrganism(m_world, ctx, child_genome);
merit_array.Resize(1);
merit_array[0] = parent.GetPhenotype().GetMerit();
@@ -149,6 +150,9 @@
parent.GetGenotype()->SetBreedStats(*child_genotype);
child_genotype->IncDeferAdjust();
+
+ // FOR UML branch - hjg
+ child_array[0]->setParentXMI(parent.getXMI());
return true;
}
Modified: branches/uml/source/main/cOrganism.cc
===================================================================
--- branches/uml/source/main/cOrganism.cc 2007-04-19 13:26:37 UTC (rev 1490)
+++ branches/uml/source/main/cOrganism.cc 2007-04-19 15:01:01 UTC (rev 1491)
@@ -81,6 +81,7 @@
, m_net(NULL)
, received_messages(RECEIVED_MESSAGES_SIZE)
, is_running(false)
+ , parent_xmi("")
{
// Initialization of structures...
m_hardware = m_world->GetHardwareManager().Create(this);
@@ -110,32 +111,65 @@
AddTrans(3,3,1);
*/
- // initialize the iterators to point to the first element
- triggers.push_back("ta");
- triggers.push_back("tb");
- triggers.push_back("tc");
- triggers.push_back("td");
- guards.push_back("ga");
- guards.push_back("gb");
- guards.push_back("gc");
- guards.push_back("gd");
- actions.push_back("aa");
- actions.push_back("ab");
- actions.push_back("ac");
- actions.push_back("ad");
+ trigger_info trig;
+ trig.label = "<null>";
+ trig.operation_id = "<null>";
+ triggers.push_back(trig);
+ trig.label = "setTempOpState(temp_op_state)";
+ trig.operation_id = "XDE-4437EBF1-9C42-4EB4-B7CF-415697B567CD";
+ triggers.push_back(trig);
+ trig.label = "setTempData(temp_data)";
+ 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()");
// initialize w/ 10 states
- states.push_back(states.size());
- states.push_back(states.size());
- states.push_back(states.size());
- states.push_back(states.size());
- states.push_back(states.size());
- states.push_back(states.size());
- states.push_back(states.size());
- states.push_back(states.size());
- states.push_back(states.size());
- states.push_back(states.size());
+ state s;
+ for (int i=0; i<11; i++) {
+ s.identifier = i;
+ s.num_incoming = 0;
+ s.num_outgoing = 0;
+ states.push_back(s);
+ }
+
+ // initialize transitions
+ transition t;
+
+ // State 0->1
+ t.orig_state = 0;
+ t.dest_state = 1;
+ states[0].num_outgoing += 1;
+ states[1].num_incoming += 1;
+ t.trans.trigger = 0;
+ t.trans.guard = "<null>";
+ t.trans.action = "<null>";
+ transitions.push_back(t);
+
+ // State 1->2
+ t.orig_state = 1;
+ t.dest_state = 2;
+ states[1].num_outgoing += 1;
+ states[2].num_incoming += 1;
+ t.trans.trigger = 0;
+ t.trans.guard = "<null>";
+ t.trans.action = "/^TempSensor.getTempData()";
+ transitions.push_back(t);
+
+ // State 2->1
+ t.orig_state = 2;
+ t.dest_state = 1;
+ states[2].num_outgoing += 1;
+ states[1].num_incoming += 1;
+ t.trans.trigger = 1;
+ t.trans.guard = "<null>";
+ t.trans.action = "<null>";
+ transitions.push_back(t);
+
+ // initialize the iterators to point to the first element
trigger_index = 0;
action_index = 0;
guard_index = 0;
@@ -144,7 +178,6 @@
dest_state_index = 9;
}
-
cOrganism::~cOrganism()
{
assert(is_running == false);
@@ -469,7 +502,7 @@
void cOrganism::modelCheck(cAvidaContext& ctx)
{
- printXMI();
+ printXMI();
assert(m_interface);
@@ -576,7 +609,7 @@
std::string t_lab;
for(std::vector<transition>::iterator i=transitions.begin(); i!=transitions.end(); ++i){
if((i->orig_state == orig) && (i->dest_state == dest)) {
- t_lab = (i->trans.trigger + i->trans.guard + i->trans.action);
+ t_lab = (StringifyAnInt(i->trans.trigger) + i->trans.guard + i->trans.action);
if (t_lab == label) {
return true;
}
@@ -706,13 +739,14 @@
return relativeMoveIndex(states, dest_state_index, jump_amount);
}
-std::string cOrganism::getTrigger()
+int cOrganism::getTriggerIndex()
{
- if (triggers.size() == 0) {
- return "";
- } else {
- return triggers[trigger_index];
- }
+ /*if (triggers.size() == 0) {
+ return 0;
+ } else {*/
+
+ return trigger_index;
+ //}
}
std::string cOrganism::getGuard()
@@ -733,12 +767,12 @@
}
}
-int cOrganism::getOrigState()
+int cOrganism::getOrigStateIndex()
{
return orig_state_index;
}
-int cOrganism::getDestState()
+int cOrganism::getDestStateIndex()
{
return dest_state_index;
}
@@ -748,16 +782,22 @@
return transition_labels[trans_label_index];
}
-// State manipulation
+// State manipulation - currently not used.
bool cOrganism::addState()
{
- if (states.size() < 11) {
+/* 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;
+ s.num_outgoing = 0;
+ states.push_back(s);
+
return true;
}
@@ -765,7 +805,7 @@
{
transition_label t;
- t.trigger = getTrigger();
+ t.trigger = getTriggerIndex();
t.guard = getGuard();
t.action = getAction();
@@ -791,8 +831,12 @@
}
transition t;
- t.orig_state = getOrigState();
- t.dest_state = getDestState();
+ t.orig_state = getOrigStateIndex();
+ t.dest_state = getDestStateIndex();
+ // increment number of edges for a state
+ states[getOrigStateIndex()].num_outgoing += 1;
+ states[getDestStateIndex()].num_incoming += 1;
+
t.trans = getTransLabel();
// no dupes
@@ -815,11 +859,22 @@
}
transition t;
- t.orig_state = getOrigState();
- t.dest_state = getDestState();
+ t.orig_state = getOrigStateIndex();
+ t.dest_state = getDestStateIndex();
+
+ // Do not create transition if the origin state is unreachable.
+ if (states[getOrigStateIndex()].num_incoming == 0) {
+ return false;
+ }
+
+ // increment number of edges for a state
+ states[getOrigStateIndex()].num_outgoing += 1;
+ states[getDestStateIndex()].num_incoming += 1;
+
+
transition_label tl;
- tl.trigger = getTrigger();
+ tl.trigger = getTriggerIndex();
tl.guard = getGuard();
tl.action = getAction();
t.trans = tl;
@@ -875,12 +930,15 @@
void cOrganism::printXMI()
{
- std::string temp, temp1, temp2;
+ std::string temp, temp1, temp2, temp3;
+ std::string trig_label, trig_op_label;
int s_count = 0;
int t_count = 0;
xmi = "";
+ // This state is the initial state; thus it should be printed regardless of whether it has an incoming
+ // edge or not.
if (numStates() > 0) {
temp = StringifyAnInt(s_count);
xmi += "<UML:Pseudostate xmi.id=\"s" + temp + "\" kind=\"initial\" outgoing=\"\" name=\"s";
@@ -888,15 +946,18 @@
++s_count;
}
+ for (; s_count < numStates(); ++s_count) {
- for (; s_count < numStates(); ++s_count) {
- temp = "s" + StringifyAnInt(s_count);
- xmi+="<UML:CompositeState xmi.id=\"";
- xmi+=temp;
- xmi+= "\" isConcurrent=\"false\" name=\"";
- xmi+= temp;
- xmi+= "\" isSpecification=\"false\"/>\n";
+ // only print if this state has an incoming edge.
+ if ((states[s_count]).num_incoming > 0) {
+ temp = "s" + StringifyAnInt(s_count);
+ xmi+="<UML:CompositeState xmi.id=\"";
+ xmi+=temp;
+ xmi+= "\" isConcurrent=\"false\" name=\"";
+ xmi+= temp;
+ xmi+= "\" isSpecification=\"false\"/>\n";
}
+ }
// end the set of states....
xmi+= "</UML:CompositeState.subvertex>\n";
@@ -913,39 +974,43 @@
temp = "t" + StringifyAnInt(t_count);
temp1 = "s" + StringifyAnInt(transitions[t_count].orig_state);
temp2 = "s" + StringifyAnInt(transitions[t_count].dest_state);
- temp = temp + temp1 + temp2;
+ temp3 = temp + temp1 + temp2;
- xmi+= "<UML:Transition xmi.id=\"" + temp + "\"";
+ xmi+= "<UML:Transition xmi.id=\"" + temp3 + "\"";
xmi+= " source=\"" + temp1 + "\"";
xmi += " target=\"" + temp2 + "\" name=\"\" isSpecification=\"false\">\n";
// Get guard, trigger, and action
- temp = transitions[t_count].trans.trigger;
+// temp = transitions[t_count].trans.trigger;
temp1 = transitions[t_count].trans.guard;
temp2 = transitions[t_count].trans.action;
+ trig_label = triggers[transitions[t_count].trans.trigger].label;
+ trig_op_label = triggers[transitions[t_count].trans.trigger].operation_id;
+
// print trigger, if any
- if (temp != "") {
+ if (trig_label != "<null>") {
xmi+= "<UML:Transition.trigger> <UML:Event> <UML:ModelElement.namespace> <UML:Namespace> ";
- xmi+= "<UML:Namespace.ownedElement> <UML:CallEvent xmi.id=\"\" operation=\"\" ";
- xmi+= "name=\"" + temp + "isSpecification=\"false\"/> ";
+ xmi+= "<UML:Namespace.ownedElement> <UML:CallEvent xmi.id=\"" + temp3;
+ xmi+= "tt\" operation=\""+ trig_op_label + "\" ";
+ xmi+= "name=\"" + trig_label + "\" isSpecification=\"false\"/> ";
xmi+= "</UML:Namespace.ownedElement> </UML:Namespace> </UML:ModelElement.namespace> ";
xmi+= "</UML:Event> </UML:Transition.trigger> ";
}
// print guard, if any
// Note: for guard to work, '<' => '<'
- if (temp1 != ""){
+ if (temp1 != "<null>"){
xmi+= "<UML:Transition.guard> <UML:Guard> <UML:Guard.expression> ";
xmi+= "<UML:BooleanExpression body=\"" + temp1 + "\" language=\"\"/> ";
xmi+= "</UML:Guard.expression> </UML:Guard> </UML:Transition.guard> ";
}
// print action, if any
- if (temp2 != "") {
- xmi+= "<UML:Transition.effect> <UML:UninterpretedAction xmi.id=\"\" ";
+ if (temp2 != "<null>") {
+ xmi+= "<UML:Transition.effect> <UML:UninterpretedAction xmi.id=\"" + temp3 + "ui\" ";
xmi+= "isAsynchronous=\"false\" name=\"\" isSpecification=\"false\"> ";
- xmi+= "<UML:Action.script> <UML:ActionExpression language=\"\" body=\" ";
+ xmi+= "<UML:Action.script> <UML:ActionExpression language=\"\" body=\"";
xmi+= temp2 + "\"/> </UML:Action.script> </UML:UninterpretedAction> </UML:Transition.effect> ";
}
Modified: branches/uml/source/main/cOrganism.h
===================================================================
--- branches/uml/source/main/cOrganism.h 2007-04-19 13:26:37 UTC (rev 1490)
+++ branches/uml/source/main/cOrganism.h 2007-04-19 15:01:01 UTC (rev 1491)
@@ -79,7 +79,7 @@
class cCodeLabel;
struct transition_label {
- std::string trigger;
+ int trigger;
std::string guard;
std::string action;
};
@@ -90,8 +90,18 @@
transition_label trans;
};
+struct state {
+ int identifier;
+ int num_incoming;
+ int num_outgoing;
+};
+struct trigger_info {
+ std::string operation_id;
+ std::string label;
+};
+
class cOrganism
{
@@ -138,9 +148,10 @@
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::vector<int> states;
- std::vector<std::string> triggers;
+ std::vector<state> states;
+ std::vector<trigger_info> triggers;
std::vector<std::string> guards;
std::vector<std::string> actions;
std::vector<transition> transitions;
@@ -228,6 +239,7 @@
int numStates();
int numTrans();
void seedModel();
+ void setParentXMI(std::string x) {parent_xmi = x;}
// find functions
bool findTrans(int, int); // find a transition between two states
@@ -274,12 +286,14 @@
// The get functions get the value of the index of various vectors
- std::string getTrigger();
+// std::string getTriggerIndex();
+ int getTriggerIndex();
std::string getGuard();
std::string getAction();
transition_label getTransLabel();
- int getOrigState();
- int getDestState();
+ int getOrigStateIndex();
+ int getDestStateIndex();
+ std::string getParentXMI() {return parent_xmi;}
// Add functions
bool addState();
@@ -287,8 +301,6 @@
bool addTransition();
bool addTransitionTotal();
-
-
bool InjectParasite(const cGenome& genome);
bool InjectHost(const cCodeLabel& in_label, const cGenome& genome);
void AddParasite(cInjectGenotype* cur) { m_parasites.Push(cur); }
Modified: branches/uml/source/main/cPopulation.h
===================================================================
--- branches/uml/source/main/cPopulation.h 2007-04-19 13:26:37 UTC (rev 1490)
+++ branches/uml/source/main/cPopulation.h 2007-04-19 15:01:01 UTC (rev 1491)
@@ -1,3 +1,4 @@
+
/*
* cPopulation.h
* Avida
Modified: branches/uml/source/main/cTaskLib.cc
===================================================================
--- branches/uml/source/main/cTaskLib.cc 2007-04-19 13:26:37 UTC (rev 1490)
+++ branches/uml/source/main/cTaskLib.cc 2007-04-19 15:01:01 UTC (rev 1491)
@@ -1944,7 +1944,14 @@
double cTaskLib::Task_Hydra(cTaskContext* ctx) const
{
cOrganism* organism = ctx->organism;
+ std::string temp;
+ temp = organism->getXMI();
+
+ if (temp == organism->getParentXMI()) {
+ return 0;
+ }
+
// Check for task success...
/* if (ctx->task_failed == 0) {
return 0;
@@ -1954,7 +1961,6 @@
m_world->GetStats().HydraAttempt();
double bonus = 0.0;
- std::string temp;
unsigned int status_total = 0;
int status=0;
@@ -1983,7 +1989,6 @@
// Then, read from from_subavida[0] as long as is possible, after which point subavida will die.
// Write the model to STDIN of subavida (be careful; write may not write all that you ask!)
- temp = organism->getXMI();
do {
status = write(to_subavida[1], temp.c_str()+status_total, temp.size());
if (status < 0) {
@@ -2015,15 +2020,16 @@
assert(done==subavida);
// if there are no errors, return 0 from hydraulic. otherwise, return non-zero.
-/* if(status != 0) {
- ctx->task_failed = 0;
+ if(status != 0) {
+// ctx->task_failed = 0;
return 0.0;
} else {
- ctx->task_failed = ctx->task_failed && 1;
+ // ctx->task_failed = ctx->task_failed && 1;
+ ctx->task_success_complete += 1;
m_world->GetStats().HydraPassed();
return 1.0;
}
- */
+
}
@@ -2050,9 +2056,9 @@
}
double cTaskLib::Task_SpinN1(cTaskContext* ctx) const {
- //if (ctx->task_failed) {
+ if (ctx->task_success_complete) {
return SpinCoprocess(ctx, "N1");
- //}
+ }
return 0.0;
}
More information about the Avida-cvs
mailing list