[Avida-SVN] r1125 - in branches/uml: Avida.xcodeproj source/cpu source/main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Mon Dec 11 19:18:46 PST 2006
Author: hjg
Date: 2006-12-11 22:18:46 -0500 (Mon, 11 Dec 2006)
New Revision: 1125
Modified:
branches/uml/Avida.xcodeproj/project.pbxproj
branches/uml/source/cpu/cHardwareCPU.cc
branches/uml/source/main/cOrganism.cc
branches/uml/source/main/cOrganism.h
branches/uml/source/main/cTaskLib.cc
Log:
Reimplement the get-state and get-trans instructions to use nops, rather than ints in registers to index a state and transition. Also, added the ability to parse Hydra output.
Modified: branches/uml/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/uml/Avida.xcodeproj/project.pbxproj 2006-12-12 01:09:58 UTC (rev 1124)
+++ branches/uml/Avida.xcodeproj/project.pbxproj 2006-12-12 03:18:46 UTC (rev 1125)
@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
+ 3E475AE00B2D01720022BCFB /* libboost_regex.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E475ADF0B2D01720022BCFB /* libboost_regex.a */; };
7005A70609BA0FA90007E16E /* cTestCPUInterface.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7005A70209BA0FA90007E16E /* cTestCPUInterface.cc */; };
7005A70809BA0FA90007E16E /* cTestCPUInterface.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7005A70209BA0FA90007E16E /* cTestCPUInterface.cc */; };
7005A83209BA621F0007E16E /* cOrgMessage.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70B0868808F49EA800FC65FE /* cOrgMessage.cc */; };
@@ -294,6 +295,7 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
+ 3E475ADF0B2D01720022BCFB /* libboost_regex.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libboost_regex.a; path = /opt/local/lib/libboost_regex.a; sourceTree = "<absolute>"; };
7005A70109BA0FA90007E16E /* cTestCPUInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cTestCPUInterface.h; sourceTree = "<group>"; };
7005A70209BA0FA90007E16E /* cTestCPUInterface.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cTestCPUInterface.cc; sourceTree = "<group>"; };
7005A70909BA0FBE0007E16E /* cOrgInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cOrgInterface.h; sourceTree = "<group>"; };
@@ -817,6 +819,7 @@
buildActionMask = 2147483647;
files = (
70DCF66C09D4DE6500924128 /* libtcmalloc.a in Frameworks */,
+ 3E475AE00B2D01720022BCFB /* libboost_regex.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1161,6 +1164,7 @@
DCC30C490762532C008F7A48 = {
isa = PBXGroup;
children = (
+ 3E475ADF0B2D01720022BCFB /* libboost_regex.a */,
DCC30C670762539A008F7A48 /* Main Source */,
70920C1A0A9CCE2C00757CDB /* Documentation */,
707AF2D209EE8501001AEA89 /* Support */,
@@ -1936,6 +1940,7 @@
isa = XCBuildConfiguration;
buildSettings = {
GCC_MODEL_CPU = G4;
+ LIBRARY_SEARCH_PATHS = /opt/local/lib;
OTHER_LDFLAGS = (
"-multiply_defined",
suppress,
@@ -1948,6 +1953,7 @@
isa = XCBuildConfiguration;
buildSettings = {
GCC_MODEL_CPU = G4;
+ LIBRARY_SEARCH_PATHS = /opt/local/lib;
OTHER_LDFLAGS = (
"-multiply_defined",
suppress,
@@ -2069,6 +2075,7 @@
isa = XCBuildConfiguration;
buildSettings = {
GCC_MODEL_CPU = G4;
+ LIBRARY_SEARCH_PATHS = /opt/local/lib;
OTHER_LDFLAGS = (
"-multiply_defined",
suppress,
@@ -2081,6 +2088,7 @@
isa = XCBuildConfiguration;
buildSettings = {
GCC_MODEL_CPU = G4;
+ LIBRARY_SEARCH_PATHS = /opt/local/lib;
OTHER_LDFLAGS = (
"-multiply_defined",
suppress,
@@ -2196,6 +2204,7 @@
isa = XCBuildConfiguration;
buildSettings = {
GCC_MODEL_CPU = G4;
+ LIBRARY_SEARCH_PATHS = /opt/local/lib;
OTHER_LDFLAGS = (
"-multiply_defined",
suppress,
Modified: branches/uml/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.cc 2006-12-12 01:09:58 UTC (rev 1124)
+++ branches/uml/source/cpu/cHardwareCPU.cc 2006-12-12 03:18:46 UTC (rev 1125)
@@ -3489,32 +3489,74 @@
bool cHardwareCPU::Inst_GetState(cAvidaContext& ctx)
{
+
+ ReadLabel();
+ GetLabel();
+
+ int state_pos = GetLabel().AsInt(1);
+// cString a = GetLabel().AsString();
+
+/*
+ a.ClipFront(<#int size#>)
+ if (a == "A") {
+ a = "a";
+ }
+
+*/
+
+ // 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 label = organism->getStateLabelInPosition(state_pos);
+ 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) = label;
- GetRegister(FindNextRegister(reg_used)) = label;
+// 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
+/* // get the state indexed by the number in
int reg_used = FindModifiedRegister(REG_AX);
- int trans_pos = GetRegister(reg_used);
+ int trans_pos = GetRegister(reg_used);*/
+ ReadLabel();
+ GetLabel();
+
+ int trans_pos = GetLabel().AsInt(1);
+
if ((trans_pos >= 0) && (trans_pos < organism->NumTrans())) {
int label = organism->getTransLabelInPosition(trans_pos);
// put value into register...
- GetRegister(FindNextRegister(reg_used)) = label;
+ GetRegister(REG_AX) = label;
}
return true;
Modified: branches/uml/source/main/cOrganism.cc
===================================================================
--- branches/uml/source/main/cOrganism.cc 2006-12-12 01:09:58 UTC (rev 1124)
+++ branches/uml/source/main/cOrganism.cc 2006-12-12 03:18:46 UTC (rev 1125)
@@ -33,10 +33,30 @@
#include <iomanip>
+#include <fstream>
using namespace std;
+std::string loadFile(const char* filename) {
+ std::string data, line; // or maybe stringstream? (strstream?)
+ std::ifstream infile;
+ infile.open(filename);
+ assert(infile.is_open());
+
+ while (getline (infile, line))
+ {
+ data.append(line);
+ line.erase();
+ }
+
+ //read from file; load into string/strstream, and return it.
+ return data;
+}
+std::string cOrganism::hil_begin = loadFile("hil_begin");
+std::string cOrganism::hil_end = loadFile("hil_end");
+
+
cOrganism::cOrganism(cWorld* world, cAvidaContext& ctx, const cGenome& in_genome)
: m_world(world)
, genotype(NULL)
@@ -81,9 +101,7 @@
if (m_world->GetConfig().NET_ENABLED.Get()) m_net = new cNetSupport();
m_id = m_world->GetStats().GetTotCreatures();
- // UML
- // initialize the hil string values
- InitHILBandE();
+
}
@@ -472,96 +490,6 @@
}
-/*
-void cOrganism::printXMI(cAvidaContext& ctx)
-{
-
-// UML pretty print part....
- std::set<int>::iterator it_st_start;
- std::set<int>::iterator it_st_end;
- std::set<int>::iterator i;
-
-
- it_st_start = uml_state_set.begin();
- it_st_end = uml_state_set.end();
- int count;
-
- // print state XMI information
- cout << "<UML:StateMachine xmi.id=\"XDE-BACD03B9-FA04-4C7F-B464-748CB92A47B2\"";
- cout << "name=\"StateMachine1\" isSpecification=\"false\">" << endl;
- cout << "<UML:StateMachine.top>" << endl;
- cout << "<UML:CompositeState xmi.id=\"XDE-3C5902C0-E8A6-4E0C-88D5-4ACB7E0EDF15\"";
- cout << "isConcurrent=\"false\" name=\"TOP\" isSpecification=\"false\">" << endl;
- cout << "<UML:CompositeState.subvertex>" << endl;
-
- for(i = it_st_start; i!=it_st_end; ++i){
- if (i == it_st_start) {
- // initial state
-// cout << "<UML:Pseudostate xmi.id=\"" << *i << "\" kind=\"initial\" outgoing=\"\"";
- cout << "<UML:Pseudostate xmi.id=\"" << *i << "\" kind=\"initial\" ";
- cout << "name=\"\" isSpecification=\"false\"/>" << endl;
-
- } else {
-// cout << "<UML:CompositeState xmi.id=\"" << *i << "\" isConcurrent=\"false\" outgoing=\"\" name=\"";
- cout << "<UML:CompositeState xmi.id=\"" << *i << "\" isConcurrent=\"false\" name=\"";
- cout << *i << "\" isSpecification=\"false\"/>" << endl;
- }
- }
- cout << "</UML:CompositeState.subvertex>" << endl;
- cout << "</UML:CompositeState>" << endl;
- cout << "</UML:StateMachine.top>" << endl;
-
-
- count = 0;
- cout << "<UML:StateMachine.transitions>" << endl;
- for (t_transitionMap::iterator it = uml_transitions.begin(); it != uml_transitions.end(); ++it) {
- cout << "<UML:Transition xmi.id=\"" << (*it).first << "\" source=\"" << (*it).second.first;
- cout << "\" target=\"" << (*it).second.second << "\" name=\"" << (*it).first;
- cout << "\" isSpecification=\"false\">" << endl;
-
- if (trans_info.size() > count) {
- cout << trans_info[count] << endl;
- }
- cout << "</UML:Transition>" << endl;
-
- count ++;
- }
-
- cout << "</UML:StateMachine.transitions>" << endl;
- cout << "</UML:StateMachine>" << endl;
-
-// end of UML pretty printing...
-
-}
-
-
-void cOrganism::InitTransForXMI()
-{
- // 0 - init state to state 1
- trans_info.push_back("");
- // 1 - state 1 to state 2 - getOperationalState()
- trans_info.push_back("<UML:Transition.trigger> <UML:Event> <UML:ModelElement.namespace> <UML:Namespace> <UML:Namespace.ownedElement> <UML:CallEvent xmi.id=\"XDE-7126ED39-5D5D-4160-924B-303514B17EAB\" operation=\"XDE-1266DA8A-61C0-43B4-A77C-200F54A6585D\" name=\"getOperationalState\" isSpecification=\"false\"/> </UML:Namespace.ownedElement></UML:Namespace> </UML:ModelElement.namespace> </UML:Event> </UML:Transition.trigger> ");
- // 2 - state 2 to state 1 - opState = True
- trans_info.push_back("<UML:Transition.effect> <UML:UninterpretedAction xmi.id=\"XDE-D9BCD8D1-7FC4-4B14-9E76-D3A642799013\" isAsynchronous=\"false\" name=\"\" isSpecification=\"false\"> <UML:Action.script> <UML:ActionExpression language=\"\" body=\"operationalState:=1;^ComputingComponent.ccTRUE\"/>` </UML:Action.script> </UML:UninterpretedAction> </UML:Transition.effect>");
- // 3 - state 2 to state 1 - opState = False
- trans_info.push_back ("<UML:Transition.effect> <UML:UninterpretedAction xmi.id=\"XDE-9F00136E-D61D-4BB0-B7D6-1E795238FD1E\" isAsynchronous=\"false\" name=\"\" isSpecification=\"false\"> <UML:Action.script> <UML:ActionExpression language=\"\" body=\"operationalState:=0;^ComputingComponent.ccFALSE\"/> </UML:Action.script> </UML:UninterpretedAction> </UML:Transition.effect>");
- // 4 - state 1 to state 3 - getBrightnessValue()
- trans_info.push_back ("<UML:Transition.trigger> <UML:Event> <UML:ModelElement.namespace> <UML:Namespace> <UML:Namespace.ownedElement> <UML:CallEvent xmi.id=\"XDE-A28463C5-2F9F-457C-B6F3-241526CA4791\" operation=\"XDE-E84A5762-CA92-4E03-A237-FE5AE2C99D9A\" name=\"getBrightnessValue\" isSpecification=\"false\"/> </UML:Namespace.ownedElement> </UML:Namespace> </UML:ModelElement.namespace> </UML:Event> </UML:Transition.trigger>");
- // 5 - state 3 to state 4 - Environment.getBrightnessValue();
- trans_info.push_back ("<UML:Transition.effect> <UML:UninterpretedAction xmi.id=\"XDE-6C3D3042-5C7A-4746-8A90-BEDB86FD2FF4\" isAsynchronous=\"false\" name=\"\" isSpecification=\"false\"> <UML:Action.script> <UML:ActionExpression language=\"\" body=\"^Environment.getBrightnessValue\"/> </UML:Action.script> </UML:UninterpretedAction> </UML:Transition.effect>" ) ;
- // 6 - state 4 to state 5 - setBrightnessValue();
- trans_info.push_back ("<UML:Transition.trigger> <UML:Event> <UML:ModelElement.namespace> <UML:Namespace> <UML:Namespace.ownedElement> <UML:CallEvent xmi.id=\"XDE-79243838-9C4E-4908-9637-9F9583043BE4\" operation=\"XDE-C8BD0DBA-E427-41A0-95F4-98FAA920ACA9\" name=\"setBrightnessValue\" isSpecification=\"false\"/> </UML:Namespace.ownedElement> </UML:Namespace> </UML:ModelElement.namespace> </UML:Event> </UML:Transition.trigger>");
- // 7 - state 5 to state 6 - value < min
- trans_info.push_back ("<UML:Transition.guard> <UML:Guard> <UML:Guard.expression> <UML:BooleanExpression body=\"brightnessValue<0\" language=\"\"/> </UML:Guard.expression> </UML:Guard> </UML:Transition.guard> <UML:Transition.effect> <UML:UninterpretedAction xmi.id=\"XDE-0B7A10EB-A9FC-4DE8-BBF1-AF1C9A970E7F\" isAsynchronous=\"false\" name=\"\" isSpecification=\"false\"> <UML:Action.script> <UML:ActionExpression language=\"\" body=\"correctedBrightnessValue:=0\"/> </UML:Action.script> </UML:UninterpretedAction> </UML:Transition.effect>");
- // 8 - state 5 to state 6 - value > max
- trans_info.push_back ("<UML:Transition.guard> <UML:Guard> <UML:Guard.expression> <UML:BooleanExpression body=\"brightnessValue>1000\" language=\"\"/> </UML:Guard.expression> </UML:Guard> </UML:Transition.guard> <UML:Transition.effect> <UML:UninterpretedAction xmi.id=\"XDE-7D6DDE48-7568-4043-B00A-87EFBE1A6CB3\" isAsynchronous=\"false\" name=\"\" isSpecification=\"false\"> <UML:Action.script> <UML:ActionExpression language=\"\" body=\"correctedBrightnessValue:=1000\"/> </UML:Action.script> </UML:UninterpretedAction> </UML:Transition.effect>");
- // 9 - state 5 to state 6 - value > min && value < max
- trans_info.push_back ("<UML:Transition.guard> <UML:Guard> <UML:Guard.expression> <UML:BooleanExpression body=\"brightnessValue >=0 & brightnessValue<=1000\" language=\"\"/> </UML:Guard.expression> </UML:Guard> </UML:Transition.guard> <UML:Transition.effect> <UML:UninterpretedAction xmi.id=\"XDE-8E3B2DF6-D63B-4A70-9CD3-FF0DE13EEDAD\" isAsynchronous=\"false\" name=\"\" isSpecification=\"false\"> <UML:Action.script> <UML:ActionExpression language=\"\" body=\"correctedBrightnessValue:=brightnessValue\"/> </UML:Action.script> </UML:UninterpretedAction> </UML:Transition.effect>");
- // 10 - state 6 to state 1 - set Computing Component brightness value
- trans_info.push_back("<UML:Transition.effect> <UML:UninterpretedAction xmi.id=\"XDE-101E5C46-12EA-4169-9DC9-D3661EE9836B\" isAsynchronous=\"false\" name=\"\" isSpecification=\"false\"> <UML:Action.script> <UML:ActionExpression language=\"\" body=\"^ComputingComponent.setBrightnessValue(brightnessValue)\"/> </UML:Action.script> </UML:UninterpretedAction> </UML:Transition.effect>");
-
-}
-*/
void cOrganism::InitTransForHIL()
{
@@ -605,49 +533,15 @@
(*it).second = "^ComputingComponent.setBrightnessValue(brightnessValue)";
break;
default:
- (*it).second = "--too many trans--";
+ (*it).second = " ";
}
count++;
}
}
-
-/* if (transGuardActionInfo.size() >= 6) {
- it = uml_trans_set.begin();
- (*it).second = "";
- ++it;
- (*it).second = "^Environment.getBrightnessValue";
- ++it;
- (*it).second = "/operationalState:=1^ComputingComponent.ccTRUE";
- ++it;
- (*it).second = "/operationalState:=0^ComputingComponent.ccFALSE";
- ++it;
- (*it).second = "getOperationalState";
- ++it;
- (*it).second = "getBrightnessValue";
- ++it;
- (*it).second = "^ComputingComponent.setBrightnessValue(brightnessValue)";
- ++it;
- (*it).second = "[brightnessValue<0]/correctedBrightnessValue:=0";
- ++it;
- (*it).second = "[brightnessValue >=0 & brightnessValue<=1000]/correctedBrightnessValue:=brightnessValue";
- ++it;
- (*it).second = "[brightnessValue>1000]/correctedBrightnessValue:=1000";
- ++it;
- (*it).second = "setBrightnessValue(brightnessValue)";
- }*/
-
-//void cOrganism::AssignTransMeaning (int trans)
-//{
-
-
-// return;
-//}
-
-
bool cOrganism::AddTrans(int trans, int orig, int dest)
{
NameStateMap::iterator pos1, pos2;
@@ -846,251 +740,6 @@
return (hil_begin + hil + hil_end);
}
-void cOrganism::InitHILBandE()
-{
-/*
- hil_begin = "Formalize as promela ;\n \
- Model XDEModel{\n \
- Class BrightnessSensor {\n \
- InstanceVar int brightnessValue ;\n \
- InstanceVar int correctedBrightnessValue ;\n \
- InstanceVar bool operationalState ;\n \
- Signal getBrightnessValue( ) ;\n \
- Signal getOperationalState( ) ;\n \
- Signal setBrightnessValue(int ) ;\n ";
-
- hil_end = "}\n\
- Class ComputingComponent {\n \
- InstanceVar bool automaticMode ;\n \
- InstanceVar int brightnessValue ;\n \
- InstanceVar int computedDimmerValue ;\n \
- InstanceVar int desiredBrightnessValue ;\n \
- InstanceVar bool initialized ;\n \
- InstanceVar bool manualMode ;\n \
- InstanceVar bool motionDetected ;\n \
- Signal ccAck( ) ;\n \
- Signal ccFALSE( ) ;\n \
- Signal ccTRUE( ) ;\n \
- Signal setBrightnessValue(int ) ;\n \
- Signal setDesiredBrightnessValue(int ) ;\n \
- Initial \"\" Init ;\n \
- State Init {\n \
- Transition \"\" to Initialize ;\n \
- }\n \
- CompositeState Initialize {\n \
- Transition \"ccFALSE\" to PowerOff ;\n \
- Initial \"\" InitializationStart ;\n \
- State BSensRec {\n \
- Transition \"^MotionSensor.getOperationalState\" to MSensReq ;\n \
- }\n \
- State BSensReq {\n \
- Transition \"ccTRUE\" to BSensRec ;\n \
- }\n \
- State DimmerRec {\n \
- Transition \"^BrightnessSensor.getOperationalState\" to BSensReq ;\n \
- }\n \
- State DimmerReq {\n \
- Transition \"ccTRUE\" to DimmerRec ;\n \
- }\n \
- State InitializationStart {\n \
- Transition \"^Dimmer.getOperationalState\" to DimmerReq ;\n \
- }\n \
- State MSensReq {\n \
- Transition \"ccTRUE/initialized:=1\" to NormalBehavior ;\n \
- }\n \
- }\n \
- CompositeState NormalBehavior {\n \
- Initial \"\" NBInit ;\n \
- CompositeState Automatic {\n \
- Initial \"/automaticMode:=1^UserInterface.setDisplayMode(1)\" AIdle ;\n \
- State AIdle {\n \
- Transition \"ccAck^MotionSensor.isRoomOccupied\" to State1 ;\n \
- }\n \
- State ActualValueRequested {\n \
- Transition \"setBrightnessValue(brightnessValue)\" to BrightnessValueReceived ;\n \
- }\n \
- State BrightnessValueReceived {\n \
- Transition \"/computedDimmerValue:=desiredBrightnessValue-brightnessValue\" to CorrectionValueCalculated ;\n \
- }\n \
- State CorrectionValueCalculated {\n \
- Transition \"^Dimmer.changeDimmerValue(computedDimmerValue)\" to CorrectionValueSumbitted ;\n \
- }\n \
- State CorrectionValueSumbitted {\n \
- Transition \"ccAck/automaticMode:=0; motionDetected:=0\" to NBInit ;\n \
- }\n \
- State DesiredValueReceived {\n \
- Transition \"^BrightnessSensor.getBrightnessValue\" to ActualValueRequested ;\n \
- }\n \
- State DesiredValueRequested {\n \
- Transition \"setDesiredBrightnessValue(desiredBrightnessValue)\" to DesiredValueReceived ;\n \
- }\n \
- State MotionValueReceived {\n \
- Transition \"[motionDetected=1]^UserInterface.getDesiredBrightnessValue\" to DesiredValueRequested ;\n \
- Transition \"[motionDetected=0]\" to NBInit ;\n \
- }\n \
- State State1 {\n \
- Transition \"ccFALSE/motionDetected:=0\" to MotionValueReceived ;\n \
- Transition \"ccTRUE/motionDetected:=1\" to MotionValueReceived ;\n \
- }\n \
- }\n \
- State EnterAuto {\n \
- Transition \"\" to OpStatusAutoSet ;\n \
- }\n \
- State EnterManual {\n \
- Transition \"\" to OpStatusManualSet ;\n \
- }\n \
- CompositeState Manual {\n \
- Initial \"/manualMode:=1^UserInterface.setDisplayMode(2)\" MIdle ;\n \
- State DimmerValueSet {\n \
- Transition \"ccAck\" to Done ;\n \
- }\n \
- State Done {\n \
- Transition \"/manualMode:=0\" to NBInit ;\n \
- }\n \
- State MIdle {\n \
- Transition \"ccAck^Dimmer.changeDimmerValue(1000)\" to DimmerValueSet ;\n \
- }\n \
- }\n \
- State ManualModeCheck {\n \
- Transition \"ccTRUE\" to EnterManual ;\n \
- Transition \"ccFALSE\" to EnterAuto ;\n \
- }\n \
- State NBInit {\n \
- Transition \"^UserInterface.isManualMode\" to ManualModeCheck ;\n \
- }\n \
- State OpStatusAutoSet {\n \
- Transition \"\" to Automatic ;\n \
- }\n \
- State OpStatusManualSet {\n \
- Transition \"\" to Manual ;\n \
- }\n \
- }\n \
- State PowerOff {\n \
- }\n \
-}\n \
-Class Dimmer {\n \
- InstanceVar int deltaDimmerValue ;\n \
- InstanceVar int dimmerValue ;\n \
- InstanceVar bool operationalState ;\n \
- InstanceVar int tempDimmerValue ;\n \
- Signal changeDimmerValue(int ) ;\n \
- Signal dimmerAck( ) ;\n \
- Signal getOperationalState( ) ;\n \
- Initial \"\" Idle ;\n \
- State DetermineOS {\n \
- Transition \"/operationalState:=1^ComputingComponent.ccTRUE\" to Idle ;\n \
- Transition \"/operationalState:=0^ComputingComponent.ccFALSE\" to Idle ;\n \
- }\n \
- State DimmerValueSet {\n \
- Transition \"dimmerAck^ComputingComponent.ccAck\" to Idle ;\n \
- }\n \
- State Idle {\n \
- Transition \"getOperationalState\" to DetermineOS ;\n \
- Transition \"changeDimmerValue(deltaDimmerValue)/tempDimmerValue:=dimmerValue+deltaDimmerValue\" to TempValueReceived ;\n \
- }\n \
- State TempValueReceived {\n \
- Transition \"[tempDimmerValue>1000]/dimmerValue:=1000\" to ValueProcessed ;\n \
- Transition \"[tempDimmerValue>=0 & tempDimmerValue<=1000]/dimmerValue:=tempDimmerValue\" to ValueProcessed ;\n \
- Transition \"[tempDimmerValue<0]/dimmerValue:=0\" to ValueProcessed ;\n \
- }\n \
- State ValueProcessed {\n \
- Transition \"^Environment.setDimmerValue(dimmerValue)\" to DimmerValueSet ;\n \
- }\n \
-}\n \
-Class Environment {\n \
- InstanceVar int brightnessValue ;\n \
- InstanceVar int dimmerValue ;\n \
- InstanceVar bool motionValue ;\n \
- InstanceVar int totalBrightnessValue ;\n \
- Signal getBrightnessValue( ) ;\n \
- Signal isRoomOccupied( ) ;\n \
- Signal setDimmerValue(int ) ;\n \
- Initial \"\" Idle ;\n \
- State BrightnessValueRequested {\n \
- Transition \"/brightnessValue:=1100\" to BrightnessValueSelected ;\n \
- Transition \"/brightnessValue:=850\" to BrightnessValueSelected ;\n \
- Transition \"/brightnessValue:=0\" to BrightnessValueSelected ;\n \
- Transition \"/brightnessValue:=300\" to BrightnessValueSelected ;\n \
- }\n \
- State BrightnessValueSelected {\n \
- Transition \"/totalBrightnessValue:=brightnessValue+dimmerValue\" to TotalValueComputed ;\n \
- }\n \
- State DimmerValueSet {\n \
- Transition \"/totalBrightnessValue:=brightnessValue+dimmerValue^Dimmer.dimmerAck\" to Idle ;\n \
- }\n \
- State Idle {\n \
- Transition \"setDimmerValue(dimmerValue)\" to DimmerValueSet ;\n \
- Transition \"isRoomOccupied\" to MotionValueRequested ;\n \
- Transition \"getBrightnessValue\" to BrightnessValueRequested ;\n \
- }\n \
- State MotionValueRequested {\n \
- Transition \"/motionValue:=1^MotionSensor.msTRUE\" to MotionValueSelected ;\n \
- Transition \"/motionValue:=0^MotionSensor.msFALSE\" to MotionValueSelected ;\n \
- }\n \
- State MotionValueSelected {\n \
- Transition \"\" to Idle ;\n \
- }\n \
- State TotalValueComputed {\n \
- Transition \"^BrightnessSensor.setBrightnessValue(totalBrightnessValue)\" to Idle ;\n \
- }\n \
-}\n \
-Class MotionSensor {\n \
- InstanceVar bool motionValue ;\n \
- InstanceVar bool operationalState ;\n \
- Signal getOperationalState( ) ;\n \
- Signal isRoomOccupied( ) ;\n \
- Signal msFALSE( ) ;\n \
- Signal msTRUE( ) ;\n \
- Initial \"\" Idle ;\n \
- State DetermineOS {\n \
- Transition \"/operationalState:=1^ComputingComponent.ccTRUE\" to Idle ;\n \
- Transition \"/operationalState:=0^ComputingComponent.ccFALSE\" to Idle ;\n \
- }\n \
- State Idle {\n \
- Transition \"getOperationalState\" to DetermineOS ;\n \
- Transition \"isRoomOccupied^Environment.isRoomOccupied\" to MotionValueRequested ;\n \
- }\n \
- State MotionValueRequested {\n \
- Transition \"msFALSE^ComputingComponent.ccFALSE\" to Idle ;\n \
- Transition \"msTRUE^ComputingComponent.ccTRUE\" to Idle ;\n \
- }\n \
-}\n \
-Class UserInterface {\n \
- InstanceVar int desiredBrightnessValue ;\n \
- InstanceVar short displayMode ;\n \
- InstanceVar bool manualMode ;\n \
- Signal getDesiredBrightnessValue( ) ;\n \
- Signal isManualMode( ) ;\n \
- Signal setDisplayMode(short ) ;\n \
- Initial \"\" DesiredValueRequested ;\n \
- State DesiredValueRequested {\n \
- Transition \"/desiredBrightnessValue:=1000\" to Idle ;\n \
- Transition \"/desiredBrightnessValue:=500\" to Idle ;\n \
- Transition \"/desiredBrightnessValue:=0\" to Idle ;\n \
- }\n \
- State Idle {\n \
- Transition \"isManualMode\" to State2 ;\n \
- Transition \"setDisplayMode(displayMode)\" to OperationalStatusSet ;\n \
- Transition \"getDesiredBrightnessValue\" to State1 ;\n \
- }\n \
- State OperationalStatusSet {\n \
- Transition \"^ComputingComponent.ccAck\" to Idle ;\n \
- }\n \
- State State1 {\n \
- Transition \"^ComputingComponent.setDesiredBrightnessValue(desiredBrightnessValue)\" to Idle ;\n \
- }\n \
- State State2 {\n \
- Transition \"/manualMode:=1^ComputingComponent.ccTRUE\" to Idle ;\n \
- Transition \"/manualMode:=0^ComputingComponent.ccFALSE\" to Idle ;\n \
- }\n \
-}\n \
-\n \
-}\n \ ";
-*/
- return;
-}
-
-
// 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 ...
Modified: branches/uml/source/main/cOrganism.h
===================================================================
--- branches/uml/source/main/cOrganism.h 2006-12-12 01:09:58 UTC (rev 1124)
+++ branches/uml/source/main/cOrganism.h 2006-12-12 03:18:46 UTC (rev 1125)
@@ -114,8 +114,6 @@
typedef graph_traits<Graph>::edge_descriptor Transition;
typedef graph_traits<Graph>::out_edge_iterator oei;
-
-
protected:
cWorld* m_world;
@@ -160,13 +158,16 @@
Transition transitions; // map of transition descriptors to transitions
NameStateMap states; // map of the state names
TransMeaning transGuardActionInfo; // map of transition integers to the string representing their label
- std::string hil_begin;
+ static std::string hil_begin;
std::string hil;
- std::string hil_end;
+ static std::string hil_end;
std::map<int, int> PosToStateLabel; // a map that relates the number in which the state was inserted
// to the label the organism assigns it.
+
+
+
class cNetSupport
{
public:
@@ -235,18 +236,9 @@
void NetReset();
// UML Stuff
-// t_stateMap uml_states;
-// t_transitionMap uml_transitions;
-// t_transitionMap uml_trans_by_state;
-// std::set <int> uml_state_set;
-// std::map <int, std::string> uml_trans_set;
void ModelCheck(cAvidaContext& ctx);
-// void printXMI(cAvidaContext& ctx);
void printHIL(cAvidaContext& ctx);
-// std::vector<std::string> trans_info;
-// void InitTransForXMI();
void InitTransForHIL();
- void InitHILBandE();
bool AddTrans(int trans, int orig, int dest);
double NumStates();
double NumTrans();
Modified: branches/uml/source/main/cTaskLib.cc
===================================================================
--- branches/uml/source/main/cTaskLib.cc 2006-12-12 01:09:58 UTC (rev 1124)
+++ branches/uml/source/main/cTaskLib.cc 2006-12-12 03:18:46 UTC (rev 1125)
@@ -9,8 +9,11 @@
*/
#include "cTaskLib.h"
+#include <unistd.h>
+#include <math.h>
+#include <errno.h>
+#include <boost/regex.hpp>
-
extern "C" {
#include <math.h>
#include <limits.h>
@@ -2032,6 +2035,9 @@
double cTaskLib::Task_Hydra(cTaskContext* ctx) const
{
+ // Sanity Check - Does hydra have a chance of succeeding?
+ if(Task_Transition10(ctx)==0.0) return 0.0; //etc.
+
cOrganism* organism = ctx->organism;
double bonus = 0.0;
std::string temp;
@@ -2051,12 +2057,18 @@
close(from_subavida[0]);
dup2(to_subavida[0], STDIN_FILENO); //oldd, newd
dup2(from_subavida[1], STDOUT_FILENO);
- // HJG - change to call hydra...
-// execl("./subavida", "subavida", "-c", "runtime_test.cfg", NULL);
execl("./hydralite/hydra", 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->getHil();
do {
status = write(to_subavida[1], temp.c_str()+status_total, temp.size());
@@ -2066,71 +2078,47 @@
status_total += status;
}
} while (status_total < temp.size());
- //parent
- close(to_subavida[0]);
- close(from_subavida[1]);
- close(to_subavida[1]);
+ close(to_subavida[1]); // Wakes up subavida.
- std::string subavida_output;
- char line[32]={0};
- //do {
- status = read(from_subavida[0], line, 31);
-// cout << "BEFORE PRINT" << endl;
-// cout << line << endl;
-// cout << "AFTER PRINT" << endl;
- // if(status > 0) {
- // subavida_output += line;
- // memset(line, 0, 32);
- // }
- //} while(((status==-1) && (errno == EINTR)) || (status>0));
-
+ // Time passes...
-
- close(from_subavida[0]);
-
-// not pertinent for the UML project
-/*
- //write the genome of this organism to_avida[1].
- const cInstSet& isa = ctx->GetOrganism()->GetHardware().GetInstSet();
- const cGenome& genome = ctx->GetOrganism()->GetGenome();
- for(int i=0; i<genome.GetSize(); ++i) {
- //for each instruction in the genome, look up its textual representation.
- const cString& inst = isa.GetName(genome[i]);
- write(to_subavida[1], (const void*)((const char*)inst), inst.GetSize());
- write(to_subavida[1], "\n", 1);
- }
-
- close(to_subavida[1]);
+ // 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[32]={0};
- int status=0;
+ char line[read_size]={0};
do {
- status = read(from_subavida[0], line, 31);
+ status = read(from_subavida[0], line, read_size-1);
if(status > 0) {
subavida_output += line;
- memset(line, 0, 32);
+ 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);
- //interpret the data that was read.
- boost::regex fitness("fitness=(\\d+\\.\\d+)");
+ //Interpret the data that we read from subavida.
+ // hydra=5;spin=10 ... or whatever.
+ boost::regex hydra("hydra=(\\d+)");
+ boost::regex spin("spin=(\\d+)");
boost::match_results<std::string::const_iterator> match;
- double ret=0.0;
+ double hydraval=0.0;
+ double spinval=0.0;
- if(boost::regex_search(subavida_output, match, fitness)) {
+ if(boost::regex_search(subavida_output, match, hydra)) {
std::istringstream iss(match[1]);
- iss >> std::dec >> ret;
+ iss >> std::dec >> hydraval;
}
-*/
-
- return bonus;
-
+ if(boost::regex_search(subavida_output, match, spin)) {
+ std::istringstream iss(match[1]);
+ iss >> std::dec >> spinval;
+ }
+
+ return pow(hydraval, spinval);
}
More information about the Avida-cvs
mailing list