[Avida-SVN] r1363 - in branches/uml/source: cpu main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Fri Feb 23 12:09:01 PST 2007
Author: hjg
Date: 2007-02-23 15:09:00 -0500 (Fri, 23 Feb 2007)
New Revision: 1363
Modified:
branches/uml/source/cpu/cHardwareCPU.cc
branches/uml/source/cpu/cHardwareCPU.h
branches/uml/source/main/cOrganism.cc
branches/uml/source/main/cOrganism.h
branches/uml/source/main/cTaskLib.cc
branches/uml/source/main/cTaskLib.h
Log:
Preliminary work on creating transitions that combine predefined triggers, guards, and actions.
Modified: branches/uml/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.cc 2007-02-23 16:07:18 UTC (rev 1362)
+++ branches/uml/source/cpu/cHardwareCPU.cc 2007-02-23 20:09:00 UTC (rev 1363)
@@ -364,7 +364,14 @@
"Get a state"),
cInstEntryCPU("remove-tr", &cHardwareCPU::Inst_DeleteTrans, false,
"Remove a transition"),
+ cInstEntryCPU("next", &cHardwareCPU::Inst_Next, false,
+ "Increment to the next position in the list"),
+ cInstEntryCPU("prev", &cHardwareCPU::Inst_Prev, false,
+ "Decrement to the previous position in the list"),
+ cInstEntryCPU("cr-trans-lab", &cHardwareCPU::Inst_CreateTransitionLabel, false,
+ "Create a transition label"),
+
// cInstEntryCPU("model-ch", &cHardwareCPU::Inst_ModelCheck, false,
// "Model check the model"),
// cInstEntryCPU("cr-trans2", &cHardwareCPU::Inst_CreateTransitionIntStates, false,
@@ -3117,7 +3124,7 @@
bool cHardwareCPU::Inst_HeadDivide(cAvidaContext& ctx)
{
// modified for UML branch
- organism->ModelCheck(ctx);
+ organism->modelCheck(ctx);
return Inst_HeadDivideMut(ctx, 1);
}
@@ -3482,7 +3489,7 @@
int dest_state = GetRegister(reg_used);
//cout << "trans: " << trans << " orig_state: " << orig_state << " dest_state: " << dest_state << endl;
- return organism->AddTrans(trans, orig_state, dest_state);
+ return organism->addTrans(trans, orig_state, dest_state);
// create or find destination state
// check to see if this transition already exists; else add it
@@ -3505,7 +3512,7 @@
int dest_state = GetRegister(reg_used);
//cout << "trans: " << trans << " orig_state: " << orig_state << " dest_state: " << dest_state << endl;
- return organism->AddTransConnect(trans, orig_state, dest_state);
+ return organism->addTransConnect(trans, orig_state, dest_state);
// create or find destination state
// check to see if this transition already exists; else add it
@@ -3533,7 +3540,7 @@
int state_pos = GetRegister(reg_used);
*/
- if ((state_pos >= 0) && (state_pos < organism->NumStates())) {
+ if ((state_pos >= 0) && (state_pos < organism->numStates())) {
int state_label = organism->getStateLabelInPosition(state_pos);
@@ -3574,7 +3581,7 @@
int trans_pos = GetLabel().AsInt(3);
- if ((trans_pos >= 0) && (trans_pos < organism->NumTrans())) {
+ if ((trans_pos >= 0) && (trans_pos < organism->numTrans())) {
int label = organism->getTransLabelInPosition(trans_pos);
// put value into register...
@@ -3591,21 +3598,69 @@
int trans_pos = GetLabel().AsInt(1);
- if ((trans_pos >= 0) && (trans_pos < organism->NumTrans())) {
+ if ((trans_pos >= 0) && (trans_pos < organism->numTrans())) {
// organism->deleteTrans(trans_pos);
// delete the transition in this position....
// int label = organism->getTransLabelInPosition(trans_pos);
+ }
+ return true;
+}
+
+bool cHardwareCPU::Inst_Next(cAvidaContext& ctx)
+{
+ // by default, this instruction increments the triggers vector iterator
+ int reg_used = FindModifiedRegister(REG_AX);
+
+ switch (reg_used){
+ case 0:
+ // increment the triggers vector iterator
+ organism->nextTrigger();
+ break;
+ case 1:
+ // increment the guards vector iterator
+ organism->nextGuard();
+ break;
+ case 2:
+ // increment the actions vector iterator
+ organism->nextAction();
+ break;
+ // default:
+ // we should never get here...
}
-
+
return true;
+}
+
+bool cHardwareCPU::Inst_Prev(cAvidaContext& ctx)
+{
+ int reg_used = FindModifiedRegister(REG_AX);
+
+ switch (reg_used){
+ case 0:
+ // increment the triggers vector iterator
+ organism->prevTrigger();
+ break;
+ case 1:
+ // increment the guards vector iterator
+ organism->prevGuard();
+ break;
+ case 2:
+ // increment the actions vector iterator
+ organism->prevAction();
+ break;
+ // default:
+ // we should never get here...
+ }
+ return true;
+}
-
-
+bool cHardwareCPU::Inst_CreateTransitionLabel(cAvidaContext& ctx)
+{
+ return organism->crTransLabel();
}
-
Modified: branches/uml/source/cpu/cHardwareCPU.h
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.h 2007-02-23 16:07:18 UTC (rev 1362)
+++ branches/uml/source/cpu/cHardwareCPU.h 2007-02-23 20:09:00 UTC (rev 1363)
@@ -480,6 +480,9 @@
bool Inst_GetState(cAvidaContext& ctx);
bool Inst_GetTrans(cAvidaContext& ctx);
bool Inst_DeleteTrans(cAvidaContext& ctx);
+ bool Inst_Next(cAvidaContext& ctx);
+ bool Inst_Prev(cAvidaContext& ctx);
+ bool Inst_CreateTransitionLabel(cAvidaContext& ctx);
// bool Inst_CreateTransitionIntStates(cAvidaContext& ctx);
};
Modified: branches/uml/source/main/cOrganism.cc
===================================================================
--- branches/uml/source/main/cOrganism.cc 2007-02-23 16:07:18 UTC (rev 1362)
+++ branches/uml/source/main/cOrganism.cc 2007-02-23 20:09:00 UTC (rev 1363)
@@ -108,7 +108,25 @@
AddTrans(2,2,3);
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");
+
+ triggers_it = triggers.begin();
+ guards_it = guards.begin();
+ actions_it = actions.begin();
+
}
@@ -433,7 +451,7 @@
/// UML Functions ///
/// This function is a copy of DoOutput ///
-void cOrganism::ModelCheck(cAvidaContext& ctx)
+void cOrganism::modelCheck(cAvidaContext& ctx)
{
// CHECK OUT WHETHER THE IDEAL WORKS....
@@ -500,7 +518,7 @@
// This sets the meaning of the transitions to those of the Multi-Sensor Example.
-void cOrganism::InitTransForMSXMI()
+void cOrganism::initTransForMSXMI()
{
// assign transition values to map elements
@@ -562,7 +580,7 @@
}
-void cOrganism::InitTransForBSXMI()
+void cOrganism::initTransForBSXMI()
{
// This particular assignment of transitions is designed to evolve the ability of Avida
@@ -791,7 +809,7 @@
-bool cOrganism::AddTrans(int trans, int orig, int dest)
+bool cOrganism::addTrans(int trans, int orig, int dest)
{
NameStateMap::iterator pos1, pos2;
bool inserted1, inserted2, inserted3;
@@ -803,7 +821,6 @@
tie(pos1, inserted1) = states.insert(std::make_pair(orig, State()));
if (inserted1) {
u = add_vertex(uml_state_diagram);
- //cout << "added state named " << orig << endl;
uml_state_diagram[u].state_label = orig;
pos1->second = u;
@@ -812,14 +829,12 @@
} else {
u = pos1->second;
- //cout << "found state named " << orig << endl;
}
// create or find dest state
tie(pos2, inserted2) = states.insert(std::make_pair(dest, State()));
if (inserted2) {
v = add_vertex(uml_state_diagram);
- //cout << "added state named " << dest << endl;
uml_state_diagram[v].state_label = dest;
pos2->second = v;
@@ -829,21 +844,16 @@
} else {
v = pos2->second;
- //cout << "found state named " << dest << endl;
}
// call isTrans...
exists = isTrans(u, v, trans);
if (exists == 0) {
tie(transitions, inserted3) = add_edge(u, v, uml_state_diagram);
- //cout << "Adding transition " << u << " " << v << " " << trans << endl;
if (inserted3) {
uml_state_diagram[transitions].edge_label = trans;
- //uml_state_diagram[transitions].edge_info = "";
uml_state_diagram[transitions].start_state = orig;
uml_state_diagram[transitions].end_state = dest;
-
-
- //cout << "added edge labeled " << trans << endl;
+
// add trans to table...
transGuardActionInfo.insert(std::make_pair(trans, ""));
}
@@ -852,110 +862,20 @@
}
-bool cOrganism::AddTransConnect(int trans, int orig, int dest)
+bool cOrganism::addTransConnect(int trans, int orig, int dest)
{
// find either the orig int or the dest int in the map of states & names
// originally thought that either orig or dest could be connected, but actually, must be orig.
- if ((states.find(orig) == states.end()) && (NumStates()>0)) // && (states.find(dest) == states.end()))
+ if ((states.find(orig) == states.end()) && (numStates()>0))
{
return false;
}
- return (AddTrans(trans,orig,dest));
+ return (addTrans(trans,orig,dest));
}
-
-// May eventually want to consider removing the states attached to a transition, if there are not
-// any other transitions that point to it...
-// Also, currently, this is not handling the potential that this is the only
-// transition with a certain integer label and thus it should be removed from the mapping
-// of labels to strings...
-
-// NOT WORKING
-/*
-void cOrganism::deleteTrans(int pos)
-{
-
-
-
-
- Graph::edge_iterator e, eend, q;
- int count = 0;
- int num_trans_w_lab = 0;
- int trans_name;
- int s_start_lab, s_end_lab; //, trans_lab;
- State* st_start;
- State* st_end;
- nsm_it i;
-
-// Transition t;
- if ((pos < 0) || (pos > NumTrans())) {
- return;
- }
-
- trans_name = getTransNumber(pos);
- //e[pos]
- //tie(e, eend) = edges(uml_state_diagram);
- //q = e[pos];
-
- for (tie(e, eend) = edges(uml_state_diagram); e != eend; ++e) {
- if (count == pos) {
-// remove_edge(e, uml_state_diagram);
- //t = uml_state_diagram[*e];
- s_start_lab = uml_state_diagram[*e].start_state;
- s_end_lab = uml_state_diagram[*e].end_state;
- //trans_lab = uml_state_diagram[*e].edge_label;
- remove_edge(*e, uml_state_diagram);
- break;
- }
-// else {
-// if (uml_state_diagram[*e].edge_label == trans_name) {
-// num_trans_w_lab ++;
-// }
-// }
-
- count ++;
- }
-
- for (tie(e, eend) = edges(uml_state_diagram); e != eend; ++e) {
- if (uml_state_diagram[*e].edge_label == trans_name) {
- num_trans_w_lab ++;
- }
- }
-
- for (i=states.begin(); i!=states.end(); ++i)
- {
- if (i->first == s_start_lab) {
- st_start = &(i->second);
- }
- if (i->first == s_end_lab) {
- st_end = &(i->second);
- }
- }
-
- if (num_trans_w_lab == 0){
- // delete from transition accounts...
- transGuardActionInfo.erase(trans_name);
- }
-
-
- if ((out_degree(*st_start, uml_state_diagram) == 0) && (in_degree(*st_start, uml_state_diagram) == 0)) {
- remove_vertex(*st_start, uml_state_diagram);
- }
-
- if ((s_start_lab != s_end_lab) && (out_degree(*st_end, uml_state_diagram) == 0) && (in_degree(*st_end, uml_state_diagram) == 0)) {
- remove_vertex(*st_end, uml_state_diagram);
- }
-
-
- return;
-}
-*/
-
-
-
// similar to getTransBetweenVertices...
// optimization candidate perhaps using edge_range as per DBK
bool cOrganism::isTrans(State u, State v, int trans_name)
@@ -1004,7 +924,7 @@
return found_entry;
}
- if ((NumStates() <= s0_pos) || (NumStates() <= s1_pos)) {
+ if ((numStates() <= s0_pos) || (numStates() <= s1_pos)) {
return found_entry;
}
@@ -1019,137 +939,7 @@
}
-/*
-void cOrganism::printIdealXMI(cAvidaContext& ctx)
-{
- std::string temp;
- temp = "0";
- xmi += "<UML:Pseudostate xmi.id=\"s" + temp + "\" kind=\"initial\" outgoing=\"\" name=\"\" isSpecification=\"false\"/>\n";
-
- for (int j = 1; j < 5; ++j) {
- temp = "s" + StringifyAnInt(j);
- 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";
- xmi+= "</UML:CompositeState>\n";
- xmi+= "</UML:StateMachine.top>\n";
-
- // start the set of transitions...
- xmi+="<UML:StateMachine.transitions>\n";
-
- // trans 0
-
- temp = "t0";
-
- xmi+= "<UML:Transition xmi.id=\"" + temp + "\"";
- temp = "s0";
- xmi+= " source=\"" + temp + "\"";
- temp = "s1";
- xmi += " target=\"" + temp + "\" name=\"\" isSpecification=\"false\">\n";
- //xmi += temp;
- xmi += "</UML:Transition>\n";
-
-
- // trans 1
-
- temp = "t1";
-
- xmi+= "<UML:Transition xmi.id=\"" + temp + "\"";
- temp = "s1";
- xmi+= " source=\"" + temp + "\"";
- temp = "s2";
- xmi += " target=\"" + temp + "\" name=\"\" isSpecification=\"false\">\n";
- temp = "";
- temp += "<UML:Transition.effect> <UML:UninterpretedAction xmi.id=\"XDE-176F1237-1448-4226-A095-075FABD68B33\"";
- temp += " isAsynchronous=\"false\" name=\"\" isSpecification=\"false\">";
- temp += "<UML:Action.script> <UML:ActionExpression language=\"\" ";
- temp += "body=\"^TempSensor.getTempData()\"/> </UML:Action.script> ";
- temp += "</UML:UninterpretedAction> </UML:Transition.effect> \n";
- xmi += temp;
- xmi += "</UML:Transition>\n";
-
- // trans 2
- temp = "t2";
-
- xmi+= "<UML:Transition xmi.id=\"" + temp + "\"";
- temp = "s2";
- xmi+= " source=\"" + temp + "\"";
- temp = "s3";
- xmi += " target=\"" + temp + "\" name=\"\" isSpecification=\"false\">\n";
-
- temp = "";
- temp += "<UML:Transition.trigger> <UML:Event> <UML:ModelElement.namespace> ";
- temp += "<UML:Namespace> <UML:Namespace.ownedElement> ";
- temp += "<UML:CallEvent xmi.id=\"XDE-4C4256DD-D7D7-4687-AA73-761334859279\" " ;
- temp += " operation=\"XDE-9517D6BA-8666-4A82-AFEA-62D60FE37B07\" name=\"setTempData\" ";
- temp += " isSpecification=\"false\"/> </UML:Namespace.ownedElement> </UML:Namespace> ";
- temp += " </UML:ModelElement.namespace> </UML:Event> </UML:Transition.trigger>\n";
- xmi += temp;
- xmi += "</UML:Transition>\n";
-
- // trans 3
- temp = "t3";
-
- xmi+= "<UML:Transition xmi.id=\"" + temp + "\"";
- temp = "s3";
- xmi+= " source=\"" + temp + "\"";
- temp = "s1";
- xmi += " target=\"" + temp + "\" name=\"\" isSpecification=\"false\">\n";
-
- temp = "";
- xmi += temp;
- xmi += "</UML:Transition>\n";
-
- // trans 4
- temp = "t4";
-
- xmi+= "<UML:Transition xmi.id=\"" + temp + "\"";
- temp = "s1";
- xmi+= " source=\"" + temp + "\"";
- temp = "s4";
- xmi += " target=\"" + temp + "\" name=\"\" isSpecification=\"false\">\n";
-
- temp = "";
- temp += "<UML:Transition.effect> <UML:UninterpretedAction xmi.id=\"XDE-8280CF2B-DA14-4989-AC7F-D83012DE3234\"";
- temp += " isAsynchronous=\"false\" name=\"\" isSpecification=\"false\"> ";
- temp += "<UML:Action.script> <UML:ActionExpression language=\"\" ";
- temp += " body=\"^TempSensor.getOpState()\"/> </UML:Action.script> ";
- temp += " </UML:UninterpretedAction> </UML:Transition.effect>\n";
-
- xmi += temp;
- xmi += "</UML:Transition>\n";
-
- // trans 5
- temp = "t5";
-
- xmi+= "<UML:Transition xmi.id=\"" + temp + "\"";
- temp = "s4";
- xmi+= " source=\"" + temp + "\"";
- temp = "s1";
- xmi += " target=\"" + temp + "\" name=\"\" isSpecification=\"false\">\n";
-
- temp = "";
- temp += "<UML:Transition.trigger> <UML:Event> <UML:ModelElement.namespace>";
- temp += "<UML:Namespace> <UML:Namespace.ownedElement> ";
- temp += "<UML:CallEvent xmi.id=\"XDE-C2891D3C-A49E-4DF0-BD95-A291630F4E4B\" ";
- temp += " operation=\"XDE-4437EBF1-9C42-4EB4-B7CF-415697B567CD\" name=\"setTempOpState\"";
- temp += " isSpecification=\"false\"/> </UML:Namespace.ownedElement> </UML:Namespace>";
- temp += " </UML:ModelElement.namespace> </UML:Event> </UML:Transition.trigger>\n";
-
- xmi += temp;
- xmi += "</UML:Transition>\n";
-
-}
-
-*/
-
void cOrganism::printXMI(cAvidaContext& ctx)
{
@@ -1161,7 +951,7 @@
std::string temp, temp1, temp2;
int tempint;
- InitTransForMSXMI();
+ initTransForMSXMI();
xmi = "";
// loop through all states
@@ -1169,8 +959,8 @@
tie(i, iend) = vertices(uml_state_diagram);
- if (NumStates() > 0) {
- temp = StringifyAnInt(uml_state_diagram[0].state_label);
+ if (numStates() > 0) {
+ temp = stringifyAnInt(uml_state_diagram[0].state_label);
xmi += "<UML:Pseudostate xmi.id=\"s" + temp + "\" kind=\"initial\" outgoing=\"\" name=\"s";
xmi += temp + "\" isSpecification=\"false\"/>\n";
++i;
@@ -1178,7 +968,7 @@
for (; i != iend; ++i) {
- temp = "s" + StringifyAnInt(uml_state_diagram[*i].state_label);
+ temp = "s" + stringifyAnInt(uml_state_diagram[*i].state_label);
xmi+="<UML:CompositeState xmi.id=\"";
xmi+=temp;
xmi+= "\" isConcurrent=\"false\" name=\"";
@@ -1199,9 +989,9 @@
for (tie(e, eend) = edges(uml_state_diagram); e != eend; ++e) {
// info determined from the trans itself....
trans_label = uml_state_diagram[*e].edge_label;
- temp = "t" + StringifyAnInt(uml_state_diagram[*e].edge_label);
- temp1 = "s" + StringifyAnInt(uml_state_diagram[*e].start_state);
- temp2 = "s" + StringifyAnInt(uml_state_diagram[*e].end_state);
+ temp = "t" + stringifyAnInt(uml_state_diagram[*e].edge_label);
+ temp1 = "s" + stringifyAnInt(uml_state_diagram[*e].start_state);
+ temp2 = "s" + stringifyAnInt(uml_state_diagram[*e].end_state);
temp = temp + temp1 + temp2;
// if I manage to set edge_info, I could then use that to print...
// currently the start state and end state are already encoded. :)
@@ -1223,7 +1013,7 @@
// print the label. Change - signs to _
-std::string cOrganism::StringifyAnInt(int x) {
+std::string cOrganism::stringifyAnInt(int x) {
std::ostringstream o;
@@ -1237,17 +1027,17 @@
}
// return the number of states in a state diagram
-double cOrganism::NumStates()
+double cOrganism::numStates()
{
return (double) num_vertices(uml_state_diagram);
}
-double cOrganism::NumTrans()
+double cOrganism::numTrans()
{
return (double) num_edges(uml_state_diagram);
}
-double cOrganism::NumUniqueTransLabels()
+double cOrganism::numUniqueTransLabels()
{
return transGuardActionInfo.size();
}
@@ -1267,14 +1057,6 @@
cOrganism::State& cOrganism::getStateInPosition (int num)
{
- /*std::pair<vertex_iterator, vertex_iterator>
-vertices(const adjacency_list& g)*/
-// Graph::vertex_iterator vi, vi_end;
-// tie(vi,vi_end) = vertices(uml_state_diagram);
-// vi+=num;
- //graph_traits<Graph>::vertex_descriptor b = *vi;
-// return *vi;
-
int count = 0;
// This code uses a value ordering on the states (lowest number = position 0)
nsm_it i;
@@ -1287,13 +1069,6 @@
}
return i->second;
-
-/*
- int x = PosToStateLabel[num];
- return (states[x]);
-*/
-
-
}
@@ -1317,34 +1092,7 @@
}
-/*
-bool cOrganism::isConnected ()
-{
-// std::vector<int> component(num_vertices(uml_state_diagram));
-// int num = connected_components(uml_state_diagram, &component[0]);
-// if (num > 1) {
-// return 0;
-// }
- Graph::vertex_iterator i, iend;
- tie(i, iend) = vertices(uml_state_diagram);
- int count = 0;
-
-
-
- for (; i != iend; ++i) {
- if (in_degree(*i, uml_state_diagram) == 0) {
- count ++;
- if (count > 1) {
- return 0;
- }
- }
- }
- return 1;
-}
-*/
-
-
// if you ask for something greater than the number of trans -- you get the highest numbered one...
int cOrganism::getTransLabelInPosition (int num)
{
@@ -1362,14 +1110,118 @@
}
-cOrganism::Graph& cOrganism::GetGraph()
+cOrganism::Graph& cOrganism::getGraph()
{
return uml_state_diagram;
}
+bool cOrganism::nextTrigger()
+{
+ triggers_it++;
+ if (triggers_it == triggers.end()){
+ triggers_it = triggers.begin();
+ }
+}
+bool cOrganism::prevTrigger()
+{
+ if (triggers_it == triggers.begin()){
+ triggers_it = triggers.end();
+ }
+ triggers_it--;
+}
+bool cOrganism::nextGuard()
+{
+ guards_it++;
+ if (guards_it == guards.end()){
+ guards_it = guards.begin();
+ }
+}
+bool cOrganism::prevGuard()
+{
+ if (guards_it == guards.begin()){
+ guards_it = guards.end();
+ }
+ guards_it--;
+}
+
+bool cOrganism::nextAction()
+{
+ actions_it++;
+ if (actions_it == actions.end()){
+ actions_it = actions.begin();
+ }
+}
+
+bool cOrganism::prevAction()
+{
+ if (actions_it == actions.begin()){
+ actions_it = actions.end();
+ }
+ actions_it--;
+}
+
+std::string cOrganism::getTrigger()
+{
+ std::string tmp;
+ if (triggers.size() > 0) {
+ tmp = *triggers_it;
+ } else {
+ tmp = "";
+ }
+ return tmp;
+}
+
+std::string cOrganism::getGuard()
+{
+ std::string tmp;
+ if (guards.size() > 0) {
+ tmp = *guards_it;
+ } else {
+ tmp = "";
+ }
+ return tmp;
+}
+
+std::string cOrganism::getAction()
+{
+ std::string tmp;
+ if (actions.size() > 0) {
+ tmp = *actions_it;
+ } else {
+ tmp = "";
+ }
+ return tmp;
+}
+
+bool cOrganism::crTransLabel()
+{
+// std::string tmp_trigger = getTrigger();
+// std::string tmp_guard = getGuard();
+// std::string tmp_action = getAction();
+ std::string tmp_label = getTrigger() + getGuard() + getAction();
+// std::vector<std::string> transition_labels;
+ transition_labels.push_back(tmp_label);
+
+ return true;
+}
+
+bool cOrganism::isTransLabel(std::string desired_lab)
+{
+ std::vector<std::string>::iterator tr_lab_it;
+ for(tr_lab_it = transition_labels.begin(); tr_lab_it != transition_labels.end(); tr_lab_it++)
+ {
+ if (desired_lab == *tr_lab_it) {
+ return true;
+ }
+ }
+ return false;
+}
+
+
+
bool cOrganism::InjectParasite(const cGenome& injected_code)
{
assert(m_interface);
Modified: branches/uml/source/main/cOrganism.h
===================================================================
--- branches/uml/source/main/cOrganism.h 2007-02-23 16:07:18 UTC (rev 1362)
+++ branches/uml/source/main/cOrganism.h 2007-02-23 20:09:00 UTC (rev 1363)
@@ -158,17 +158,26 @@
tBuffer<cOrgMessage> inbox;
tBuffer<cOrgMessage> sent;
- // UML internal state diagram components
+ // UML diagram components
Graph uml_state_diagram; // the overall graph of the UML state diagram
Transition transitions; //
NameStateMap states; // map of the state names
TransMeaning transGuardActionInfo; // map of transition integers to the string representing their label
- static std::string xmi_begin;
- std::string xmi;
- static std::string xmi_end;
+ 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::map<int, int> PosToStateLabel; // a map that relates the number in which the state was inserted
// to the label the organism assigns it.
+ std::vector<std::string> triggers;
+ std::vector<std::string> guards;
+ std::vector<std::string> actions;
+ std::vector<std::string> transition_labels;
+ std::vector<std::string>::iterator triggers_it;
+ std::vector<std::string>::iterator guards_it;
+ std::vector<std::string>::iterator actions_it;
+
+
@@ -241,34 +250,44 @@
void NetReset();
// UML Stuff
- void ModelCheck(cAvidaContext& ctx);
- void printXMI(cAvidaContext& ctx);
-// void printIdealXMI(cAvidaContext& ctx);
-
- void InitTransForMSXMI();
- void InitTransForBSXMI();
- bool AddTrans(int trans, int orig, int dest);
- bool AddTransConnect(int trans, int orig, int dest);
- double NumStates();
- double NumTrans();
- double NumUniqueTransLabels();
- void AssignTransMeaning(int trans);
- Graph& GetGraph();
+ void modelCheck(cAvidaContext& ctx); // evaluate the model
+ void printXMI(cAvidaContext& ctx); // print the XMI version of the model
+ bool addTrans(int trans, int orig, int dest); // add a transition to the diagram
+ bool addTransConnect(int trans, int orig, int dest); // add a transition to the diagram
+ // however, the trans initial state MUST
+ // already be a part of the diagram.
+ bool crTransLabel(); // create a transition label
+
+ // accessors -
+ double numStates();
+ double numTrans();
+ double numUniqueTransLabels();
+ void assignTransMeaning(int trans);
+ Graph& getGraph();
State& getStateInPosition (int num);
int getStateLabelInPosition (int num);
int getTransLabelInPosition (int num);
bool isTrans(State, State, int);
+ bool isTransLabel(std::string);
int getTransNumber (int pos);
bool findTrans(int s0_pos, int s1_pos, int t_pos);
-// void deleteTrans (int pos);
-// bool isConnected();
-
- // This returns the list of transitions between two states. What I want is to look up one based
- // on its placement in the trans_set, but this has already been solved by HIL printing. Check there after dinner.
- // stl::set<int> getTransBetweenVertices(State, State);
- std::string StringifyAnInt (int x);
std::string getXMI();
+
+ // helper functions
+ std::string stringifyAnInt (int x);
+ void initTransForMSXMI();
+ void initTransForBSXMI();
+ bool nextTrigger();
+ bool prevTrigger();
+ bool nextGuard();
+ bool prevGuard();
+ bool nextAction();
+ bool prevAction();
+ std::string getTrigger();
+ std::string getGuard();
+ std::string getAction();
+
// NameStateMap::iterator pos;
Modified: branches/uml/source/main/cTaskLib.cc
===================================================================
--- branches/uml/source/main/cTaskLib.cc 2007-02-23 16:07:18 UTC (rev 1362)
+++ branches/uml/source/main/cTaskLib.cc 2007-02-23 20:09:00 UTC (rev 1363)
@@ -373,6 +373,12 @@
NewTask(name, "Successfully Created transition 10", &cTaskLib::Task_Transition_bs10);
else if (name == "spinn1")
NewTask(name, "Successfully ran spin for N1 (yay!)", &cTaskLib::Task_SpinN1);
+ else if (name == "trl-1")
+ NewTask(name, "Successfully created test transition label 1", &cTaskLib::Task_TransLabTest1);
+ else if (name == "trl-2")
+ NewTask(name, "Successfully created test transition label 1", &cTaskLib::Task_TransLabTest2);
+ else if (name == "trl-3")
+ NewTask(name, "Successfully created test transition label 1", &cTaskLib::Task_TransLabTest3);
/* else if (name == "uml_trs")
NewTask(name, "Successfully Created the right number of transitions", &cTaskLib::Task_CreateTranss);
*/
@@ -1889,10 +1895,10 @@
{
cOrganism* organism = ctx->organism;
double bonus = 0.0;
- double numStates = organism->NumStates();
+ double numStates = organism->numStates();
// reward for constructing 7 states - brightness sensor
- if (organism->NumStates() <= 7) {
+ if (organism->numStates() <= 7) {
bonus += numStates;
//bonus = 1.0;
} /*else {
@@ -1907,10 +1913,10 @@
{
cOrganism* organism = ctx->organism;
double bonus = 0.0;
- double numTrans = organism->NumTrans();
+ double numTrans = organism->numTrans();
// reward for constructing 11 trans - brightness sensor
- if (organism->NumTrans() <= 11) {
+ if (organism->numTrans() <= 11) {
bonus += numTrans;
//bonus = 1.0;
} /*else {
@@ -1983,7 +1989,7 @@
double bonus = 0.0;
//if (ctx->organism->findTrans(1, 4, 4)) {
- if (ctx->organism->NumUniqueTransLabels() > 4) {
+ if (ctx->organism->numUniqueTransLabels() > 4) {
bonus = 1.0;
}
@@ -2146,7 +2152,7 @@
// when min/max/set are at end
// if (ctx->organism->findTrans(6, 1, 8)) {
- if (ctx->organism->NumStates() > 8) {
+ if (ctx->organism->numStates() > 8) {
bonus = 1.0;
}
@@ -2180,8 +2186,40 @@
return bonus;
}
+double cTaskLib::Task_TransLabTest1(cTaskContext* ctx) const
+{
+ double bonus = 0.0;
+ // tbgbab
+ if (ctx->organism->isTransLabel("tbgbab")) {
+ bonus = 1.0;
+ }
+
+ return bonus;
+}
+double cTaskLib::Task_TransLabTest2(cTaskContext* ctx) const
+{
+ double bonus = 0.0;
+ // tdgaad
+ if (ctx->organism->isTransLabel("tdgaad")) {
+ bonus = 1.0;
+ }
+
+ return bonus;
+}
+double cTaskLib::Task_TransLabTest3(cTaskContext* ctx) const
+{
+ double bonus = 0.0;
+ // tagdac
+ if (ctx->organism->isTransLabel("tagdac")) {
+ bonus = 1.0;
+ }
+
+ return bonus;
+}
+
+
double cTaskLib::Task_Hydra(cTaskContext* ctx) const
{
cOrganism* organism = ctx->organism;
Modified: branches/uml/source/main/cTaskLib.h
===================================================================
--- branches/uml/source/main/cTaskLib.h 2007-02-23 16:07:18 UTC (rev 1362)
+++ branches/uml/source/main/cTaskLib.h 2007-02-23 20:09:00 UTC (rev 1363)
@@ -254,6 +254,9 @@
double Task_Transition_bs8(cTaskContext* ctx) const;
double Task_Transition_bs9(cTaskContext* ctx) const;
double Task_Transition_bs10(cTaskContext* ctx) const;
+ double Task_TransLabTest1(cTaskContext* ctx) const;
+ double Task_TransLabTest2(cTaskContext* ctx) const;
+ double Task_TransLabTest3(cTaskContext* ctx) const;
double SpinCoprocess(cTaskContext* ctx, const std::string& neverclaimFile) const;
double Task_SpinN1(cTaskContext* ctx) const;
More information about the Avida-cvs
mailing list