[Avida-SVN] r1933 - branches/uml/source/main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Mon Aug 13 18:59:01 PDT 2007
Author: hjg
Date: 2007-08-13 21:59:01 -0400 (Mon, 13 Aug 2007)
New Revision: 1933
Modified:
branches/uml/source/main/cStats.cc
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 code that checks if the state diagram is non-deterministic. Changed the stats to be ratios of scenario completion.
Modified: branches/uml/source/main/cStats.cc
===================================================================
--- branches/uml/source/main/cStats.cc 2007-08-13 20:21:00 UTC (rev 1932)
+++ branches/uml/source/main/cStats.cc 2007-08-14 01:59:01 UTC (rev 1933)
@@ -1046,7 +1046,7 @@
df.Write( m_scenario7loop.Sum(), "total number of scenario 7 all transitions - might loop");*/
for (unsigned int i = 0; i < m_scenario_completion.size(); i++) {
- df.Write ( m_scenario_completion[i].Sum(), "total number of scenario passes");
+ df.Write ( m_scenario_completion[i].Average(), "Average ratio of scenario completion (+looping,start-state)");
m_scenario_completion[i].Clear();
}
Modified: branches/uml/source/main/cTaskLib.cc
===================================================================
--- branches/uml/source/main/cTaskLib.cc 2007-08-13 20:21:00 UTC (rev 1932)
+++ branches/uml/source/main/cTaskLib.cc 2007-08-14 01:59:01 UTC (rev 1933)
@@ -426,7 +426,8 @@
NewTask(name, "Successfully ran Spin witness trace", &cTaskLib::Task_SpinW2);
else if (name == "min-trans") //
NewTask(name, "Minimizing edges", &cTaskLib::Task_MinTrans);
-
+ else if (name == "non-determinism")
+ NewTask(name, "Non-determinism", &cTaskLib::Task_Nondeterminism);
/* else if (name == "mult_trans") //
NewTask(name, "Successfully completed multiple transitions", &cTaskLib::Task_MultTrans);*/
@@ -3280,3 +3281,17 @@
}
+
+double cTaskLib::Task_Nondeterminism(cTaskContext& ctx) const {
+ cOrganism* organism = ctx.getOrganism();
+ unsigned int bonus = 0;
+
+ for(unsigned int i=0; i<organism->getUMLModel()->getStateDiagramSize(); ++i) {
+ cUMLStateDiagram* sd=organism->getUMLModel()->getStateDiagram(i);
+ if(sd->numTrans() > 0) {
+ bonus += sd->getNumberOfNonDeterministicStates();
+ }
+ }
+
+ return !bonus;
+}
Modified: branches/uml/source/main/cTaskLib.h
===================================================================
--- branches/uml/source/main/cTaskLib.h 2007-08-13 20:21:00 UTC (rev 1932)
+++ branches/uml/source/main/cTaskLib.h 2007-08-14 01:59:01 UTC (rev 1933)
@@ -300,6 +300,7 @@
double Task_SpinW2(cTaskContext& ctx) const;
double Task_MinTrans(cTaskContext& ctx) const;
// double Task_MultTrans(cTaskContext& ctx) const;
+ double Task_Nondeterminism(cTaskContext& ctx) const;
};
Modified: branches/uml/source/main/cUMLModel.cc
===================================================================
--- branches/uml/source/main/cUMLModel.cc 2007-08-13 20:21:00 UTC (rev 1932)
+++ branches/uml/source/main/cUMLModel.cc 2007-08-14 01:59:01 UTC (rev 1933)
@@ -289,16 +289,17 @@
complete_bonus = s.path.size() + s.shouldLoop;
if (s.startState >= 0) complete_bonus++;
- if (temp_bonus == complete_bonus) {
-// bonus_info["scenario"+i] = 1;
- scenario_completion[i] = 1;
-// std::cout << "scenario complete " << std::endl;
- } else {
-// bonus_info["scenario"+i] = 0;
- scenario_completion[i] = 0;
-// std::cout << "scenario incomplete " << std::endl;
-
- }
+// if (temp_bonus == complete_bonus) {
+//// bonus_info["scenario"+i] = 1;
+// scenario_completion[i] = temp_bonus / complete_bonus;
+//// std::cout << "scenario complete " << std::endl;
+// } else {
+//// bonus_info["scenario"+i] = 0;
+// scenario_completion[i] = 0;
+//// std::cout << "scenario incomplete " << std::endl;
+//
+// }
+ scenario_completion[i] = temp_bonus / complete_bonus;
}
return total_bonus;
Modified: branches/uml/source/main/cUMLStateDiagram.cc
===================================================================
--- branches/uml/source/main/cUMLStateDiagram.cc 2007-08-13 20:21:00 UTC (rev 1932)
+++ branches/uml/source/main/cUMLStateDiagram.cc 2007-08-14 01:59:01 UTC (rev 1933)
@@ -1,4 +1,5 @@
#include "cUMLStateDiagram.h"
+#include <set>
cUMLStateDiagram::cUMLStateDiagram()
{
@@ -26,6 +27,42 @@
}
+unsigned int cUMLStateDiagram::getNumberOfNonDeterministicStates() {
+ std::string tt, tg, ta, ts;
+ unsigned int numNonD=0;
+ boost::graph_traits<state_diagram>::out_edge_iterator ei, ei_end;
+ boost::graph_traits<state_diagram>::vertex_iterator vi, vi_end;
+
+ // For each...
+ for(tie(vi,vi_end) = vertices(sd0); vi != vi_end; ++vi) {
+ std::set<std::string> tnames;
+ // out-edge of each vertex:
+ for(tie(ei,ei_end) = out_edges(*vi, sd0); ei != ei_end; ++ei) {
+ boost::graph_traits<state_diagram>::edge_descriptor e = *ei;
+
+ // Build a string from the trigger and guard for this out-edge.
+ tt = triggers[(sd0[e]._tr)].operation_id;
+ tg = guards[(sd0[e]._gu)];
+ if (tt == "<null>") tt = "";
+ if (tg == "<null>") tg = "";
+ ts = tt + "[" + tg + "]";
+
+ // See if it's already in the set:
+ if(tnames.find(ts) == tnames.end()) {
+ // no; add it.
+ tnames.insert(ts);
+ } else {
+ // yes; increment the count of non-deterministic states.
+ // We've found a state that has out-edges where the trigger+guard
+ // combination is duplicated at least once.
+ ++numNonD;
+ }
+ }
+ }
+ return numNonD;
+}
+
+
// This function accepts a path throught the state diagram as a deque and returns the length
// of the longest path segment that the diagram satisfies.
// The function is complicated by the fact that the longest path segment could start at the
@@ -56,7 +93,7 @@
if (len > path_dist) {
actual_path_start = i;
path_dist = len;
- }
+ }
}
p.pop_front();
@@ -72,7 +109,7 @@
}
}
if (should_loop == 1 && (path_dist == p_temp.size())) {
- int y = getEndState(p_temp, actual_path_start);
+ getEndState(p_temp, actual_path_start);
if (actual_end_state == actual_path_start) bonus +=1;
}
Modified: branches/uml/source/main/cUMLStateDiagram.h
===================================================================
--- branches/uml/source/main/cUMLStateDiagram.h 2007-08-13 20:21:00 UTC (rev 1932)
+++ branches/uml/source/main/cUMLStateDiagram.h 2007-08-14 01:59:01 UTC (rev 1933)
@@ -72,7 +72,9 @@
int numGuards() { return guards.size(); }
int numActions() { return actions.size(); }
+ unsigned int getNumberOfNonDeterministicStates();
+
bool findTrans(int, int, int, int, int);
// bool findTransLabel(transition_label); // find a specific transition label
More information about the Avida-cvs
mailing list