[Avida-SVN] r1369 - in branches/uml/source: cpu main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Sun Feb 25 17:09:13 PST 2007
Author: hjg
Date: 2007-02-25 20:09:12 -0500 (Sun, 25 Feb 2007)
New Revision: 1369
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/cStats.cc
branches/uml/source/main/cStats.h
branches/uml/source/main/cTaskLib.cc
branches/uml/source/main/cTaskLib.h
Log:
Beginning of the refactoring - states, trans, translabels, etc. are all vectors w/ indices
Modified: branches/uml/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.cc 2007-02-26 00:15:44 UTC (rev 1368)
+++ branches/uml/source/cpu/cHardwareCPU.cc 2007-02-26 01:09:12 UTC (rev 1369)
@@ -351,31 +351,17 @@
// nop-x (included with nops)
cInstEntryCPU("skip", &cHardwareCPU::Inst_Skip),
- // UML Element Creation
-// cInstEntryCPU("cr-state", &cHardwareCPU::Inst_CreateState, false,
-// "Create a state"),
- cInstEntryCPU("cr-trans-con", &cHardwareCPU::Inst_CreateTransitionConnect, false,
- "Create a connected transition"),
- cInstEntryCPU("cr-trans", &cHardwareCPU::Inst_CreateTransition, false,
- "Create a transition"),
- cInstEntryCPU("get-trans", &cHardwareCPU::Inst_GetTrans, false,
- "Get a transition"),
- cInstEntryCPU("get-state", &cHardwareCPU::Inst_GetState, false,
- "Get a state"),
- cInstEntryCPU("remove-tr", &cHardwareCPU::Inst_DeleteTrans, false,
- "Remove a transition"),
+ // UML Element Creation
+ cInstEntryCPU("addState", &cHardwareCPU::Inst_AddState, false,
+ "Add a new state"),
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,
-// "Create a transition; States read from registers")
+ cInstEntryCPU("addTransLab", &cHardwareCPU::Inst_AddTransitionLabel, false,
+ "Add a transition label"),
+ cInstEntryCPU("addTrans", &cHardwareCPU::Inst_AddTransition, false,
+ "Add a transition")
};
const int n_size = sizeof(s_n_array)/sizeof(cNOPEntryCPU);
@@ -3393,241 +3379,37 @@
//// UML Element Construction ////
-/*
-bool cHardwareCPU::Inst_CreateState(cAvidaContext& ctx)
-{
- const int reg_used = FindModifiedRegister(REG_AX);
-// currently, we are only allowing for 3 states, nop-A, nop-B, nop-C
- organism->uml_states[reg_used]=reg_used;
- if (organism->uml_states.size() > 2)
- return true;
-
-
- return true;
-}
-
-bool cHardwareCPU::Inst_CreateTransition(cAvidaContext& ctx)
-{
- // a transition should consist of 3 nops; all of which are optional....
- // must figure out how to do that...
- const int trans = FindModifiedRegister(REG_AX);
- const int orig_state = FindModifiedRegister(REG_AX);
- const int dest_state = FindModifiedRegister(REG_BX);
-
- pair<int, int> st;
- st = make_pair (orig_state, dest_state);
-
- //m.insert(pair<const char* const, int>("a", 1));
- organism->uml_transitions.insert(pair<int, pair<int, int> >(trans, st));
- if ((trans == 1) && (orig_state == 1) && (dest_state == 2))
- return true;
-
- return true;
-}
-
-
-bool cHardwareCPU::Inst_ModelCheck(cAvidaContext& ctx)
-{
-// const int reg_used = FindModifiedRegister(REG_BX);
-
- // Do the "put" component
-// const int value_out = GetRegister(reg_used);
- organism->ModelCheck(ctx); // , value_out); // Check for tasks completed.
-
-// Do the "get" component
-// const int value_in = organism->GetNextInput();
-// GetRegister(reg_used) = value_in;
-// organism->DoInput(value_in);
- return true;
-}
-
-
-bool cHardwareCPU::Inst_CreateTransitionIntStates(cAvidaContext& ctx)
-{
-
-// a transition should consist of an integer in a nop.
- int reg_used = FindModifiedRegister(REG_AX);
- int trans = GetRegister(reg_used);
-
-// the origin and destination states are determined by the values in reg b and reg c.
-// both registers could be modified by a nop...
- reg_used = FindModifiedRegister(REG_BX);
- int orig_state = GetRegister(reg_used);
- reg_used = FindNextRegister(reg_used);
- int dest_state = GetRegister(reg_used);
-
- // add states to set of states
- organism->uml_state_set.insert(orig_state);
- organism->uml_state_set.insert(dest_state);
- organism->uml_trans_set.insert(pair<int, std::string>(trans, ""));
-
- // add transition to multipmap
- pair<int, int> st;
- st = make_pair (orig_state, dest_state);
- organism->uml_transitions.insert(pair<int, pair<int, int> >(trans, st));
-
- // add transition to mapping by state
- st = make_pair (trans, dest_state);
- organism->uml_trans_by_state.insert(pair<int, pair<int, int> >(orig_state, st));
-
- return true;
-
-}
-*/
-
-bool cHardwareCPU::Inst_CreateTransition(cAvidaContext& ctx)
-{
- // a transition should consist of an integer in a nop.
- int reg_used = FindModifiedRegister(REG_AX);
- int trans = GetRegister(reg_used);
-
-// the origin and destination states are determined by the values in reg b and reg c.
-// both registers could be modified by a nop...
- reg_used = FindModifiedRegister(REG_BX);
- int orig_state = GetRegister(reg_used);
- reg_used = FindNextRegister(reg_used);
- 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);
- // create or find destination state
-
- // check to see if this transition already exists; else add it
-
-
-// return true;
-}
-
-bool cHardwareCPU::Inst_CreateTransitionConnect(cAvidaContext& ctx)
-{
- // a transition should consist of an integer in a nop.
- int reg_used = FindModifiedRegister(REG_AX);
- int trans = GetRegister(reg_used);
-
-// the origin and destination states are determined by the values in reg b and reg c.
-// both registers could be modified by a nop...
- reg_used = FindModifiedRegister(REG_BX);
- int orig_state = GetRegister(reg_used);
- reg_used = FindNextRegister(reg_used);
- 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);
- // create or find destination state
-
- // check to see if this transition already exists; else add it
-
-
-// return true;
-}
-
-
-bool cHardwareCPU::Inst_GetState(cAvidaContext& ctx)
-{
-
- ReadLabel();
- GetLabel();
-
- int state_pos = GetLabel().AsInt(3);
-// cString a = GetLabel().AsString();
-
-
-
- // This did not work. Time to try again.
-/*
- // get the state indexed by the number in
- int reg_used = FindModifiedRegister(REG_AX);
- int state_pos = GetRegister(reg_used);
-*/
-
- if ((state_pos >= 0) && (state_pos < organism->numStates())) {
- int state_label = organism->getStateLabelInPosition(state_pos);
-
-
-/*
- assert(default_register < NUM_REGISTERS); // Reg ID too high.
-
- if (m_inst_set->IsNop(IP().GetNextInst())) {
- IP().Advance();
- default_register = m_inst_set->GetNopMod(IP().GetInst());
- IP().SetFlagExecuted();
- }
- return default_register;
-*/
- // put value into register...
-// FindNextRegister(reg_used) = state_label;
- GetRegister(REG_CX) = state_label;
- }
-
-
-
-// this needs to calculate a state to return based on some crazy nop calculation
-
- // check if next instruction is nop.
-
- return true;
-
-
-}
-
-bool cHardwareCPU::Inst_GetTrans(cAvidaContext& ctx)
-{
-/* // get the state indexed by the number in
- int reg_used = FindModifiedRegister(REG_AX);
- int trans_pos = GetRegister(reg_used);*/
-
- ReadLabel();
- GetLabel();
-
- int trans_pos = GetLabel().AsInt(3);
-
- if ((trans_pos >= 0) && (trans_pos < organism->numTrans())) {
- int label = organism->getTransLabelInPosition(trans_pos);
-
- // put value into register...
- GetRegister(REG_AX) = label;
- }
-
- return true;
-}
-
-bool cHardwareCPU::Inst_DeleteTrans(cAvidaContext& ctx)
-{
- ReadLabel();
- GetLabel();
-
- int trans_pos = GetLabel().AsInt(1);
-
- 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
+ // by default, this instruction increments the triggers vector index
int reg_used = FindModifiedRegister(REG_AX);
switch (reg_used){
case 0:
- // increment the triggers vector iterator
+ // increment the triggers vector index
organism->nextTrigger();
break;
case 1:
- // increment the guards vector iterator
+ // increment the guards vector index
organism->nextGuard();
break;
case 2:
- // increment the actions vector iterator
+ // increment the actions vector index
organism->nextAction();
break;
+ case 3:
+ // increment the transition labels index
+ organism->nextTransitionLabel();
+ break;
+ case 4:
+ // increment the origin state index
+ organism->nextOriginState();
+ break;
+ case 5:
+ // increment the destination state index
+ organism->nextDestinationState();
+ break;
// default:
// we should never get here...
}
@@ -3641,26 +3423,48 @@
switch (reg_used){
case 0:
- // increment the triggers vector iterator
+ // decrement the triggers vector index
organism->prevTrigger();
break;
case 1:
- // increment the guards vector iterator
+ // decrement the guards vector index
organism->prevGuard();
break;
case 2:
- // increment the actions vector iterator
+ // decrement the actions vector index
organism->prevAction();
break;
+ case 3:
+ // decrement the transition labels index
+ organism->prevTransitionLabel();
+ break;
+ case 4:
+ // decrement the original state index
+ organism->prevOriginState();
+ break;
+ case 5:
+ // decement the destination state index
+ organism->prevDestinationState();
+ break;
// default:
// we should never get here...
}
return true;
}
-bool cHardwareCPU::Inst_CreateTransitionLabel(cAvidaContext& ctx)
+bool cHardwareCPU::Inst_AddTransitionLabel(cAvidaContext& ctx)
{
- return organism->crTransLabel();
+ return organism->addTransitionLabel();
+// return true;
}
+bool cHardwareCPU::Inst_AddState(cAvidaContext& ctx)
+{
+ return organism->addState();
+}
+bool cHardwareCPU::Inst_AddTransition(cAvidaContext& ctx)
+{
+ return organism->addTransition();
+}
+
Modified: branches/uml/source/cpu/cHardwareCPU.h
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.h 2007-02-26 00:15:44 UTC (rev 1368)
+++ branches/uml/source/cpu/cHardwareCPU.h 2007-02-26 01:09:12 UTC (rev 1369)
@@ -472,18 +472,12 @@
bool Inst_Skip(cAvidaContext& ctx);
//// UML Element Construction ////
-// bool Inst_CreateState(cAvidaContext& ctx);
-// bool Inst_CreateTransition(cAvidaContext& ctx);
-// bool Inst_ModelCheck(cAvidaContext& ctx);
- bool Inst_CreateTransition(cAvidaContext& ctx);
- bool Inst_CreateTransitionConnect(cAvidaContext& ctx);
- bool Inst_GetState(cAvidaContext& ctx);
- bool Inst_GetTrans(cAvidaContext& ctx);
- bool Inst_DeleteTrans(cAvidaContext& ctx);
+ bool Inst_AddState(cAvidaContext& ctx);
bool Inst_Next(cAvidaContext& ctx);
bool Inst_Prev(cAvidaContext& ctx);
- bool Inst_CreateTransitionLabel(cAvidaContext& ctx);
-// bool Inst_CreateTransitionIntStates(cAvidaContext& ctx);
+ bool Inst_AddTransitionLabel(cAvidaContext& ctx);
+ bool Inst_AddTransition(cAvidaContext& ctx);
+
};
Modified: branches/uml/source/main/cOrganism.cc
===================================================================
--- branches/uml/source/main/cOrganism.cc 2007-02-26 00:15:44 UTC (rev 1368)
+++ branches/uml/source/main/cOrganism.cc 2007-02-26 01:09:12 UTC (rev 1369)
@@ -50,6 +50,7 @@
}
//read from file; load into string/strstream, and return it.
+
return data;
}
@@ -123,10 +124,12 @@
actions.push_back("ac");
actions.push_back("ad");
- triggers_it = triggers.begin();
- guards_it = guards.begin();
- actions_it = actions.begin();
-
+ trigger_index = 0;
+ action_index = 0;
+ guard_index = 0;
+ orig_state_index = -1;
+ dest_state_index = -1;
+ total_states = 0;
}
@@ -454,9 +457,7 @@
void cOrganism::modelCheck(cAvidaContext& ctx)
{
- // CHECK OUT WHETHER THE IDEAL WORKS....
printXMI(ctx);
- //printIdealXMI(ctx);
assert(m_interface);
@@ -511,717 +512,276 @@
m_hardware->ProcessBonusInst(ctx, cInstruction(cur_inst) );
}
- m_world->GetStats().UpdateModelStats(uml_state_diagram);
+// m_world->GetStats().UpdateModelStats(uml_state_diagram);
}
+// For all of the next* functions
+// increment the index. If the index points to the end of the vector, it should then point to
+// the beginning of the vector.
-// This sets the meaning of the transitions to those of the Multi-Sensor Example.
-void cOrganism::initTransForMSXMI()
+bool cOrganism::nextTrigger()
{
-
- // assign transition values to map elements
- std::map <int, std::string>::iterator it;
- std::string temp;
- int count = 0;
-
- for (it = transGuardActionInfo.begin(); it!=transGuardActionInfo.end(); ++it) {
- switch (count){
- case 0:
- (*it).second = "";
- break;
- case 1:
- 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";
- (*it).second = temp;
- break;
- case 2:
- 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";
- (*it).second = temp;
- break;
- case 3:
- (*it).second = "";
- break;
- case 4:
- 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";
- (*it).second =temp;
- break;
- case 5:
- 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";
- (*it).second = temp;
- break;
- default:
- (*it).second = " ";
+ if (triggers.size() == 0) {
+ return false;
}
- count++;
- }
-}
-
-void cOrganism::initTransForBSXMI()
-{
-
- // This particular assignment of transitions is designed to evolve the ability of Avida
- // to develop a function that checks for operational state...
-
- std::map <int, std::string>::iterator it;
- std::string temp;
- int count = 0;
-
- for (it = transGuardActionInfo.begin(); it!=transGuardActionInfo.end(); ++it) {
- switch (count){
- case 0:
- (*it).second = "";
- break;
- case 1:
- temp = "";
- temp += "<UML:Transition.trigger> <UML:Event> <UML:ModelElement.namespace> <UML:Namespace> ";
- temp += "<UML:Namespace.ownedElement> <UML:CallEvent xmi.id=\"XDE-A28463C5-2F9F-457C-B6F3-241526CA4791\" ";
- temp += " operation=\"XDE-E84A5762-CA92-4E03-A237-FE5AE2C99D9A\" name=\"getBrightnessValue\" ";
- temp += "isSpecification=\"false\"/> </UML:Namespace.ownedElement> </UML:Namespace> ";
- temp += " </UML:ModelElement.namespace> </UML:Event> </UML:Transition.trigger> ";
- (*it).second =temp;
- break;
- case 2:
- temp = "";
- temp += "<UML:Transition.effect> <UML:UninterpretedAction xmi.id=\"XDE-6C3D3042-5C7A-4746-8A90-BEDB86FD2FF4\" ";
- temp += "isAsynchronous=\"false\" name=\"\" isSpecification=\"false\"> <UML:Action.script> ";
- temp += " <UML:ActionExpression language=\"\" body=\"^Environment.getBrightnessValue\"/> ";
- temp += "</UML:Action.script> </UML:UninterpretedAction> </UML:Transition.effect> ";
- (*it).second = temp;
- break;
- case 3:
- temp = "";
- temp += "<UML:Transition.trigger> <UML:Event> <UML:ModelElement.namespace> <UML:Namespace> ";
- temp += " <UML:Namespace.ownedElement> <UML:CallEvent xmi.id=\"XDE-79243838-9C4E-4908-9637-9F9583043BE4\" ";
- temp += " operation=\"XDE-C8BD0DBA-E427-41A0-95F4-98FAA920ACA9\" name=\"setBrightnessValue\" ";
- temp += "isSpecification=\"false\"/> </UML:Namespace.ownedElement> </UML:Namespace> ";
- temp += " </UML:ModelElement.namespace> </UML:Event> </UML:Transition.trigger> ";
- (*it).second = temp;
- break;
- case 4:
- temp = "";
- temp += "<UML:Transition.guard> <UML:Guard> <UML:Guard.expression> ";
- temp += "<UML:BooleanExpression body=\"brightnessValue >=0 & brightnessValue<=1000\" language=\"\"/>";
- temp += " </UML:Guard.expression> </UML:Guard> </UML:Transition.guard> <UML:Transition.effect> ";
- temp += " <UML:UninterpretedAction xmi.id=\"XDE-8E3B2DF6-D63B-4A70-9CD3-FF0DE13EEDAD\" ";
- temp += " isAsynchronous=\"false\" name=\"\" isSpecification=\"false\"> <UML:Action.script> ";
- temp += " <UML:ActionExpression language=\"\" body=\"correctedBrightnessValue:=brightnessValue\"/> ";
- temp += " </UML:Action.script> </UML:UninterpretedAction> </UML:Transition.effect> ";
- (*it).second = temp;
- break;
- case 5:
- temp = "";
- temp += "<UML:Transition.guard> <UML:Guard> <UML:Guard.expression> ";
- temp += "<UML:BooleanExpression body=\"brightnessValue<0\" language=\"\"/> ";
- temp += " </UML:Guard.expression> </UML:Guard> </UML:Transition.guard> <UML:Transition.effect> ";
- temp += " <UML:UninterpretedAction xmi.id=\"XDE-0B7A10EB-A9FC-4DE8-BBF1-AF1C9A970E7F\" ";
- temp += " isAsynchronous=\"false\" name=\"\" isSpecification=\"false\"> <UML:Action.script> ";
- temp += " <UML:ActionExpression language=\"\" body=\"correctedBrightnessValue:=0\"/> ";
- temp += " </UML:Action.script> </UML:UninterpretedAction> </UML:Transition.effect> ";
- (*it).second = temp;
- break;
- case 6:
- temp = "";
- temp += "<UML:Transition.guard> <UML:Guard> <UML:Guard.expression> ";
- temp += "<UML:BooleanExpression body=\"brightnessValue>1000\" language=\"\"/> ";
- temp += " </UML:Guard.expression> </UML:Guard> </UML:Transition.guard> <UML:Transition.effect> ";
- temp += " <UML:UninterpretedAction xmi.id=\"XDE-7D6DDE48-7568-4043-B00A-87EFBE1A6CB3\" ";
- temp += " isAsynchronous=\"false\" name=\"\" isSpecification=\"false\"> <UML:Action.script> ";
- temp += " <UML:ActionExpression language=\"\" body=\"correctedBrightnessValue:=1000\"/> ";
- temp += " </UML:Action.script> </UML:UninterpretedAction> </UML:Transition.effect> ";
- (*it).second = temp;
- break;
- case 7:
- temp = "";
- temp += "<UML:Transition.effect> <UML:UninterpretedAction xmi.id=\"XDE-101E5C46-12EA-4169-9DC9-D3661EE9836B\" ";
- temp += "isAsynchronous=\"false\" name="" isSpecification=\"false\"> <UML:Action.script> ";
- temp += " <UML:ActionExpression language=\"\" body=\"^ComputingComponent.setBrightnessValue(brightnessValue)\"/> ";
- temp += " </UML:Action.script> </UML:UninterpretedAction> </UML:Transition.effect> ";
- (*it).second = temp;
- break;
- case 8:
- temp = "";
- temp += "<UML:Transition.trigger> <UML:Event> <UML:ModelElement.namespace> <UML:Namespace> ";
- temp += "<UML:Namespace.ownedElement> <UML:CallEvent xmi.id=\"XDE-7126ED39-5D5D-4160-924B-303514B17EAB\" ";
- temp += " operation=\"XDE-1266DA8A-61C0-43B4-A77C-200F54A6585D\" name=\"getOperationalState\"";
- temp += " isSpecification=\"false\"/> </UML:Namespace.ownedElement> </UML:Namespace> ";
- temp += " </UML:ModelElement.namespace> </UML:Event> </UML:Transition.trigger>";
- (*it).second = temp;
- break;
- case 9:
- temp = "";
- temp += "<UML:Transition.effect> <UML:UninterpretedAction xmi.id=\"XDE-D9BCD8D1-7FC4-4B14-9E76-D3A642799013\"";
- temp += " isAsynchronous=\"false\" name=\"\" isSpecification=\"false\"> <UML:Action.script> ";
- temp += "<UML:ActionExpression language=\"\" body=\"operationalState:=1;^ComputingComponent.ccTRUE\"/> ";
- temp += "</UML:Action.script> </UML:UninterpretedAction> </UML:Transition.effect>";
- (*it).second = temp;
- break;
- case 10:
- temp = "";
- temp += "<UML:Transition.effect> <UML:UninterpretedAction xmi.id=\"XDE-9F00136E-D61D-4BB0-B7D6-1E795238FD1E\"";
- temp += " isAsynchronous=\"false\" name=\"\" isSpecification=\"false\"> <UML:Action.script> ";
- temp += " <UML:ActionExpression language=\"\" body=\"operationalState:=0;^ComputingComponent.ccFALSE\"/> ";
- temp += "</UML:Action.script> </UML:UninterpretedAction> </UML:Transition.effect> ";
- (*it).second = "";
- break;
-
- default:
- (*it).second = " ";
+ trigger_index++;
+ if (trigger_index >= triggers.size()) {
+ trigger_index = 0;
}
- count++;
- }
+ return true;
-/* // This particular set of commented out transitions is designed to test the ability of
- // Avida to evolve the min/max functions that check value.
- // assign transition values to map elements
- std::map <int, std::string>::iterator it;
- std::string temp;
- int count = 0;
+}
- for (it = transGuardActionInfo.begin(); it!=transGuardActionInfo.end(); ++it) {
- switch (count){
- case 0:
- (*it).second = "";
- break;
- case 1:
- temp = "";
- temp += "<UML:Transition.trigger> <UML:Event> <UML:ModelElement.namespace> <UML:Namespace> ";
- temp += "<UML:Namespace.ownedElement> <UML:CallEvent xmi.id=\"XDE-7126ED39-5D5D-4160-924B-303514B17EAB\" ";
- temp += " operation=\"XDE-1266DA8A-61C0-43B4-A77C-200F54A6585D\" name=\"getOperationalState\"";
- temp += " isSpecification=\"false\"/> </UML:Namespace.ownedElement> </UML:Namespace> ";
- temp += " </UML:ModelElement.namespace> </UML:Event> </UML:Transition.trigger>";
- (*it).second = temp;
- break;
- case 2:
- temp = "";
- temp += "<UML:Transition.effect> <UML:UninterpretedAction xmi.id=\"XDE-D9BCD8D1-7FC4-4B14-9E76-D3A642799013\"";
- temp += " isAsynchronous=\"false\" name=\"\" isSpecification=\"false\"> <UML:Action.script> ";
- temp += "<UML:ActionExpression language=\"\" body=\"operationalState:=1;^ComputingComponent.ccTRUE\"/> ";
- temp += "</UML:Action.script> </UML:UninterpretedAction> </UML:Transition.effect>";
- (*it).second = temp;
- break;
- case 3:
- temp = "";
- temp += "<UML:Transition.effect> <UML:UninterpretedAction xmi.id=\"XDE-9F00136E-D61D-4BB0-B7D6-1E795238FD1E\"";
- temp += " isAsynchronous=\"false\" name=\"\" isSpecification=\"false\"> <UML:Action.script> ";
- temp += " <UML:ActionExpression language=\"\" body=\"operationalState:=0;^ComputingComponent.ccFALSE\"/> ";
- temp += "</UML:Action.script> </UML:UninterpretedAction> </UML:Transition.effect> ";
- (*it).second = "";
- break;
- case 4:
- temp = "";
- temp += "<UML:Transition.trigger> <UML:Event> <UML:ModelElement.namespace> <UML:Namespace> ";
- temp += "<UML:Namespace.ownedElement> <UML:CallEvent xmi.id=\"XDE-A28463C5-2F9F-457C-B6F3-241526CA4791\" ";
- temp += " operation=\"XDE-E84A5762-CA92-4E03-A237-FE5AE2C99D9A\" name=\"getBrightnessValue\" ";
- temp += "isSpecification=\"false\"/> </UML:Namespace.ownedElement> </UML:Namespace> ";
- temp += " </UML:ModelElement.namespace> </UML:Event> </UML:Transition.trigger> ";
- (*it).second =temp;
- break;
- case 5:
- temp = "";
- temp += "<UML:Transition.effect> <UML:UninterpretedAction xmi.id=\"XDE-6C3D3042-5C7A-4746-8A90-BEDB86FD2FF4\" ";
- temp += "isAsynchronous=\"false\" name=\"\" isSpecification=\"false\"> <UML:Action.script> ";
- temp += " <UML:ActionExpression language=\"\" body=\"^Environment.getBrightnessValue\"/> ";
- temp += "</UML:Action.script> </UML:UninterpretedAction> </UML:Transition.effect> ";
- (*it).second = temp;
- break;
- case 6:
- temp = "";
- temp += "<UML:Transition.trigger> <UML:Event> <UML:ModelElement.namespace> <UML:Namespace> ";
- temp += " <UML:Namespace.ownedElement> <UML:CallEvent xmi.id=\"XDE-79243838-9C4E-4908-9637-9F9583043BE4\" ";
- temp += " operation=\"XDE-C8BD0DBA-E427-41A0-95F4-98FAA920ACA9\" name=\"setBrightnessValue\" ";
- temp += "isSpecification=\"false\"/> </UML:Namespace.ownedElement> </UML:Namespace> ";
- temp += " </UML:ModelElement.namespace> </UML:Event> </UML:Transition.trigger> ";
- (*it).second = temp;
- break;
- case 7:
- temp = "";
- temp += "<UML:Transition.guard> <UML:Guard> <UML:Guard.expression> ";
- temp += "<UML:BooleanExpression body=\"brightnessValue >=0 & brightnessValue<=1000\" language=\"\"/>";
- temp += " </UML:Guard.expression> </UML:Guard> </UML:Transition.guard> <UML:Transition.effect> ";
- temp += " <UML:UninterpretedAction xmi.id=\"XDE-8E3B2DF6-D63B-4A70-9CD3-FF0DE13EEDAD\" ";
- temp += " isAsynchronous=\"false\" name=\"\" isSpecification=\"false\"> <UML:Action.script> ";
- temp += " <UML:ActionExpression language=\"\" body=\"correctedBrightnessValue:=brightnessValue\"/> ";
- temp += " </UML:Action.script> </UML:UninterpretedAction> </UML:Transition.effect> ";
- (*it).second = temp;
- break;
- case 8:
- temp = "";
- temp += "<UML:Transition.effect> <UML:UninterpretedAction xmi.id=\"XDE-101E5C46-12EA-4169-9DC9-D3661EE9836B\" ";
- temp += "isAsynchronous=\"false\" name="" isSpecification=\"false\"> <UML:Action.script> ";
- temp += " <UML:ActionExpression language=\"\" body=\"^ComputingComponent.setBrightnessValue(brightnessValue)\"/> ";
- temp += " </UML:Action.script> </UML:UninterpretedAction> </UML:Transition.effect> ";
- (*it).second = temp;
- break;
- case 9:
- temp = "";
- temp += "<UML:Transition.guard> <UML:Guard> <UML:Guard.expression> ";
- temp += "<UML:BooleanExpression body=\"brightnessValue<0\" language=\"\"/> ";
- temp += " </UML:Guard.expression> </UML:Guard> </UML:Transition.guard> <UML:Transition.effect> ";
- temp += " <UML:UninterpretedAction xmi.id=\"XDE-0B7A10EB-A9FC-4DE8-BBF1-AF1C9A970E7F\" ";
- temp += " isAsynchronous=\"false\" name=\"\" isSpecification=\"false\"> <UML:Action.script> ";
- temp += " <UML:ActionExpression language=\"\" body=\"correctedBrightnessValue:=0\"/> ";
- temp += " </UML:Action.script> </UML:UninterpretedAction> </UML:Transition.effect> ";
- (*it).second = temp;
- break;
- case 10:
- temp = "";
- temp += "<UML:Transition.guard> <UML:Guard> <UML:Guard.expression> ";
- temp += "<UML:BooleanExpression body=\"brightnessValue>1000\" language=\"\"/> ";
- temp += " </UML:Guard.expression> </UML:Guard> </UML:Transition.guard> <UML:Transition.effect> ";
- temp += " <UML:UninterpretedAction xmi.id=\"XDE-7D6DDE48-7568-4043-B00A-87EFBE1A6CB3\" ";
- temp += " isAsynchronous=\"false\" name=\"\" isSpecification=\"false\"> <UML:Action.script> ";
- temp += " <UML:ActionExpression language=\"\" body=\"correctedBrightnessValue:=1000\"/> ";
- temp += " </UML:Action.script> </UML:UninterpretedAction> </UML:Transition.effect> ";
- (*it).second = temp;
- break;
- default:
- (*it).second = " ";
+bool cOrganism::nextGuard()
+{
+ if (guards.size() == 0) {
+ return false;
}
- count++;
+
+ guard_index++;
+ if (guard_index >= guards.size()) {
+ guard_index = 0;
}
-*/
-}
-
-
-
-bool cOrganism::addTrans(int trans, int orig, int dest)
-{
- NameStateMap::iterator pos1, pos2;
- bool inserted1, inserted2, inserted3;
- bool exists = 0;
- State u, v;
-
-
- // create or find origin state
- tie(pos1, inserted1) = states.insert(std::make_pair(orig, State()));
- if (inserted1) {
- u = add_vertex(uml_state_diagram);
- uml_state_diagram[u].state_label = orig;
- pos1->second = u;
-
- // add to the map between position and label....
- PosToStateLabel[states.size()] = orig;
-
- } else {
- u = pos1->second;
- }
-
- // create or find dest state
- tie(pos2, inserted2) = states.insert(std::make_pair(dest, State()));
- if (inserted2) {
- v = add_vertex(uml_state_diagram);
- uml_state_diagram[v].state_label = dest;
- pos2->second = v;
-
- // add to map betweek positions and label.....
- PosToStateLabel[states.size()] = orig;
-
-
- } else {
- v = pos2->second;
- }
- // call isTrans...
- exists = isTrans(u, v, trans);
- if (exists == 0) {
- tie(transitions, inserted3) = add_edge(u, v, uml_state_diagram);
- if (inserted3) {
- uml_state_diagram[transitions].edge_label = trans;
- uml_state_diagram[transitions].start_state = orig;
- uml_state_diagram[transitions].end_state = dest;
-
- // add trans to table...
- transGuardActionInfo.insert(std::make_pair(trans, ""));
- }
- }
return true;
}
-
-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))
- {
+bool cOrganism::nextAction()
+{
+ if (actions.size() == 0) {
return false;
}
- return (addTrans(trans,orig,dest));
-}
-
-
-// similar to getTransBetweenVertices...
-// optimization candidate perhaps using edge_range as per DBK
-bool cOrganism::isTrans(State u, State v, int trans_name)
-{
- oei e1, e2;
- bool exists = 0;
-
- // check to see if another trans has the same start, dest, and label
- // if so, do not create trans. Else, create trans.
- for (tie(e1, e2) = out_edges(u, uml_state_diagram); e1 != e2; ++e1) {
- if ((target(*e1, uml_state_diagram) == v) && (uml_state_diagram[*e1].edge_label == trans_name)) {
- exists = 1;
- break;
- }
+ action_index++;
+ if (action_index >= actions.size()) {
+ action_index = 0;
}
- return exists;
+ return true;
}
-int cOrganism::getTransNumber (int pos)
+/* int orig_state_index;
+ int dest_state_index;
+ int trans_label_index;*/
+
+bool cOrganism::nextTransitionLabel()
{
- int count = 0;
- int trans_name = -1;
- std::map <int, std::string>::iterator it;
-
- for (it = transGuardActionInfo.begin(); it!=transGuardActionInfo.end(); ++it) {
- if (count == pos){
- trans_name = (*it).first;
- break;
- }
- count++;
+ if (transition_labels.size() == 0) {
+ return false;
}
+ trans_label_index++;
+ if (trans_label_index >= transition_labels.size()) {
+ trans_label_index = 0;
+ }
- return trans_name;
-
+ return true;
}
-bool cOrganism::findTrans(int s0_pos, int s1_pos, int t_pos)
+bool cOrganism::nextOriginState()
{
- int found_entry = 0;
- int trans_name;
-
- trans_name = getTransNumber (t_pos);
-
- if (trans_name == -1) {
- return found_entry;
+ if (total_states == 0) {
+ return false;
}
-
- if ((numStates() <= s0_pos) || (numStates() <= s1_pos)) {
- return found_entry;
+ orig_state_index++;
+ if (orig_state_index >= total_states) {
+ orig_state_index = 0;
}
- cOrganism::State& s0 = getStateInPosition(s0_pos);
- cOrganism::State& s1 = getStateInPosition(s1_pos);
-
- if (isTrans(s0, s1, trans_name)) {
- found_entry = 1;
- }
-
- return found_entry;
-
+ return true;
}
-void cOrganism::printXMI(cAvidaContext& ctx)
+bool cOrganism::nextDestinationState()
{
-
- Graph::vertex_iterator i, iend;
- Graph::edge_iterator e, eend;
-
- int trans_label;
- int dest_state;
- std::string temp, temp1, temp2;
- int tempint;
-
- initTransForMSXMI();
-
- xmi = "";
- // loop through all states
- // print initial information for the init state.
-
- tie(i, iend) = vertices(uml_state_diagram);
-
- 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;
+ if (total_states == 0) {
+ return false;
}
-
-
- for (; i != iend; ++i) {
- temp = "s" + stringifyAnInt(uml_state_diagram[*i].state_label);
- 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";
-
-
-
- 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 = 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. :)
-
- xmi+= "<UML:Transition xmi.id=\"" + temp + "\"";
- xmi+= " source=\"" + temp1 + "\"";
- xmi += " target=\"" + temp2 + "\" name=\"\" isSpecification=\"false\">\n";
-
-
- temp = transGuardActionInfo[trans_label];
- xmi += temp;
-
- xmi += "</UML:Transition>\n";
-
-
+ dest_state_index++;
+ if (dest_state_index >= total_states) {
+ dest_state_index = 0;
}
+ return true;
}
-
-// print the label. Change - signs to _
-std::string cOrganism::stringifyAnInt(int x) {
-
- std::ostringstream o;
-
- if (x < 0) {
- x = abs(x);
- o << "_";
- }
+bool cOrganism::prevTrigger()
+{
+ if (triggers.size() == 0) {
+ return false;
+ }
- o << x;
- return o.str();
+ if (trigger_index <= 0) {
+ trigger_index = triggers.size();
+ }
+ trigger_index--;
+
+ return true;
}
-// return the number of states in a state diagram
-double cOrganism::numStates()
-{
- return (double) num_vertices(uml_state_diagram);
-}
-double cOrganism::numTrans()
-{
- return (double) num_edges(uml_state_diagram);
-}
-double cOrganism::numUniqueTransLabels()
+bool cOrganism::prevGuard()
{
- return transGuardActionInfo.size();
-}
-
-std::string cOrganism::getXMI()
-{
-// std::string temp = xmi_begin + xmi + xmi_end;
-// cout << "PRINT XMI" << endl;
-// cout << temp << endl;
-// cout << "END PRINT XMI" << endl;
- return (xmi_begin + xmi + xmi_end);
-}
-
-// This function takes in an integer and returns the state in that position within the states map. Recall that this
-// map relates integers (the number assigned to a state) to a state in the graph.
-// ... Potential candidate for optimization as per DBK ...
-
-cOrganism::State& cOrganism::getStateInPosition (int num)
-{
- int count = 0;
- // This code uses a value ordering on the states (lowest number = position 0)
- nsm_it i;
- for (i=states.begin(); i!=states.end(); ++i)
- {
- if (count == num) {
- break;
- }
- count++;
+ if (guards.size() == 0) {
+ return false;
}
- return i->second;
+ if (guard_index <= 0) {
+ guard_index = guards.size();
+ }
+ guard_index--;
+
+ return true;
}
-
-
-
-// if you ask for something greater than the number of states then you get the highest numbered state.
-int cOrganism::getStateLabelInPosition (int num)
+bool cOrganism::prevAction()
{
-
- int count = 0;
- // This code uses a value ordering on the states (lowest number = position 0)
- nsm_it i;
- for (i=states.begin(); i!=states.end(); ++i)
- {
- if (count == num) {
- break;
- }
- count++;
+ if (actions.size() == 0) {
+ return false;
}
- return i->first;
-
+ if (action_index <= 0) {
+ action_index = actions.size();
+ }
+ action_index--;
+
+ return true;
}
-
-// if you ask for something greater than the number of trans -- you get the highest numbered one...
-int cOrganism::getTransLabelInPosition (int num)
+bool cOrganism::prevTransitionLabel()
{
- int count = 0;
- tm_it i;
- for (i=transGuardActionInfo.begin(); i!=transGuardActionInfo.end(); ++i)
- {
- if (count == num) {
- break;
- }
- count++;
+ if (transition_labels.size() == 0) {
+ return false;
}
-
- return i->first;
+ if (trans_label_index <= 0) {
+ trans_label_index = transition_labels.size();
+ }
+ trans_label_index--;
+ return true;
}
-cOrganism::Graph& cOrganism::getGraph()
-{
- return uml_state_diagram;
-}
-bool cOrganism::nextTrigger()
+bool cOrganism::prevOriginState()
{
- triggers_it++;
- if (triggers_it == triggers.end()){
- triggers_it = triggers.begin();
+ if (total_states == 0) {
+ return false;
}
+ if (orig_state_index <= 0) {
+ orig_state_index = total_states;
+ }
+ orig_state_index--;
+
+ return true;
}
-bool cOrganism::prevTrigger()
+bool cOrganism::prevDestinationState()
{
- if (triggers_it == triggers.begin()){
- triggers_it = triggers.end();
+ if (total_states == 0) {
+ return false;
+ }
+ if (dest_state_index <= 0) {
+ dest_state_index = total_states;
}
- triggers_it--;
+ dest_state_index--;
+
+ return true;
}
-bool cOrganism::nextGuard()
+std::string cOrganism::getTrigger()
{
- guards_it++;
- if (guards_it == guards.end()){
- guards_it = guards.begin();
+ if (triggers.size() == 0) {
+ return "";
+ } else {
+ return triggers[trigger_index];
}
}
-bool cOrganism::prevGuard()
+std::string cOrganism::getGuard()
{
- if (guards_it == guards.begin()){
- guards_it = guards.end();
- }
- guards_it--;
+ if (guards.size() == 0) {
+ return "";
+ } else {
+ return guards[guard_index];
+ }
}
-bool cOrganism::nextAction()
-{
- actions_it++;
- if (actions_it == actions.end()){
- actions_it = actions.begin();
+std::string cOrganism::getAction()
+{
+ if (actions.size() == 0) {
+ return "";
+ } else {
+ return actions[action_index];
}
}
-bool cOrganism::prevAction()
+int cOrganism::getOrigState()
{
- if (actions_it == actions.begin()){
- actions_it = actions.end();
- }
- actions_it--;
+ return orig_state_index;
}
-
-std::string cOrganism::getTrigger()
+
+int cOrganism::getDestState()
{
- std::string tmp;
- if (triggers.size() > 0) {
- tmp = *triggers_it;
- } else {
- tmp = "";
- }
- return tmp;
+ return dest_state_index;
}
-std::string cOrganism::getGuard()
+transition_label cOrganism::getTransLabel()
{
- std::string tmp;
- if (guards.size() > 0) {
- tmp = *guards_it;
- } else {
- tmp = "";
- }
- return tmp;
+ return transition_labels[trans_label_index];
}
-std::string cOrganism::getAction()
+// State manipulation
+bool cOrganism::addState()
{
- std::string tmp;
- if (actions.size() > 0) {
- tmp = *actions_it;
- } else {
- tmp = "";
+ total_states++;
+ // if this is the first state, point the orig and dest state indices to it
+ if (total_states == 1) {
+ orig_state_index = 0;
+ dest_state_index = 0;
}
- return tmp;
+ return true;
}
-bool cOrganism::crTransLabel()
+bool cOrganism::addTransitionLabel()
{
-// 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);
+ transition_label t;
+ t.trigger = getTrigger();
+ t.guard = getGuard();
+ t.action = getAction();
+
+ transition_labels.push_back(t);
+
return true;
}
-bool cOrganism::isTransLabel(std::string desired_lab)
+
+bool cOrganism::addTransition()
{
- 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;
- }
+ if ((total_states == 0) || (transition_labels.size() == 0)) {
+ return false;
}
- return false;
+
+ transition t;
+ t.orig_state = getOrigState();
+ t.dest_state = getDestState();
+ t.trans = getTransLabel();
+
+ transitions.push_back(t);
+ return true;
+
}
+void cOrganism::printXMI(cAvidaContext& ctx)
+{
+ return;
+}
+
+
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-26 00:15:44 UTC (rev 1368)
+++ branches/uml/source/main/cOrganism.h 2007-02-26 01:09:12 UTC (rev 1369)
@@ -19,11 +19,11 @@
#include <vector>
//#include <boost/config.hpp>
//#include <boost/graph/edge_list.hpp>
-#include <boost/graph/adjacency_list.hpp>
-#include <boost/graph/graph_utility.hpp>
+//#include <boost/graph/adjacency_list.hpp>
+//#include <boost/graph/graph_utility.hpp>
//#include <boost/graph/filtered_graph.hpp>
-#include <boost/graph/connected_components.hpp>
-using namespace boost;
+//#include <boost/graph/connected_components.hpp>
+//using namespace boost;
@@ -86,39 +86,24 @@
class cEnvironment;
class cCodeLabel;
-// structures used to label vertices and edges
-struct edge_info {
- int edge_label;
- std::string edge_info;
- int start_state;
- int end_state;
+//
+
+struct transition_label {
+ std::string trigger;
+ std::string guard;
+ std::string action;
};
-struct state_info {
- int state_label;
+struct transition {
+ int orig_state;
+ int dest_state;
+ transition_label trans;
};
+
class cOrganism
{
-public:
-
-//!Types of the UML types for states and transitions
-// define graph -- multisetS - allows for the sorting of out edges by target vertex
-//bidirectionalS
-//typedef adjacency_list<multisetS, vecS, directedS, state_info, edge_info> Graph;
-typedef adjacency_list<multisetS, vecS, bidirectionalS, state_info, edge_info> Graph;
-// map the graph's vertex's to their descriptors
-typedef graph_traits<Graph>::vertex_descriptor State;
-typedef std::map<int, State> NameStateMap;
-typedef NameStateMap::iterator nsm_it;
-// A map from the integer representing a transition to the string representing its label
-typedef std::map<int, std::string> TransMeaning;
-typedef TransMeaning::iterator tm_it;
-// map the graph's edge's to their descriptors
-typedef graph_traits<Graph>::edge_descriptor Transition;
-typedef graph_traits<Graph>::out_edge_iterator oei;
-
protected:
cWorld* m_world;
@@ -159,29 +144,27 @@
tBuffer<cOrgMessage> sent;
// 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; // 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;
+ std::vector<transition> transitions;
+ std::vector<transition_label> transition_labels;
+ int total_states;
+ int orig_state_index;
+ int dest_state_index;
+ int trans_label_index;
+ int trigger_index;
+ int guard_index;
+ int action_index;
-
-
-
-
-
class cNetSupport
{
public:
@@ -252,49 +235,38 @@
// UML Stuff
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);
- std::string getXMI();
-
- // helper functions
- std::string stringifyAnInt (int x);
- void initTransForMSXMI();
- void initTransForBSXMI();
+// The next functions increment the index of the various vectors.
bool nextTrigger();
bool prevTrigger();
bool nextGuard();
+ bool nextTransitionLabel();
+ bool nextOriginState();
+ bool nextDestinationState();
+
+// The previous functions decrement the index of the various vectors.
bool prevGuard();
bool nextAction();
bool prevAction();
+ bool prevTransitionLabel();
+ bool prevOriginState();
+ bool prevDestinationState();
+
+// The get functions get the value of the index of various vectors
std::string getTrigger();
std::string getGuard();
std::string getAction();
+ transition_label getTransLabel();
+ int getOrigState();
+ int getDestState();
-
+// Add functions
+ bool addState();
+ bool addTransitionLabel();
+ bool addTransition();
-// NameStateMap::iterator pos;
-
-
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/cStats.cc
===================================================================
--- branches/uml/source/main/cStats.cc 2007-02-26 00:15:44 UTC (rev 1368)
+++ branches/uml/source/main/cStats.cc 2007-02-26 01:09:12 UTC (rev 1369)
@@ -880,6 +880,7 @@
df.Endl();
}
+/*
void cStats::UpdateModelStats (cOrganism::Graph& g)
{
@@ -887,6 +888,6 @@
av_number_of_trans.Add(num_edges(g));
}
+*/
-
Modified: branches/uml/source/main/cStats.h
===================================================================
--- branches/uml/source/main/cStats.h 2007-02-26 00:15:44 UTC (rev 1368)
+++ branches/uml/source/main/cStats.h 2007-02-26 01:09:12 UTC (rev 1369)
@@ -542,7 +542,7 @@
// UML Data Function
- void UpdateModelStats (cOrganism::Graph& g);
+// void UpdateModelStats (cOrganism::Graph& g);
void HydraAttempt() { ++m_hydraAttempt; }
void HydraPassed() { ++m_hydraPassed; }
void SpinAttempt() { ++m_spinAttempt; }
Modified: branches/uml/source/main/cTaskLib.cc
===================================================================
--- branches/uml/source/main/cTaskLib.cc 2007-02-26 00:15:44 UTC (rev 1368)
+++ branches/uml/source/main/cTaskLib.cc 2007-02-26 01:09:12 UTC (rev 1369)
@@ -331,57 +331,7 @@
NewTask(name, "Successfully Received Network Message", &cTaskLib::Task_NetReceive);
// UML tasks
- if (name == "uml_ns")
- NewTask(name, "Successfully Created the right number of states", &cTaskLib::Task_NumberOfState);
- else if (name == "uml_nt")
- NewTask(name, "Successfully Created the right number of transitions", &cTaskLib::Task_NumberOfTrans);
- else if (name == "uml_hy")
- NewTask(name, "Ran Hydra... Returning bonus proportional to the number of errors", &cTaskLib::Task_Hydra);
- else if (name == "uml_tr_ms0")
- NewTask(name, "Successfully Created transition 0", &cTaskLib::Task_Transition_ms0);
- else if (name == "uml_tr_ms1")
- NewTask(name, "Successfully Created transition 1", &cTaskLib::Task_Transition_ms1);
- else if (name == "uml_tr_ms2")
- NewTask(name, "Successfully Created transition 2", &cTaskLib::Task_Transition_ms2);
- else if (name == "uml_tr_ms3")
- NewTask(name, "Successfully Created transition 3", &cTaskLib::Task_Transition_ms3);
- else if (name == "uml_tr_ms4")
- NewTask(name, "Successfully Created transition 4", &cTaskLib::Task_Transition_ms4);
- else if (name == "uml_tr_ms5")
- NewTask(name, "Successfully Created transition 5", &cTaskLib::Task_Transition_ms5);
- else if (name == "uml_tr_bs0")
- NewTask(name, "Successfully Created transition 0", &cTaskLib::Task_Transition_bs0);
- else if (name == "uml_tr_bs1")
- NewTask(name, "Successfully Created transition 1", &cTaskLib::Task_Transition_bs1);
- else if (name == "uml_tr_bs2")
- NewTask(name, "Successfully Created transition 2", &cTaskLib::Task_Transition_bs2);
- else if (name == "uml_tr_bs3")
- NewTask(name, "Successfully Created transition 3", &cTaskLib::Task_Transition_bs3);
- else if (name == "uml_tr_bs4")
- NewTask(name, "Successfully Created transition 4", &cTaskLib::Task_Transition_bs4);
- else if (name == "uml_tr_bs5")
- NewTask(name, "Successfully Created transition 5", &cTaskLib::Task_Transition_bs5);
- else if (name == "uml_tr_bs6")
- NewTask(name, "Successfully Created transition 6", &cTaskLib::Task_Transition_bs6);
- else if (name == "uml_tr_bs7")
- NewTask(name, "Successfully Created transition 7", &cTaskLib::Task_Transition_bs7);
- else if (name == "uml_tr_bs8")
- NewTask(name, "Successfully Created transition 8", &cTaskLib::Task_Transition_bs8);
- else if (name == "uml_tr_bs9")
- NewTask(name, "Successfully Created transition 9", &cTaskLib::Task_Transition_bs9);
- else if (name == "uml_tr_bs10")
- 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);
-*/
+
// Make sure we have actually found a task
if (task_array.GetSize() == start_size) {
@@ -1887,461 +1837,3 @@
return 0.0;
}
-
-
-
-// Count the number of states. Give rewards for upto 7. 7 is the number the brightness sensor needs...
-double cTaskLib::Task_NumberOfState(cTaskContext* ctx) const
-{
- cOrganism* organism = ctx->organism;
- double bonus = 0.0;
- double numStates = organism->numStates();
-
- // reward for constructing 7 states - brightness sensor
- if (organism->numStates() <= 7) {
- bonus += numStates;
- //bonus = 1.0;
- } /*else {
-
- bonus = (7 - (numStates - 7));
- }*/
-
- return bonus;
-}
-
-double cTaskLib::Task_NumberOfTrans(cTaskContext* ctx) const
-{
- cOrganism* organism = ctx->organism;
- double bonus = 0.0;
- double numTrans = organism->numTrans();
-
- // reward for constructing 11 trans - brightness sensor
- if (organism->numTrans() <= 11) {
- bonus += numTrans;
- //bonus = 1.0;
- } /*else {
-
- bonus = (11 - (numTrans -11));
-
- }*/
-
- return bonus;
-}
-
-/*
-
-The following tasks check for the graph topology of the multisensor
-
-*/
-double cTaskLib::Task_Transition_ms0(cTaskContext* ctx) const
-{
- double bonus = 0.0;
-
- if (ctx->organism->findTrans(0, 1, 0)) {
- bonus = 1.0;
- }
- ctx->task_failed = ctx->task_failed && bonus;
- return bonus;
-}
-
-double cTaskLib::Task_Transition_ms1(cTaskContext* ctx) const
-{
- double bonus = 0.0;
-
- if (ctx->organism->findTrans(1, 2, 1)) {
-
- bonus = 1.0;
- }
- ctx->task_failed = ctx->task_failed && bonus;
- return bonus;
-}
-
-
-double cTaskLib::Task_Transition_ms2(cTaskContext* ctx) const
-{
- double bonus = 0.0;
-
- if (ctx->organism->findTrans(2, 3, 2)) {
-
-
- bonus = 1.0;
- }
-
- ctx->task_failed = ctx->task_failed && bonus;
- return bonus;
-}
-
-double cTaskLib::Task_Transition_ms3(cTaskContext* ctx) const
-{
- double bonus = 0.0;
-
- if (ctx->organism->findTrans(3, 1, 3)) {
-
- bonus = 1.0;
- }
-
- ctx->task_failed = ctx->task_failed && bonus;
- return bonus;
-}
-
-double cTaskLib::Task_Transition_ms4(cTaskContext* ctx) const
-{
- double bonus = 0.0;
-
- //if (ctx->organism->findTrans(1, 4, 4)) {
- if (ctx->organism->numUniqueTransLabels() > 4) {
-
- bonus = 1.0;
- }
-
- ctx->task_failed = ctx->task_failed && bonus;
- return bonus;
-}
-
-double cTaskLib::Task_Transition_ms5(cTaskContext* ctx) const
-{
- double bonus = 0.0;
-
- if (ctx->organism->findTrans(4, 1, 5)){
- bonus = 1.0;
- }
-
- ctx->task_failed = ctx->task_failed && bonus;
- return bonus;
-}
-
-
-/*
-The following tasks check for the graph topology of the brightness sensor.
-The order of the transitions has been changed from the original runs to enable the min/max
-transitions to come last. The objective is to enable Avida to evolve these using Spin/Hydra.
-
-*/
-double cTaskLib::Task_Transition_bs0(cTaskContext* ctx) const
-{
- double bonus = 0.0;
-
- if (ctx->organism->findTrans(0, 1, 0)) {
- bonus = 1.0;
- }
- ctx->task_failed = ctx->task_failed && bonus;
- return bonus;
-}
-
-double cTaskLib::Task_Transition_bs1(cTaskContext* ctx) const
-{
- double bonus = 0.0;
-
-
- if (ctx->organism->findTrans(1, 2, 1)) {
-
- bonus = 1.0;
- }
- ctx->task_failed = ctx->task_failed && bonus;
- return bonus;
-}
-
-
-double cTaskLib::Task_Transition_bs2(cTaskContext* ctx) const
-{
- double bonus = 0.0;
-
- // when min/max/set are at end
- //if (ctx->organism->findTrans(2, 1, 2)) {
-
- // when opset is at end
- if (ctx->organism->findTrans(2, 3, 2)) {
-
- bonus = 1.0;
- }
-
- ctx->task_failed = ctx->task_failed && bonus;
- return bonus;
-}
-
-double cTaskLib::Task_Transition_bs3(cTaskContext* ctx) const
-{
- double bonus = 0.0;
-
- // when min/max/set are at end
- //if (ctx->organism->findTrans(2, 1, 3)) {
-
- // when opset is at end
- if (ctx->organism->findTrans(3, 4, 3)) {
-
-
- bonus = 1.0;
- }
-
- ctx->task_failed = ctx->task_failed && bonus;
- return bonus;
-}
-
-double cTaskLib::Task_Transition_bs4(cTaskContext* ctx) const
-{
- double bonus = 0.0;
-
- // when min/max/set are at end
- //if (ctx->organism->findTrans(1, 3, 4)) {
-
- // when opset is at end
- if (ctx->organism->findTrans(4, 5, 4)) {
- bonus = 1.0;
- }
-
- ctx->task_failed = ctx->task_failed && bonus;
- return bonus;
-}
-
-double cTaskLib::Task_Transition_bs5(cTaskContext* ctx) const
-{
- double bonus = 0.0;
-
- // when min/max/set are at end
- // if (ctx->organism->findTrans(3, 4, 5)) {
-
- // when opset is at end
- if (ctx->organism->findTrans(4, 5, 5)) {
- bonus = 1.0;
- }
-
- ctx->task_failed = ctx->task_failed && bonus;
- return bonus;
-}
-
-double cTaskLib::Task_Transition_bs6(cTaskContext* ctx) const
-{
- double bonus = 0.0;
-
- // when min/max/set are at end
- // if (ctx->organism->findTrans(4, 5, 6)) {
-
- // when opset is at end
- if (ctx->organism->findTrans(4, 5, 6)) {
- bonus = 1.0;
- }
-
- ctx->task_failed = ctx->task_failed && bonus;
- return bonus;
-}
-
-double cTaskLib::Task_Transition_bs7(cTaskContext* ctx) const
-{
- double bonus = 0.0;
-
- // This has been modified to check if the 7th transition is present... we don't care
- // where it is in the model. This is enough to cause the property check to fail.
- //if (ctx->organism->findTrans(5, 6, 7)) {
-
- // when min/max/set are at end
- //if (ctx->organism->NumStates() > 7) {
-
- // when opset is at end
- if (ctx->organism->findTrans(5, 1, 7)) {
-
- bonus = 1.0;
- }
-
- ctx->task_failed = ctx->task_failed && bonus;
- return bonus;
-}
-
-double cTaskLib::Task_Transition_bs8(cTaskContext* ctx) const
-{
- double bonus = 0.0;
-
- // when min/max/set are at end
- // if (ctx->organism->findTrans(6, 1, 8)) {
- if (ctx->organism->numStates() > 8) {
- bonus = 1.0;
- }
-
- ctx->task_failed = ctx->task_failed && bonus;
- return bonus;
-}
-
-double cTaskLib::Task_Transition_bs9(cTaskContext* ctx) const
-{
- double bonus = 0.0;
-
- // when min/max/set are at end
- if (ctx->organism->findTrans(5, 6, 9)) {
- bonus = 1.0;
- }
-
- ctx->task_failed = ctx->task_failed && bonus;
- return bonus;
-}
-
-double cTaskLib::Task_Transition_bs10(cTaskContext* ctx) const
-{
- double bonus = 0.0;
-
- // when min/max/set are at end
- if (ctx->organism->findTrans(5, 6, 10)) {
- bonus = 1.0;
- }
-
- ctx->task_failed = ctx->task_failed && bonus;
- 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;
-
-/* if (organism->isConnected() == 0) {
- ctx->task_failed = 0;
- return 0;
- }
-*/
-
- if (ctx->task_failed == 0) {
- return 0;
- }
-
-
- m_world->GetStats().HydraAttempt();
-
- double bonus = 0.0;
- std::string temp;
- unsigned int status_total = 0;
- int status=0;
-
- int to_subavida[2]={0};
- int from_subavida[2]={0};
-
- pipe(to_subavida); //write to 1, read from 0
- pipe(from_subavida);
-
- pid_t subavida = fork();
- if(subavida == 0) {
- //child
- close(to_subavida[1]);
- close(from_subavida[0]);
- dup2(to_subavida[0], STDIN_FILENO); //oldd, newd
- dup2(from_subavida[1], STDOUT_FILENO);
- execl("/usr/bin/java", "-cp .", "-jar", "./hydraulic.jar", NULL);
- // We don't ever get here.
- }
- //parent
- close(to_subavida[0]);
- close(from_subavida[1]);
-
- // At this point, forget about subavida - It's running.
- // Write the model to to_subavida[1]. Close to_subavida[1] (which wakes up subavida).
- // 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) {
- break;
- } else {
- status_total += status;
- }
- } while (status_total < temp.size());
- close(to_subavida[1]); // Wakes up subavida.
-
- // Time passes...
-
- // Read the output from subavida. Keep reading until subavida closes the pipe.
- const int read_size=128; // The number of bytes that we're going to try to read from subavida.
- std::string subavida_output;
- char line[read_size]={0};
- do {
- status = read(from_subavida[0], line, read_size-1);
- if(status > 0) {
- subavida_output += line;
- memset(line, 0, read_size);
- }
- } while(((status==-1) && (errno == EINTR)) || (status>0));
- // Done with subavida.
- close(from_subavida[0]);
- // Make sure that subavida dies.
- pid_t done=0;
- while((done=waitpid(subavida, &status, 0))==-1 && (errno == EINTR));
- assert(done==subavida);
-
- // if there are no errors, return 0 from hydraulic. otherwise, return non-zero.
- if(status != 0) {
- ctx->task_failed = 0;
- return 0.0;
- } else {
- ctx->task_failed = ctx->task_failed && 1;
- m_world->GetStats().HydraPassed();
- return 1.0;
- }
-}
-
-double cTaskLib::SpinCoprocess(cTaskContext* ctx, const std::string& neverclaimFile) const {
- cOrganism* organism = ctx->organism;
- m_world->GetStats().SpinAttempt();
- int status=0;
- std::string cmd = "cat " + neverclaimFile + " >> tmp.pr && ./spin -a tmp.pr &> /dev/null";
- if(system(cmd.c_str())!=0) return 0.0;
- m_world->GetStats().SpinPassed();
- m_world->GetStats().PanAttempt();
- //-e -n -a -w19 -m100000 -c1
-// if(system("/usr/bin/gcc pan.c -e -o pan &> /dev/null")!=0) return 0.0;
-// if(system("./pan -a &> ./pan.out")!=0) return 0.0;
-// -DMEMLIM=256
- 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;
- //cmd = "cp tmp.xmi " + organism->GetGenotype()->GetID() + ".xml";
-
-// if(organism->GetGenotype() != NULL) {
- std::ostringstream strstrm;
- strstrm << "cp tmp.xmi " << m_world->GetStats().GetUpdate() << "." << organism->GetID();
- // << "." + organism->GetID() << ".xml";
- //strstrm << "." << organism->GetGenotype()->GetID();
- strstrm << ".xml";
- if(system(strstrm.str().c_str())!=0) return 0.0;
-// }
-
- m_world->GetStats().PanPassed();
- return 3.0;
-}
-
-double cTaskLib::Task_SpinN1(cTaskContext* ctx) const {
- if (ctx->task_failed) {
- return SpinCoprocess(ctx, "N1");
- }
- return 0.0;
-}
Modified: branches/uml/source/main/cTaskLib.h
===================================================================
--- branches/uml/source/main/cTaskLib.h 2007-02-26 00:15:44 UTC (rev 1368)
+++ branches/uml/source/main/cTaskLib.h 2007-02-26 01:09:12 UTC (rev 1369)
@@ -231,35 +231,7 @@
double Task_NetReceive(cTaskContext* ctx) const;
// UML Tasks...
-// double Task_CreateStates(cTaskContext* ctx) const;
-// double Task_CreateTransX(cTaskContext* ctx) const;
-// double Task_CreateTranss(cTaskContext* ctx) const;
- double Task_NumberOfState(cTaskContext* ctx) const;
- double Task_NumberOfTrans(cTaskContext* ctx) const;
- double Task_Hydra(cTaskContext* ctx) const;
- double Task_Transition_ms0(cTaskContext* ctx) const;
- double Task_Transition_ms1(cTaskContext* ctx) const;
- double Task_Transition_ms2(cTaskContext* ctx) const;
- double Task_Transition_ms3(cTaskContext* ctx) const;
- double Task_Transition_ms4(cTaskContext* ctx) const;
- double Task_Transition_ms5(cTaskContext* ctx) const;
- double Task_Transition_bs0(cTaskContext* ctx) const;
- double Task_Transition_bs1(cTaskContext* ctx) const;
- double Task_Transition_bs2(cTaskContext* ctx) const;
- double Task_Transition_bs3(cTaskContext* ctx) const;
- double Task_Transition_bs4(cTaskContext* ctx) const;
- double Task_Transition_bs5(cTaskContext* ctx) const;
- double Task_Transition_bs6(cTaskContext* ctx) const;
- double Task_Transition_bs7(cTaskContext* ctx) const;
- 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