[Avida-SVN] r1122 - in branches/uml/source: cpu main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Sat Dec 9 19:59:20 PST 2006
Author: hjg
Date: 2006-12-09 22:59:19 -0500 (Sat, 09 Dec 2006)
New Revision: 1122
Modified:
branches/uml/source/cpu/cHardwareCPU.cc
branches/uml/source/cpu/cHardwareCPU.h
branches/uml/source/main/cOrganism.cc
branches/uml/source/main/cOrganism.h
branches/uml/source/main/cTaskLib.cc
Log:
Added instructions get-state and get-trans to retrieve the label of a state and a transition, respectively.
Modified: branches/uml/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.cc 2006-12-09 02:00:50 UTC (rev 1121)
+++ branches/uml/source/cpu/cHardwareCPU.cc 2006-12-10 03:59:19 UTC (rev 1122)
@@ -356,6 +356,10 @@
// "Create a state"),
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("model-ch", &cHardwareCPU::Inst_ModelCheck, false,
// "Model check the model"),
// cInstEntryCPU("cr-trans2", &cHardwareCPU::Inst_CreateTransitionIntStates, false,
@@ -3483,3 +3487,37 @@
}
+bool cHardwareCPU::Inst_GetState(cAvidaContext& ctx)
+{
+ // 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);
+
+ // put value into register...
+// FindNextRegister(reg_used) = label;
+ GetRegister(FindNextRegister(reg_used)) = label;
+ }
+
+ 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);
+
+ if ((trans_pos >= 0) && (trans_pos < organism->NumTrans())) {
+ int label = organism->getTransLabelInPosition(trans_pos);
+
+ // put value into register...
+ GetRegister(FindNextRegister(reg_used)) = label;
+ }
+
+ return true;
+}
+
+
Modified: branches/uml/source/cpu/cHardwareCPU.h
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.h 2006-12-09 02:00:50 UTC (rev 1121)
+++ branches/uml/source/cpu/cHardwareCPU.h 2006-12-10 03:59:19 UTC (rev 1122)
@@ -476,6 +476,8 @@
// bool Inst_CreateTransition(cAvidaContext& ctx);
// bool Inst_ModelCheck(cAvidaContext& ctx);
bool Inst_CreateTransition(cAvidaContext& ctx);
+ bool Inst_GetState(cAvidaContext& ctx);
+ bool Inst_GetTrans(cAvidaContext& ctx);
// bool Inst_CreateTransitionIntStates(cAvidaContext& ctx);
};
Modified: branches/uml/source/main/cOrganism.cc
===================================================================
--- branches/uml/source/main/cOrganism.cc 2006-12-09 02:00:50 UTC (rev 1121)
+++ branches/uml/source/main/cOrganism.cc 2006-12-10 03:59:19 UTC (rev 1122)
@@ -1126,6 +1126,56 @@
}
+
+// if you ask for something greater than the number of states then you get the highest numbered state.
+int cOrganism::getStateLabelInPosition (int num)
+{
+ /*std::pair<vertex_iterator, vertex_iterator>
+vertices(const adjacency_list& g)*/
+// Graph::vertex_iterator vi, vi_end;
+// tie(vi,vi_end) = vertices(uml_state_diagram);
+// vi+=num;
+ //graph_traits<Graph>::vertex_descriptor b = *vi;
+// return *vi;
+
+ int count = 0;
+ // This code uses a value ordering on the states (lowest number = position 0)
+ nsm_it i;
+ for (i=states.begin(); i!=states.end(); ++i)
+ {
+ if (count == num) {
+ break;
+ }
+ count++;
+ }
+ return i->first;
+
+
+/*
+ int x = PosToStateLabel[num];
+ return (states[x]);
+*/
+}
+
+
+// if you ask for something greater than the number of trans -- you get the highest numbered one...
+int cOrganism::getTransLabelInPosition (int num)
+{
+ int count = 0;
+ tm_it i;
+ for (i=transGuardActionInfo.begin(); i!=transGuardActionInfo.end(); ++i)
+ {
+ if (count == num) {
+ break;
+ }
+ count++;
+ }
+ int test = i->first;
+
+ return i->first;
+
+}
+
cOrganism::Graph& cOrganism::GetGraph()
{
return uml_state_diagram;
Modified: branches/uml/source/main/cOrganism.h
===================================================================
--- branches/uml/source/main/cOrganism.h 2006-12-09 02:00:50 UTC (rev 1121)
+++ branches/uml/source/main/cOrganism.h 2006-12-10 03:59:19 UTC (rev 1122)
@@ -109,6 +109,7 @@
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;
@@ -252,6 +253,8 @@
void AssignTransMeaning(int trans);
Graph& GetGraph();
State& getStateInPosition (int num);
+ int getStateLabelInPosition (int num);
+ int getTransLabelInPosition (int num);
bool isTrans(State, State, int);
int getTransNumber (int pos);
bool findTrans(int s0_pos, int s1_pos, int t_pos);
Modified: branches/uml/source/main/cTaskLib.cc
===================================================================
--- branches/uml/source/main/cTaskLib.cc 2006-12-09 02:00:50 UTC (rev 1121)
+++ branches/uml/source/main/cTaskLib.cc 2006-12-10 03:59:19 UTC (rev 1122)
@@ -1861,228 +1861,8 @@
}
-/*
-double cTaskLib::Task_CreateStates(cTaskContext* ctx) const
-{
- cOrganism* organism = ctx->organism;
- double bonus = 0.0;
-
- // reward for constructing 7 states - brightness sensor
- if (organism->uml_state_set.size() <= 7) {
- bonus += organism->uml_state_set.size();
- }
- return bonus;
-}
-
-double cTaskLib::Task_CreateTransX(cTaskContext* ctx) const
-{
- std::pair<cOrganism::tr_it, cOrganism::tr_it> trans_range;
- std::pair<int, int> st;
- cOrganism* organism = ctx->organism;
- cOrganism::tr_it i;
- double bonus = 0.0;
- std::set<int>::iterator it;
- cOrganism::t_transitionMap::iterator it2;
- int state0, state1, state2, state3, state4, state5, state6;
- int trans1, trans2, trans3, trans4, trans5, trans6, trans7;
- int trans8, trans9, trans10, trans0;
-
-
-
- if ((organism->uml_state_set.size() > 6) && (organism->uml_transitions.size() > 10)){
- // get the 7 states
- it = organism->uml_state_set.begin();
- state0 = *it;
- it++;
- state1 = *it;
- it++;
- state2 = *it;
- it++;
- state3 = *it;
- it++;
- state4 = *it;
- it++;
- state5 = *it;
- it++;
- state6 = *it;
-
- it2 = organism->uml_transitions.begin();
- trans0 = (*it2).first;
- it2++;
- trans1 = (*it2).first;
- it2++;
- trans2 = (*it2).first;
- it2++;
- trans3 = (*it2).first;
- it2++;
- trans4 = (*it2).first;
- it2++;
- trans5 = (*it2).first;
- it2++;
- trans6 = (*it2).first;
- it2++;
- trans7 = (*it2).first;
- it2++;
- trans8 = (*it2).first;
- it2++;
- trans9 = (*it2).first;
-
-
-
- // reward for each transition
- // transition 0
- trans_range = organism->uml_transitions.equal_range(trans3);
- for(i=trans_range.first; i!=trans_range.second; ++i) {
- st = i->second;
-
- if ((st.first == state0) && (st.second == state1)) {
-
- bonus += 1.0;
- break;
- }
- }
-
- // transition 1
- trans_range = organism->uml_transitions.equal_range(trans1);
- for(i=trans_range.first; i!=trans_range.second; ++i) {
- st = i->second;
-
- if ((st.first == state1) && (st.second == state2)) {
- bonus += 1.0;
- break;
- }
- }
-
- // transition 2
- trans_range = organism->uml_transitions.equal_range(trans2);
- for(i=trans_range.first; i!=trans_range.second; ++i) {
- st = i->second;
-
- if ((st.first == state2) && (st.second == state1)) {
- bonus += 1.0;
- break;
- }
- }
-
- // transition 3
- trans_range = organism->uml_transitions.equal_range(trans3);
- for(i=trans_range.first; i!=trans_range.second; ++i) {
- st = i->second;
-
- if ((st.first == state2) && (st.second == state1)) {
-
- bonus += 1.0;
- break;
- }
- }
-
- // transition 4
- trans_range = organism->uml_transitions.equal_range(trans4);
- for(i=trans_range.first; i!=trans_range.second; ++i) {
- st = i->second;
-
- if ((st.first == state1) && (st.second == state3)) {
-
- bonus += 1.0;
- break;
- }
- }
-
- // transition 5
- trans_range = organism->uml_transitions.equal_range(trans5);
- for(i=trans_range.first; i!=trans_range.second; ++i) {
- st = i->second;
-
- if ((st.first == state3) && (st.second == state4)) {
-
- bonus += 1.0;
- break;
- }
- }
-
- // transition 6
- trans_range = organism->uml_transitions.equal_range(trans6);
- for(i=trans_range.first; i!=trans_range.second; ++i) {
- st = i->second;
-
- if ((st.first == state4) && (st.second == state5)) {
-
- bonus += 1.0;
- break;
- }
- }
-
- // transition 7
- trans_range = organism->uml_transitions.equal_range(trans7);
- for(i=trans_range.first; i!=trans_range.second; ++i) {
- st = i->second;
-
- if ((st.first == state5) && (st.second == state6)) {
-
- bonus += 1.0;
- break;
- }
- }
-
- // transition 8
- trans_range = organism->uml_transitions.equal_range(trans8);
- for(i=trans_range.first; i!=trans_range.second; ++i) {
- st = i->second;
-
- if ((st.first == state5) && (st.second == state6)) {
-
- bonus += 1.0;
- break;
- }
- }
-
- // transition 9
- trans_range = organism->uml_transitions.equal_range(trans9);
- for(i=trans_range.first; i!=trans_range.second; ++i) {
- st = i->second;
-
- if ((st.first == state5) && (st.second == state6)) {
-
- bonus += 1.0;
- break;
- }
- }
-
- // transition 10
- trans_range = organism->uml_transitions.equal_range(trans10);
- for(i=trans_range.first; i!=trans_range.second; ++i) {
- st = i->second;
-
- if ((st.first == state6) && (st.second == state1)) {
-
- bonus += 1.0;
- break;
- }
- }
-
-
-
- }
-
- return bonus;
-}
-
-double cTaskLib::Task_CreateTranss(cTaskContext* ctx) const
-{
- cOrganism* organism = ctx->organism;
- double bonus = 0.0;
-
- // reward for constructing 7 states - brightness sensor
- if (organism->uml_transitions.size() <= 11) {
- bonus += organism->uml_transitions.size();
- }
-
- return bonus;
-}
-*/
-
// 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
{
@@ -2093,7 +1873,11 @@
// reward for constructing 7 states - brightness sensor
if (organism->NumStates() <= 7) {
bonus += numStates;
- }
+ //bonus = 1.0;
+ } /*else {
+
+ bonus = (7 - (numStates - 7));
+ }*/
return bonus;
}
@@ -2104,10 +1888,15 @@
double bonus = 0.0;
double numTrans = organism->NumTrans();
- // reward for constructing 7 states - brightness sensor
+ // reward for constructing 11 trans - brightness sensor
if (organism->NumTrans() <= 11) {
bonus += numTrans;
- }
+ //bonus = 1.0;
+ } /*else {
+
+ bonus = (11 - (numTrans -11));
+
+ }*/
return bonus;
}
@@ -2128,10 +1917,10 @@
double bonus = 0.0;
// good for both bs and gsm
- // if (ctx->organism->findTrans(1, 2, 1)) {
+ if (ctx->organism->findTrans(1, 2, 1)) {
// testing the creation of multiple trans to get reward concept
- if ((ctx->organism->findTrans(1, 2, 1)) && (ctx->organism->findTrans(2, 3, 2))) {
+// if ((ctx->organism->findTrans(1, 2, 1)) && (ctx->organism->findTrans(2, 3, 2))) {
bonus = 1.0;
}
@@ -2144,9 +1933,9 @@
double bonus = 0.0;
// brightness sensor
- // if (ctx->organism->findTrans(2, 1, 2)) {
+ if (ctx->organism->findTrans(2, 1, 2)) {
// gsm:
- if (ctx->organism->findTrans(2, 3, 2)) {
+// if (ctx->organism->findTrans(2, 3, 2)) {
bonus = 1.0;
}
@@ -2158,9 +1947,9 @@
double bonus = 0.0;
// brightness sensor
- // if (ctx->organism->findTrans(2, 1, 3)) {
+ if (ctx->organism->findTrans(2, 1, 3)) {
// gsm:
- if (ctx->organism->findTrans(3, 4, 3)) {
+ //if (ctx->organism->findTrans(3, 4, 3)) {
bonus = 1.0;
}
@@ -2172,8 +1961,8 @@
double bonus = 0.0;
// brightness sensor
-// if (ctx->organism->findTrans(1, 3, 4)) {
- if (ctx->organism->findTrans(4, 1, 4)) {
+ if (ctx->organism->findTrans(1, 3, 4)) {
+// if (ctx->organism->findTrans(4, 1, 4)) {
bonus = 1.0;
}
More information about the Avida-cvs
mailing list