[Avida-SVN] r2241 - in branches/uml: Avida.xcodeproj source/main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Fri Dec 28 10:49:09 PST 2007
Author: hjg
Date: 2007-12-28 13:49:09 -0500 (Fri, 28 Dec 2007)
New Revision: 2241
Modified:
branches/uml/Avida.xcodeproj/project.pbxproj
branches/uml/source/main/cMDEAbsenceProperty.cc
branches/uml/source/main/cMDEUniversalProperty.cc
branches/uml/source/main/cUMLModel.cc
branches/uml/source/main/cUMLStateDiagram.cc
branches/uml/source/main/cUMLStateDiagram.h
Log:
Added support for transition labels.
Modified: branches/uml/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/uml/Avida.xcodeproj/project.pbxproj 2007-12-27 14:52:54 UTC (rev 2240)
+++ branches/uml/Avida.xcodeproj/project.pbxproj 2007-12-28 18:49:09 UTC (rev 2241)
@@ -856,7 +856,7 @@
DCC315CE076253A5008F7A48 /* environment.rotate */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = environment.rotate; sourceTree = "<group>"; };
DCC315D0076253A5008F7A48 /* task_event_gen.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = task_event_gen.cc; sourceTree = "<group>"; };
DCC315D1076253A5008F7A48 /* task_event_gen.old.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = task_event_gen.old.cc; sourceTree = "<group>"; };
- DCC3164D07626CF3008F7A48 /* avida */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = avida; sourceTree = BUILT_PRODUCTS_DIR; };
+ DCC3164D07626CF3008F7A48 /* avida */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = avida; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
Modified: branches/uml/source/main/cMDEAbsenceProperty.cc
===================================================================
--- branches/uml/source/main/cMDEAbsenceProperty.cc 2007-12-27 14:52:54 UTC (rev 2240)
+++ branches/uml/source/main/cMDEAbsenceProperty.cc 2007-12-28 18:49:09 UTC (rev 2241)
@@ -69,10 +69,11 @@
std::string work_prop = "properties_that_passed";
+
// if this property passed, then save it to a file
if (verify_reward) {
- cmd = "cat " + _name + " >> " + work_prop;
- system(cmd.c_str());
+ // cmd = "cat " + _name + " >> " + work_prop;
+ // system(cmd.c_str());
}
_reward = verify_reward;
Modified: branches/uml/source/main/cMDEUniversalProperty.cc
===================================================================
--- branches/uml/source/main/cMDEUniversalProperty.cc 2007-12-27 14:52:54 UTC (rev 2240)
+++ branches/uml/source/main/cMDEUniversalProperty.cc 2007-12-28 18:49:09 UTC (rev 2241)
@@ -66,8 +66,8 @@
// if this property passed, then save it to a file
if (verify_reward) {
- cmd = "cat " + _name + " >> " + work_prop;
- system(cmd.c_str());
+// cmd = "cat " + _name + " >> " + work_prop;
+// system(cmd.c_str());
}
_reward = verify_reward;
Modified: branches/uml/source/main/cUMLModel.cc
===================================================================
--- branches/uml/source/main/cUMLModel.cc 2007-12-27 14:52:54 UTC (rev 2240)
+++ branches/uml/source/main/cUMLModel.cc 2007-12-28 18:49:09 UTC (rev 2241)
@@ -157,9 +157,16 @@
}
scenarios.push_back(s);
+ } else if (line == "-TRANSITION-LABELS-------------") {
+ line.erase();
+ infile >> temp;
+ while (temp!= "-END---------------------------") {
+ infile >> trig_i >> guard_i >> act_i;
+ state_diagrams[cur_sd].addTransitionLabel(trig_i, guard_i, act_i);
+ }
+ infile >> temp;
}
- /* Missing code for reading in transition labels .... */
line.erase();
}
@@ -320,23 +327,11 @@
for (unsigned int i=0; i< scenarios.size(); i++) {
s = scenarios[i];
temp_bonus = getStateDiagram(s.stateDiagramID)->findPath(s.path, s.shouldLoop, s.startState);
-// std::cout << "TEMP BONUS: " << temp_bonus << std::endl;
-// total_bonus += temp_bonus;
-
+
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] = 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;
-//
total_bonus += (temp_bonus / complete_bonus);
-// }
scenario_completion[i] = temp_bonus / complete_bonus;
}
@@ -433,13 +428,6 @@
}
}
- /*if (temp_val == 0) {
- m_property_failure++;
- } else {
- m_property_success++;
- }*/
-
-
total += temp_val;
}
Modified: branches/uml/source/main/cUMLStateDiagram.cc
===================================================================
--- branches/uml/source/main/cUMLStateDiagram.cc 2007-12-27 14:52:54 UTC (rev 2240)
+++ branches/uml/source/main/cUMLStateDiagram.cc 2007-12-28 18:49:09 UTC (rev 2241)
@@ -8,8 +8,6 @@
sd0 = state_diagram(13);
// initialize / seed UML state diagram here
-// orig_state_index = 0;
-// dest_state_index = 0;
orig = vertex(0, sd0);
dest = vertex(0, sd0);
@@ -87,15 +85,6 @@
int actual_path_start;
int bonus = 0;
- // Entire path must start at state 0.
-// len = checkForPathStep(p, vertex(0, sd0), 0);
- // If this returns a length, then the path is found & we can exit.
-// if (len > 0) {
-// path_dist = len;
-// } else {
- // Else, check for partial paths, which can start from anywhere...
-// p.pop_front();
- // Must check each state other than state 0.
while (!p.empty()) {
for (int i = 0; i<num_vert; i++) {
len = checkForPathStep(p, vertex(i, sd0), 0);
@@ -109,8 +98,6 @@
if (len > p.size()) break;
}
-
- //}
bonus = path_dist;
if (start_state != -1) {
@@ -123,8 +110,6 @@
if (actual_end_state == actual_path_start) bonus +=1;
}
-
-
return bonus;
}
@@ -163,8 +148,6 @@
if (ts == path.front()) {
- //std::cout << "Looking for and found a path named: " << ts << std::endl;
- //std::cout << "Searching vertex " << target(ed, sd0) << "with distance " << curr_dist+1 << std::endl;
temp = checkForPathStep(std::deque<std::string>(++path.begin(), path.end()), target(ed,sd0), curr_dist+1);
@@ -173,15 +156,7 @@
}
}
- /*else if (ts == "[]/") {
- temp = checkForPathStep(path, target(ed, sd0), curr_dist);
- if (temp > longest_dist) {
- longest_dist = temp;
- }
- }*/
}
-
- //std::cout << "Returning longest_dist " << longest_dist << std::endl;
return longest_dist;
}
@@ -216,16 +191,12 @@
if (ta == "<null>") ta = "";
ts = tt + "[" + tg + "]" + "/" + ta;
-// std::cout << "transition named: " << ts << std::endl;
-
-
+
if (ts == path.front()) {
- //std::cout << "Searching vertex " << target(ed, sd0) << "with distance " << curr_dist+1 << std::endl;
temp = getEndState(std::deque<std::string>(++path.begin(), path.end()), target(ed,sd0));
}
}
- //std::cout << "Returning longest_dist " << longest_dist << std::endl;
return v;
}
@@ -394,28 +365,6 @@
}
-int cUMLStateDiagram::getTriggerIndex()
-{
- return trigger_index;
-}
-
-int cUMLStateDiagram::getGuardIndex()
-{
- return guard_index;
-}
-
-int cUMLStateDiagram::getActionIndex()
-{
- return action_index;
-
-}
-
-
-transition_label cUMLStateDiagram::getTransLabel()
-{
- return transition_labels[trans_label_index];
-}
-
bool cUMLStateDiagram::addTrigger(std::string op_id, std::string lab)
{
trigger_info t;
@@ -439,62 +388,14 @@
return true;
}
-/*
-bool cUMLStateDiagram::addTransition()
-{
+bool cUMLStateDiagram::addTransitionLabel(int t, int g, int a) {
- if ((states.size() == 0) || (transition_labels.size() == 0)) {
-
- return false;
- }
-
- transition t;
- t.orig_state = getOrigStateIndex();
- t.dest_state = getDestStateIndex();
- // increment number of edges for a state
- states[getOrigStateIndex()].num_outgoing += 1;
- states[getDestStateIndex()].num_incoming += 1;
-
- t.trans = getTransLabel();
-
- if ((t.orig_state != 0) && (states[t.orig_state].num_incoming == 0)) {
- return false;
- }
-
- // no dupes
- if (findTrans(t.orig_state, t.dest_state, t.trans.trigger, t.trans.guard, t.trans.action)) {
- return false;
- }
-
- transitions.push_back(t);
-// boost::add_edge(transition_properties());
-
- orig_state_index = 0;
- dest_state_index = 0;
- trans_label_index = 0;
- trigger_index = 0;
- guard_index = 0 ;
- action_index = 0;
-
+ transition_properties tp = transition_properties(t, g, a);
+ transition_labels.push_back(tp);
return true;
-
}
-*/
-bool cUMLStateDiagram::addTransitionLabel(int tr, int gu, int act)
-{
- transition_label t;
- t.trigger = tr;
- t.guard = gu;
- t.action = act;
- // currently, not checking for dupes, since we are seeding the labels.
-
- transition_labels.push_back(t);
-
- return true;
-}
-
bool cUMLStateDiagram::addTransitionTotal(int o, int d, int t, int g, int a) {
absoluteJumpGuard(g);
absoluteJumpAction(a);
@@ -505,6 +406,17 @@
}
+bool cUMLStateDiagram::addTransitionFromLabel() {
+ // get the properties of the transition label.
+ transition_properties tp = transition_labels[trans_label_index];
+
+ absoluteJumpTrigger(tp._tr);
+ absoluteJumpGuard(tp._gu);
+ absoluteJumpAction(tp._act);
+
+ return addTransitionTotal();
+}
+
bool cUMLStateDiagram::addTransitionTotal()
{
// Check that there are two vertices
@@ -512,14 +424,6 @@
return false;
}
-/* // Removed on 7/17/2007 - The scenarios should take care of this problem.
- // Check that the origin state of the transition is reachable.
- boost::graph_traits<state_diagram>::in_edge_iterator in_start, in_end;
- tie (in_start, in_end) = in_edges(orig, sd0);
- if ((in_start == in_end) && (orig != vertex(0, sd0))) {
- return false;
- }
-*/
// Disable transitions from one state to itself.
if (orig == dest) return false;
@@ -573,35 +477,6 @@
return o.str();
}
-/*void cUMLStateDiagram::executeVisitor() {
-
- PathVisitor visitor;
- boost::graph_traits<state_diagram>::vertex_descriptor o_temp;
- o_temp = vertex(0, sd0);
-
- boost::breadth_first_search(sd0, o_temp, boost::visitor(visitor));
-
-}
-
-
-struct transition_writer {
- transition_writer(cUMLStateDiagram::state_diagram& sd) : _sd(sd) { }
-
- template<typename Edge>
- void operator()(std::ostream& out) {
- out << "working?";
- }
-
- cUMLStateDiagram::state_diagram& _sd;
-};
-
-void cUMLStateDiagram::printGraphViz() {
- std::ofstream outfile("gv");
- boost::write_graphviz(outfile, sd0); //, transition_writer(sd0)); //, topo_vertex_writer(_topo_last_network));
- outfile.close();
-
-}*/
-
std::string cUMLStateDiagram::getXMI(std::string name)
{
printXMI(name);
Modified: branches/uml/source/main/cUMLStateDiagram.h
===================================================================
--- branches/uml/source/main/cUMLStateDiagram.h 2007-12-27 14:52:54 UTC (rev 2240)
+++ branches/uml/source/main/cUMLStateDiagram.h 2007-12-28 18:49:09 UTC (rev 2241)
@@ -22,12 +22,6 @@
int _tr, _gu, _act;
};
-struct transition_label {
- int trigger;
- int guard;
- int action;
-};
-
struct state {
int identifier;
int num_incoming;
@@ -42,14 +36,15 @@
class cUMLStateDiagram {
protected:
+
+ // used for both alphabet options
std::vector<trigger_info> triggers;
std::vector<std::string> guards;
std::vector<std::string> actions;
-// std::vector<transition> transitions;
- std::vector<transition_label> transition_labels;
+
+ // used for alphabet where a word is a transition label
+ std::vector<transition_properties> transition_labels;
-// int orig_state_index;
-// int dest_state_index;
int trans_label_index;
int trigger_index;
int guard_index;
@@ -77,7 +72,6 @@
bool findTrans(int, int, int, int, int);
-// bool findTransLabel(transition_label); // find a specific transition label
// Boost graph type for a state diagram.
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS,
@@ -90,37 +84,6 @@
template <typename T>
bool relativeMoveIndex (T x, int &y, int z);
-
- // pass in the path; state to know path step; examine_edge
- // Issue: the need to revisit the same node.
- //! A BGL breadth-first visitor used to see if a path is included in a state diagram.
-/*class PathVisitor : public boost::bfs_visitor< > {
-public:
- PathVisitor() {}
- template <class state_diagram>
- void tree_edge(typename boost::graph_traits<state_diagram>::edge_descriptor e, state_diagram& g) {
- typename boost::graph_traits<state_diagram>::vertex_descriptor u, v;
- u = boost::source(e, g);
- v = boost::target(e, g);
-// distance[v] = distance[u] + 1;
- std::cout << "origin: " << u << std::endl;
- std::cout << "destination: " << v << std::endl;
- std::cout << "tga: " << g[e]._tr << g[e]._gu << g[e]._act << std::endl;
- }
- };
-
-struct transition_writer {
- transition_writer(state_diagram& sd) : _sd(sd) { }
-
- template<typename Edge>
- void operator()(std::ostream& out) {
- out << "working?";
- }
-
- state_diagram& _sd;
-};
- */
-
// The jump functions jump the index of the various vectors either forward (+ int) or backwards (- int)
bool absoluteJumpGuard(int);
bool absoluteJumpAction(int);
@@ -138,28 +101,24 @@
// The get functions get the value of the index of various vectors
- int getTriggerIndex();
- int getGuardIndex();
- int getActionIndex();
+ int getTriggerIndex() { return trigger_index; }
+ int getGuardIndex() { return guard_index; }
+ int getActionIndex() { return action_index; }
+ int getTransitionLabelIndex() { return trans_label_index; }
std::string getGuard() { return guards[getGuardIndex()]; }
- transition_label getTransLabel();
std::string getName() { return sd_name; }
-// Visit graph
-// void executeVisitor();
-// void printGraphViz();
-
-
// Add functions
-// bool addTransition();
bool addTransitionTotal();
+ bool addTransitionFromLabel();
bool addTransitionTotal(int, int, int, int, int);
bool addTrigger(std::string, std::string);
bool addGuard(std::string);
bool addAction(std::string);
bool addTransitionLabel(int, int, int);
- // END UML functions
+
+
protected:
state_diagram sd0;
boost::graph_traits<state_diagram>::vertex_descriptor orig;
More information about the Avida-cvs
mailing list