[Avida-SVN] r2553 - in branches/uml/source: cpu main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Thu Apr 24 12:10:18 PDT 2008
Author: hjg
Date: 2008-04-24 15:10:17 -0400 (Thu, 24 Apr 2008)
New Revision: 2553
Modified:
branches/uml/source/cpu/cHardwareCPU.cc
branches/uml/source/cpu/cHardwareCPU.h
branches/uml/source/main/cTaskLib.cc
branches/uml/source/main/cTaskLib.h
branches/uml/source/main/cUMLModel.cc
branches/uml/source/main/cUMLStateDiagram.cc
branches/uml/source/main/cUMLStateDiagram.h
Log:
Added loop instruction.
Modified: branches/uml/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.cc 2008-04-24 19:08:03 UTC (rev 2552)
+++ branches/uml/source/cpu/cHardwareCPU.cc 2008-04-24 19:10:17 UTC (rev 2553)
@@ -614,8 +614,10 @@
"AND expressions"),
tInstLibEntry<tMethod>("or-exp", &cHardwareCPU::Inst_ORExpressions, false,
"OR expressions"),
-
-
+ tInstLibEntry<tMethod>("start-loop", &cHardwareCPU::Inst_StartLoop, false,
+ "start a loop"),
+ tInstLibEntry<tMethod>("end-loop", &cHardwareCPU::Inst_EndLoop, false,
+ "end a loop"),
@@ -5136,4 +5138,14 @@
return val;
}
-
+bool cHardwareCPU::Inst_StartLoop(cAvidaContext& ctx)
+{
+ organism->getStateDiagram()->startLooping();
+ return true;
+}
+
+bool cHardwareCPU::Inst_EndLoop(cAvidaContext& ctx)
+{
+ organism->getStateDiagram()->endLooping();
+ return true;
+}
Modified: branches/uml/source/cpu/cHardwareCPU.h
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.h 2008-04-24 19:08:03 UTC (rev 2552)
+++ branches/uml/source/cpu/cHardwareCPU.h 2008-04-24 19:10:17 UTC (rev 2553)
@@ -696,6 +696,8 @@
bool Inst_NextExpressionR(cAvidaContext& ctx);
bool Inst_PrevExpressionR(cAvidaContext& ctx);
bool Inst_AbsoluteMoveExpressionR(cAvidaContext& ctx);
+ bool Inst_StartLoop(cAvidaContext& ctx);
+ bool Inst_EndLoop(cAvidaContext& ctx);
// bool
};
Modified: branches/uml/source/main/cTaskLib.cc
===================================================================
--- branches/uml/source/main/cTaskLib.cc 2008-04-24 19:08:03 UTC (rev 2552)
+++ branches/uml/source/main/cTaskLib.cc 2008-04-24 19:10:17 UTC (rev 2553)
@@ -433,9 +433,7 @@
NewTask(name, "Export XMI", &cTaskLib::Task_ExportXMI);
else if (name == "check-props")
NewTask(name, "Check Properties", &cTaskLib::Task_Properties);
- else if (name == "utility")
- NewTask(name, "Check Utility", &cTaskLib::Task_Utility);
-
+
/* else if (name == "mult_trans") //
NewTask(name, "Successfully completed multiple transitions", &cTaskLib::Task_MultTrans);*/
@@ -3399,15 +3397,5 @@
}
-double cTaskLib::Task_Utility(cTaskContext& ctx) const {
- cOrganism* organism = ctx.getOrganism();
- double bonus = 0.0;
-
- // calculate the utility of the model.
- // how do you figure mutually exclusive (e.g., if they use both bluetooth and wifi?)
-
-
- return bonus;
-}
Modified: branches/uml/source/main/cTaskLib.h
===================================================================
--- branches/uml/source/main/cTaskLib.h 2008-04-24 19:08:03 UTC (rev 2552)
+++ branches/uml/source/main/cTaskLib.h 2008-04-24 19:10:17 UTC (rev 2553)
@@ -306,7 +306,6 @@
double Task_Nondeterminism(cTaskContext& ctx) const;
double Task_ExportXMI(cTaskContext& ctx) const;
double Task_Properties(cTaskContext& ctx) const;
- double Task_Utility(cTaskContext& ctx) const;
};
Modified: branches/uml/source/main/cUMLModel.cc
===================================================================
--- branches/uml/source/main/cUMLModel.cc 2008-04-24 19:08:03 UTC (rev 2552)
+++ branches/uml/source/main/cUMLModel.cc 2008-04-24 19:10:17 UTC (rev 2553)
@@ -560,7 +560,7 @@
total_util += s.utilityMap["Accuracy"]*.2;
total_bonus = complete_bonus * total_util;
- return total_bonus;
+ return (total_bonus *5);
}
bool cUMLModel::readyForHydra()
Modified: branches/uml/source/main/cUMLStateDiagram.cc
===================================================================
--- branches/uml/source/main/cUMLStateDiagram.cc 2008-04-24 19:08:03 UTC (rev 2552)
+++ branches/uml/source/main/cUMLStateDiagram.cc 2008-04-24 19:10:17 UTC (rev 2553)
@@ -460,14 +460,24 @@
}
bool cUMLStateDiagram::addTransitionFromLabel() {
- // get the properties of the transition label.
- transition_properties tp = transition_labels[trans_label_index];
+
+ bool val = true;
- absoluteJumpTrigger(tp._tr);
- absoluteJumpGuard(tp._gu);
- absoluteJumpAction(tp._act);
+ if (looping) {
+// std::cout << "Adding loop element " << trans_label_index << std::endl;
+
+ loop_trans_labels.push_back(trans_label_index);
+ } else{
+ // get the properties of the transition label.
+ transition_properties tp = transition_labels[trans_label_index];
- return addTransitionTotal();
+ absoluteJumpTrigger(tp._tr);
+ absoluteJumpGuard(tp._gu);
+ absoluteJumpAction(tp._act);
+
+ val = addTransitionTotal();
+ }
+ return val;
}
bool cUMLStateDiagram::addTransitionTotal()
@@ -693,3 +703,34 @@
return;
}
+
+void cUMLStateDiagram::endLooping() {
+ looping = false;
+
+ // set up the origin
+ absoluteJumpOriginState(loop_state);
+
+
+ // for each element of the loop...
+ while (loop_trans_labels.size()!=0){
+ // set up the destination
+ if(loop_trans_labels.size() == 1) {
+ // last transition loop to start
+ absoluteJumpDestinationState(loop_state);
+ } else {
+ relativeJumpDestinationState(1);
+ }
+
+ // set up the label
+ absoluteJumpTransitionLabel(loop_trans_labels.front());
+ addTransitionFromLabel();
+// std::cout << "deque front " << loop_trans_labels.front() << " " << orig << " " << dest << std::endl;
+ loop_trans_labels.pop_front();
+ relativeJumpOriginState(1);
+
+ }
+
+}
+
+
+
Modified: branches/uml/source/main/cUMLStateDiagram.h
===================================================================
--- branches/uml/source/main/cUMLStateDiagram.h 2008-04-24 19:08:03 UTC (rev 2552)
+++ branches/uml/source/main/cUMLStateDiagram.h 2008-04-24 19:10:17 UTC (rev 2553)
@@ -128,13 +128,22 @@
// print
void printStateDiagram();
+
+ // loop functions
+ void startLooping () { looping = true; loop_state = orig; }
+ void endLooping();
+
+
protected:
state_diagram sd0;
boost::graph_traits<state_diagram>::vertex_descriptor orig;
boost::graph_traits<state_diagram>::vertex_descriptor dest;
int actual_end_state;
std::string sd_name;
+ bool looping;
+ int loop_state;
+ std::deque<int> loop_trans_labels;
};
More information about the Avida-cvs
mailing list