[Avida-SVN] r1750 - in branches/uml: Avida.xcodeproj source/actions source/cpu source/main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Thu Jul 5 09:41:28 PDT 2007
Author: hjg
Date: 2007-07-05 12:41:28 -0400 (Thu, 05 Jul 2007)
New Revision: 1750
Modified:
branches/uml/Avida.xcodeproj/project.pbxproj
branches/uml/source/actions/PopulationActions.cc
branches/uml/source/actions/PrintActions.cc
branches/uml/source/cpu/cHardwareCPU.cc
branches/uml/source/cpu/cHardwareCPU.h
branches/uml/source/main/cDeme.cc
branches/uml/source/main/cDeme.h
branches/uml/source/main/cOrganism.cc
branches/uml/source/main/cPopulation.cc
branches/uml/source/main/cTaskLib.cc
branches/uml/source/main/cTaskLib.h
branches/uml/source/main/cUMLModel.cc
branches/uml/source/main/cUMLModel.h
branches/uml/source/main/cUMLStateDiagram.cc
branches/uml/source/main/cUMLStateDiagram.h
Log:
Changed to boost architecture for representing state diagrams.
Modified: branches/uml/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/uml/Avida.xcodeproj/project.pbxproj 2007-07-05 16:03:54 UTC (rev 1749)
+++ branches/uml/Avida.xcodeproj/project.pbxproj 2007-07-05 16:41:28 UTC (rev 1750)
@@ -2264,7 +2264,7 @@
isa = XCBuildConfiguration;
buildSettings = {
GCC_MODEL_CPU = G4;
- HEADER_SEARCH_PATHS = /usr/local/boost;
+ HEADER_SEARCH_PATHS = /opt/local/include/;
OTHER_LDFLAGS = (
"-multiply_defined",
suppress,
@@ -2277,6 +2277,7 @@
isa = XCBuildConfiguration;
buildSettings = {
GCC_MODEL_CPU = G4;
+ HEADER_SEARCH_PATHS = /opt/local/include/;
OTHER_LDFLAGS = (
"-multiply_defined",
suppress,
@@ -2394,6 +2395,7 @@
isa = XCBuildConfiguration;
buildSettings = {
GCC_MODEL_CPU = G4;
+ HEADER_SEARCH_PATHS = /opt/local/include/;
OTHER_LDFLAGS = (
"-multiply_defined",
suppress,
@@ -2406,6 +2408,7 @@
isa = XCBuildConfiguration;
buildSettings = {
GCC_MODEL_CPU = G4;
+ HEADER_SEARCH_PATHS = /opt/local/include/;
OTHER_LDFLAGS = (
"-multiply_defined",
suppress,
@@ -2623,6 +2626,7 @@
isa = XCBuildConfiguration;
buildSettings = {
GCC_MODEL_CPU = G4;
+ HEADER_SEARCH_PATHS = /opt/local/include/;
OTHER_LDFLAGS = (
"-multiply_defined",
suppress,
Modified: branches/uml/source/actions/PopulationActions.cc
===================================================================
--- branches/uml/source/actions/PopulationActions.cc 2007-07-05 16:03:54 UTC (rev 1749)
+++ branches/uml/source/actions/PopulationActions.cc 2007-07-05 16:41:28 UTC (rev 1750)
@@ -1005,7 +1005,6 @@
else if (in_trigger == "full_deme") m_rep_trigger = 1;
else if (in_trigger == "corners") m_rep_trigger = 2;
else if (in_trigger == "deme-age") m_rep_trigger = 3;
- else if (in_trigger == "uml-mod") m_rep_trigger = 4;
else {
cString err("Unknown replication trigger '");
err += in_trigger;
Modified: branches/uml/source/actions/PrintActions.cc
===================================================================
--- branches/uml/source/actions/PrintActions.cc 2007-07-05 16:03:54 UTC (rev 1749)
+++ branches/uml/source/actions/PrintActions.cc 2007-07-05 16:41:28 UTC (rev 1750)
@@ -1735,18 +1735,6 @@
}
};
-class cActionPrintDemeUMLStats : public cAction
-{
-public:
- cActionPrintDemeUMLStats(cWorld* world, const cString& args) : cAction(world, args) { ; }
-
- static const cString GetDescription() { return "No Arguments"; }
-
- void Process(cAvidaContext& ctx)
- {
- m_world->GetPopulation().PrintDemeUMLStats();
- }
-};
class cActionSetVerbose : public cAction
{
@@ -1822,7 +1810,7 @@
action_lib->Register<cActionPrintPhenotypeData>("PrintPhenotypeData");
action_lib->Register<cActionPrintPhenotypeStatus>("PrintPhenotypeStatus");
action_lib->Register<cActionPrintDemeStats>("PrintDemeStats");
- action_lib->Register<cActionPrintDemeUMLStats>("PrintDemeUMLStats");
+// action_lib->Register<cActionPrintDemeUMLStats>("PrintDemeUMLStats");
// Processed Data
@@ -1891,7 +1879,6 @@
action_lib->Register<cActionPrintPhenotypeData>("print_number_phenotypes");
action_lib->Register<cActionPrintPhenotypeStatus>("print_phenotype_status");
action_lib->Register<cActionPrintDemeStats>("print_deme_stats");
- action_lib->Register<cActionPrintDemeUMLStats>("print_deme_uml_stats");
action_lib->Register<cActionPrintData>("print_data");
Modified: branches/uml/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.cc 2007-07-05 16:03:54 UTC (rev 1749)
+++ branches/uml/source/cpu/cHardwareCPU.cc 2007-07-05 16:41:28 UTC (rev 1750)
@@ -347,8 +347,9 @@
tInstLibEntry<tMethod>("decay-reg", &cHardwareCPU::Inst_DecayRegulation),
// UML Element Creation
- tInstLibEntry<tMethod>("addState", &cHardwareCPU::Inst_AddState, false,
+/* tInstLibEntry<tMethod>("addState", &cHardwareCPU::Inst_AddState, false,
"Add a new state"),
+*/
tInstLibEntry<tMethod>("next", &cHardwareCPU::Inst_Next, false,
"Increment to the next position in the list"),
tInstLibEntry<tMethod>("prev", &cHardwareCPU::Inst_Prev, false,
@@ -357,8 +358,10 @@
tInstLibEntry<tMethod>("addTransLab", &cHardwareCPU::Inst_AddTransitionLabel, false,
"Add a transition label"),
*/
+/*
tInstLibEntry<tMethod>("addTrans", &cHardwareCPU::Inst_AddTransition, false,
- "Add a transition"),
+ "Add a transition"),
+*/
tInstLibEntry<tMethod>("addTransT", &cHardwareCPU::Inst_AddTransitionTotal, false,
"Add a transition without adding a label."),
tInstLibEntry<tMethod>("jump", &cHardwareCPU::Inst_JumpIndex, false,
@@ -4248,6 +4251,7 @@
}
*/
+/*
bool cHardwareCPU::Inst_AddState(cAvidaContext& ctx)
{
if(organism->GetCellID()==-1) return false;
@@ -4263,6 +4267,7 @@
return organism->getStateDiagram()->addTransition();
}
+*/
bool cHardwareCPU::Inst_AddTransitionTotal(cAvidaContext& ctx)
Modified: branches/uml/source/cpu/cHardwareCPU.h
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.h 2007-07-05 16:03:54 UTC (rev 1749)
+++ branches/uml/source/cpu/cHardwareCPU.h 2007-07-05 16:41:28 UTC (rev 1750)
@@ -535,13 +535,13 @@
bool Inst_Skip(cAvidaContext& ctx);
//// UML Element Construction ////
- bool Inst_AddState(cAvidaContext& ctx);
+// bool Inst_AddState(cAvidaContext& ctx);
bool Inst_Next(cAvidaContext& ctx);
bool Inst_Prev(cAvidaContext& ctx);
bool Inst_JumpIndex(cAvidaContext& ctx);
bool Inst_JumpDist(cAvidaContext& ctx);
// bool Inst_AddTransitionLabel(cAvidaContext& ctx);
- bool Inst_AddTransition(cAvidaContext& ctx);
+// bool Inst_AddTransition(cAvidaContext& ctx);
bool Inst_AddTransitionTotal(cAvidaContext& ctx);
// bool Inst_Last(cAvidaContext& ctx);
// bool Inst_First(cAvidaContext& ctx);
Modified: branches/uml/source/main/cDeme.cc
===================================================================
--- branches/uml/source/main/cDeme.cc 2007-07-05 16:03:54 UTC (rev 1749)
+++ branches/uml/source/main/cDeme.cc 2007-07-05 16:41:28 UTC (rev 1750)
@@ -43,9 +43,6 @@
birth_count = 0;
org_count = 0;
- // Initialize the UML model with 1 state diagram per
- umlMod.resetUMLModel();
-
// If width is negative, set it to the full number of cells.
width = in_width;
if (width < 1) width = cell_ids.GetSize();
@@ -77,7 +74,6 @@
{
birth_count = 0;
_age = 0;
- umlMod.resetStateDiagrams(cell_ids.GetSize());
}
Modified: branches/uml/source/main/cDeme.h
===================================================================
--- branches/uml/source/main/cDeme.h 2007-07-05 16:03:54 UTC (rev 1749)
+++ branches/uml/source/main/cDeme.h 2007-07-05 16:41:28 UTC (rev 1750)
@@ -67,8 +67,6 @@
//! Replaces this deme's germline.
void ReplaceGermline(const cGermline& germline);
- // UML Model functions
- cUMLModel* getUMLModel() { return ¨Mod; }
// -= Update support =-
//! Called once, at the end of every update.
@@ -83,8 +81,6 @@
int birth_count; //!< Number of organisms that have been born into this deme since reset.
int org_count; //!< Number of organisms are currently in this deme.
int _age; //!< Age of this deme, in updates.
- cUMLModel umlMod; // !< The UML model for this deme, if used.
- cUMLModel prevMod; // !< The previous (possibly parent) model for the deme, if used
cGermline _germline; //!< The germline for this deme, if used.
};
Modified: branches/uml/source/main/cOrganism.cc
===================================================================
--- branches/uml/source/main/cOrganism.cc 2007-07-05 16:03:54 UTC (rev 1749)
+++ branches/uml/source/main/cOrganism.cc 2007-07-05 16:41:28 UTC (rev 1750)
@@ -646,14 +646,7 @@
{
cUMLModel* temp_mod;
- // Check if using deme...
- if (m_world->GetConfig().NUM_DEMES.Get() != 1) {
- cDeme& deme = m_world->GetPopulation().GetDeme(m_world->GetPopulation().GetCell(GetCellID()).GetDemeID());
- temp_mod = deme.getUMLModel();
- } else {
-
- temp_mod = &m_model;
- }
+ temp_mod = &m_model;
return temp_mod;
}
@@ -693,7 +686,7 @@
}
// Determines if this is the transition the organism is about to add
-bool cOrganism::currTrans (int sd, int orig, int dest, int tr, int gu, int act)
+/*bool cOrganism::currTrans (int sd, int orig, int dest, int tr, int gu, int act)
{
// check if it is manipulating this diagram
if (sd != m_state_diag) return false;
@@ -708,6 +701,7 @@
return (s->currTrans(orig, dest, tr, gu, act));
}
+*/
bool cOrganism::absoluteJumpGuard(int amount)
{
Modified: branches/uml/source/main/cPopulation.cc
===================================================================
--- branches/uml/source/main/cPopulation.cc 2007-07-05 16:03:54 UTC (rev 1749)
+++ branches/uml/source/main/cPopulation.cc 2007-07-05 16:41:28 UTC (rev 1750)
@@ -760,16 +760,6 @@
}
}
break;
- case 7: {
- for (int deme_id = 0; deme_id < num_demes; deme_id++) {
- cDeme& cur_deme = deme_array[deme_id];
- double f = cur_deme.getUMLModel()->evaluateModel(deme_id, m_world);
- deme_fitness[deme_id] = f;
- total_fitness += f;
- }
- break;
- }
-
}
// Pick which demes should be in the next generation.
@@ -1156,29 +1146,6 @@
}
-void cPopulation::PrintDemeUMLStats()
-{
- cStats& stats = m_world->GetStats();
- cDataFile& df_uml = m_world->GetDataFile("deme_uml.dat");
- df_uml.WriteComment("UML info for each deme in the population");
- // Going to bypass cDataFile for the rest of this.
- std::ostream& out = df_uml.GetOFStream();
-
- out << "Update: " << stats.GetUpdate() << endl;
-
- const int num_demes = deme_array.GetSize();
- for (int deme_id = 0; deme_id < num_demes; deme_id++) {
- out << "Deme: " << deme_id << endl;
-
- // Print all the self_bonus info
- const std::map<std::string, double>& uml_bonus = deme_array[deme_id].getUMLModel()->getBonus();
- std::map<std::string, double>::const_iterator iter;
- for(iter=uml_bonus.begin(); iter != uml_bonus.end(); ++iter) {
- out << iter->first << ": " << iter->second << endl;
- }
- }
-}
-
// Print out statistics about individual demes
void cPopulation::PrintDemeStats()
Modified: branches/uml/source/main/cTaskLib.cc
===================================================================
--- branches/uml/source/main/cTaskLib.cc 2007-07-05 16:03:54 UTC (rev 1749)
+++ branches/uml/source/main/cTaskLib.cc 2007-07-05 16:41:28 UTC (rev 1750)
@@ -417,8 +417,6 @@
NewTask(name, "Successfully ran Spin witness trace", &cTaskLib::Task_SpinW1);
else if (name == "mult_trans") //
NewTask(name, "Successfully completed multiple transitions", &cTaskLib::Task_MultTrans);
- else if (name == "mod_eval") //
- NewTask(name, "Successfully evaluated model", &cTaskLib::Task_ModEval);
@@ -3066,16 +3064,7 @@
return (2^ctx.task_success_complete);
}
-double cTaskLib::Task_ModEval(cTaskContext& ctx) const {
- double bonus = 0.0;
- cUMLModel* self = ctx.organism->getUMLModel();
-
- bonus = self->evaluateModel(ctx.organism->GetID(), m_world);
-
- return bonus;
-}
-
double cTaskLib::Task_PropTrigger(cTaskContext& ctx) const {
// This task checks for the trigger of the property.
cOrganism* organism = ctx.organism;
Modified: branches/uml/source/main/cTaskLib.h
===================================================================
--- branches/uml/source/main/cTaskLib.h 2007-07-05 16:03:54 UTC (rev 1749)
+++ branches/uml/source/main/cTaskLib.h 2007-07-05 16:41:28 UTC (rev 1750)
@@ -296,7 +296,6 @@
double Task_SpinN1(cTaskContext& ctx) const;
double Task_SpinW1(cTaskContext& ctx) const;
double Task_MultTrans(cTaskContext& ctx) const;
- double Task_ModEval(cTaskContext& ctx) const;
};
Modified: branches/uml/source/main/cUMLModel.cc
===================================================================
--- branches/uml/source/main/cUMLModel.cc 2007-07-05 16:03:54 UTC (rev 1749)
+++ branches/uml/source/main/cUMLModel.cc 2007-07-05 16:41:28 UTC (rev 1750)
@@ -21,7 +21,8 @@
}
//read from file; load into string/strstream, and return it.
-
+ infile.close();
+
return data;
}
@@ -34,24 +35,13 @@
cUMLModel::cUMLModel()
{
// initialize / seed UML model here
- resetUMLModel();
-
+// state_diagrams.clear();
+// state_diagrams.resize(2);
}
cUMLModel::~cUMLModel()
-{
-}
+{}
-
-
-void cUMLModel::resetUMLModel()
-{
- // Currently there are 2 state diagrams...
- resetStateDiagrams(2);
- return;
-
-}
-
cUMLStateDiagram* cUMLModel::getStateDiagram (int x)
{
// check to see whether this state diagram exists
@@ -61,285 +51,82 @@
}
-cUMLClassDiagram* cUMLModel::getClassDiagram (int x)
-{
- // check to see whether this state diagram exists
- if (x < class_diagrams.size()) {
- return (&(class_diagrams.begin()[x]));
- }
-
-}
-
-void cUMLModel::resetStateDiagrams(int x)
-{
- // reset the number of state diagrams.
- state_diagrams.clear();
- state_diagrams.resize(x);
- class_diagrams.clear();
- class_diagrams.resize(x);
- seedDiagrams();
-}
-
+/* This is a crappy little function to read in from a file.
+It is not robust. It will not understand things unless you
+follow the *very* specific file format. */
void cUMLModel::seedDiagrams()
{
- self_bonus.clear();
-
-/*
- // Used for simple example - tagaaa model
- cUMLStateDiagram* temp = getStateDiagram(0);
- temp->addTransitionLabel(1, 2, 3);
- temp->addTransitionLabel(0, 0, 0);
- temp->addTransitionLabel(0, 3, 1);
- temp->addTransitionLabel(2, 1, 2);
- temp->addTransitionLabel(3, 0, 0);
-
- std::string trig_label = "ta";
- std::string trig_operation_id = "ta";
- temp->addTrigger(trig_label, trig_operation_id);
-
- trig_label = "tb";
- trig_operation_id = "tb";
- temp->addTrigger(trig_label, trig_operation_id);
-
- trig_label = "tc";
- trig_operation_id = "tc";
- temp->addTrigger(trig_label, trig_operation_id);
-
- trig_label = "td";
- trig_operation_id = "td";
- temp->addTrigger(trig_label, trig_operation_id);
-
- temp->addGuard("ga");
- temp->addGuard("gb");
- temp->addGuard("gc");
- temp->addGuard("gd");
-
- temp->addAction("aa");
- temp->addAction("ab");
- temp->addAction("ac");
- temp->addAction("ad");
-
-
-
-
- cUMLStateDiagram* temp1 = getStateDiagram(1);
- temp1->addTransitionLabel(3, 2, 1);
- temp1->addTransitionLabel(0, 1, 0);
- temp1->addTransitionLabel(2, 0, 3);
- temp1->addTransitionLabel(2, 1, 0);
- temp1->addTransitionLabel(1, 1, 1);
- */
-
- // Used for Temperature Sensor / MultiSensor example.
-
- // For the first state diagram...
- // Software Sensor
- cUMLStateDiagram* soft_sense = getStateDiagram(1);
+ std::string data, line; // or maybe stringstream? (strstream?)
+ int num_states;
+ int num_sd = 0;
+ int cur_sd = -1;
+ char c;
+ std::string tr_l, tr_o, gu, act;
+ std::ifstream infile;
+ infile.open("seed-model.cfg");
+ assert(infile.is_open());
- // init triggers, guards, and actions
- // trig 0
- std::string trig_label = "<null>";
- std::string trig_operation_id = "<null>";
- soft_sense->addTrigger(trig_label, trig_operation_id);
- // trig 1
- trig_label = "setTempOpState";
- trig_operation_id = "XDE-4437EBF1-9C42-4EB4-B7CF-415697B567CD";
- soft_sense->addTrigger(trig_label, trig_operation_id);
- // trig 2
- trig_label = "setTempData";
- trig_operation_id = "XDE-9517D6BA-8666-4A82-AFEA-62D60FE37B07";
- soft_sense->addTrigger(trig_label, trig_operation_id);
- // guard 0
- soft_sense->addGuard("<null>");
- // action 0
- soft_sense->addAction("<null>");
- // action 1
- soft_sense->addAction("^TempSensor.getOpState()");
- // action 2
- soft_sense->addAction("^TempSensor.getTempData()");
-
- //seeded transitions...
-// soft_sense->addTransitionTotal(0, 1, 0, 0, 0);
-// soft_sense->addTransitionTotal(1, 2, 0, 0, 2);
-// soft_sense->addTransitionTotal(2, 3, 2, 0, 0);
-// soft_sense->addTransitionTotal(3, 1, 0, 0, 0);
-
- // Temperature Sensor
- cUMLStateDiagram* temp_sense = getStateDiagram(0);
-
- // init triggers, guards, and actions
- // trig 0
- trig_label = "<null>";
- trig_operation_id = "<null>";
- temp_sense->addTrigger(trig_label, trig_operation_id);
- // trig 1
- trig_label = "getOpState";
- trig_operation_id = "XDE-73C1C501-493F-44F2-A70A-0C7BFA92160D";
- temp_sense->addTrigger(trig_label, trig_operation_id);
- // trig 2
- trig_label = "getTempData";
- trig_operation_id = "XDE-7C41CD1F-6E52-4E32-9C8E-999BA1919EC6";
- temp_sense->addTrigger(trig_label, trig_operation_id);
- // guard 0
- temp_sense->addGuard("<null>");
- // action 0
- temp_sense->addAction("<null>");
- // action 1
- temp_sense->addAction("^SoftwareSensor.setTempOpState(op_state)");
- // action 2
- temp_sense->addAction("^SoftwareSensor.setTempData(data)");
- // action 3
- temp_sense->addAction("op_state:=1");
- // action 4
- temp_sense->addAction("op_state:=0");
- // action 5
- temp_sense->addAction("data:=100");
- // action 6
- temp_sense->addAction("data:=200");
- // action 7
- temp_sense->addAction("data:=300");
-
-
-
-}
-
-double cUMLModel::evaluateModel(int id, cWorld* world)
-{
- double bonus = 0.0;
- double mod_bonus = 0.0;
-
- double size = state_diagrams.size();
-
- int s0_nt = getStateDiagram(0)->numTrans();
- int s1_nt = getStateDiagram(1)->numTrans();
-
- cUMLStateDiagram* temp_sense = getStateDiagram(0);
- cUMLStateDiagram* soft_sense = getStateDiagram(1);
-
- world->GetStats().addState(temp_sense->numStates() + soft_sense->numStates());
- world->GetStats().addTrans(s0_nt + s1_nt);
-
-
- // Check if the model meets the sequence diagram
-// bonus += checkForSequenceDiagram1();
+ while (getline (infile, line))
+ {
+ // Read in states
+ if (line == "=STATES====================") {
+ std::cout << "Ooh, I found a state! " << std::endl;
+ line.erase();
+ infile >> num_states;
+ std::cout << "Numer of states: "<< num_states << std::endl;
+ // Read in number of state diagrams
+ } else if (line == "=STATE-DIAGRAM=============") {
+ std::cout << "Yippee! A state diagram for me! " << std::endl;
+ line.erase();
+ infile >> num_sd;
+ std::cout << "Numer of sds: "<< num_sd << std::endl;
+ state_diagrams.resize(num_sd);
+ // Read in each state diagram
+ } else if (line == "=SD========================") {
+ line.erase();
+ cur_sd++;
+ } else if (line == "-TRIGGERS------------------") {
+ line.erase();
+ infile >> tr_l;
+ while (tr_l != "-END---------------------------") {
+ infile >> tr_o;
+ state_diagrams[cur_sd].addTrigger(tr_l, tr_o);
+ std::cout << "Adding a trigger " << tr_l << " " << tr_o << std::endl;
+ infile >> tr_l;
+ }
+ }else if (line == "-GUARDS--------------------") {
+ line.erase();
+ infile >> gu;
+ while (gu != "-END---------------------------") {
+ state_diagrams[cur_sd].addGuard(gu);
+ std::cout << "Adding a guard " << gu << std::endl;
+ infile >> gu;
+ }
+ } else if (line == "-ACTIONS--------------------") {
+ line.erase();
+ infile >> act;
+ while (act != "-END---------------------------") {
+ state_diagrams[cur_sd].addAction(act);
+ std::cout << "Adding an action " << act << std::endl;
+ infile >> act;
+ }
+ }
+ /* Missing code for reading in transition labels and transitions.... */
- // Check if the model can be correctly formalized
-// if (bonus >= 5.0) {
- if (temp_sense->findTrans(-1, -1, -1, -1, 3)) {
- self_bonus["hydra_attempt"] = 1;
- mod_bonus = formalizeModel(world);
- self_bonus["hydra_pass"] = mod_bonus;
- bonus += mod_bonus;
- }
-
- // Check if the model meets the properties.
- if (mod_bonus > 0.0) {
- self_bonus["spin_attempt"] = 1;
- mod_bonus += propertyN1(id, world);
- self_bonus["spin_pass"] = mod_bonus;
- bonus += mod_bonus;
+
+ line.erase();
}
-
- // additional bonus for creating transitions...
- if (s0_nt <= 2) {
- bonus += (s0_nt / 4);
- } else {
- bonus += .5;
- }
- if (s1_nt <= 2) {
- bonus += (s1_nt / 4);
- } else {
- bonus += .5;
- }
-
-
+ //read from file; load into string/strstream, and return it.
+ infile.close();
- return bonus;
+ return;
+
}
-double cUMLModel::checkForSequenceDiagram1()
-{
- double bonus = 0.0;
- double temp_bonus = 0.0;
-
-
- cUMLStateDiagram* soft_sense = getStateDiagram(1);
- cUMLStateDiagram* temp_sense = getStateDiagram(0);
-
- int nt = soft_sense->numTrans() + temp_sense->numTrans();
-/* // reward if number of transitions is greater than 10
- int nt = soft_sense->numTrans() + temp_sense->numTrans();
- if (nt <= 10) {
- bonus += nt;
- } else {
- bonus += 10;
- }
-*/
-
-
-
- // Software Sensor
-
- // action:
- // TempSensor.getOpState()
-// temp_bonus = soft_sense->findTrans(-1, -1, -1, "*", "^TempSensor.getOpState()");
- temp_bonus = soft_sense->findTrans(-1, -1, -1, -1, 1);
- self_bonus["seq_d_1"] = temp_bonus;
- bonus += temp_bonus;
-
- // trigger:
- // setTempOpState(op_state)
-// temp_bonus = soft_sense->findTrans(-1, -1, 1, "*", "*");
- temp_bonus = soft_sense->findTrans(-1, -1, 1, -1, -1);
- self_bonus["seq_d_2"] = temp_bonus;
- bonus += temp_bonus;
-
-
- // Temperature Sensor
-
- // trigger:
- // getOpState()
- temp_bonus = temp_sense->findTrans(-1, -1, 1, -1, -1);
- self_bonus["seq_d_3"] = temp_bonus;
- bonus += temp_bonus;
-
-
- // action:
- // op_state := 1
- //temp_bonus = temp_sense->findTrans(-1, -1, -1, "*", "op_state:=1");
- temp_bonus = temp_sense->findTrans(-1, -1, -1, -1, 3);
-
- self_bonus["seq_d_4"] = temp_bonus;
- bonus += temp_bonus;
-
-// temp_bonus = temp_sense->findTrans(-1, -1, -1, "*", "^SoftwareSensor.setTempOpState(op_state)");
- temp_bonus = temp_sense->findTrans(-1, -1, -1, -1, 1);
-
- self_bonus["seq_d_5"] = temp_bonus;
- bonus += temp_bonus;
-
- // For each state diagram, look for the relevant transitions
-/* if(getStateDiagram(0)->findTrans(-1, -1, -1, "*", "<null>")) {
- bonus += 1.0;
- }
- if(getStateDiagram(1)->findTrans(-1, -1, -1, "*", "<null>")) {
- bonus += 1.0;
- }
- if(getStateDiagram(2)->findTrans(-1, -1, -1, "*", "<null>")) {
- bonus += 1.0;
- }*/
-
-
-// bonus += formalizeModel();
-// bonus += propertyN1();
-
- return bonus;
-}
-
void cUMLModel::printXMI()
{
xmi = "";
@@ -358,167 +145,8 @@
std::string cUMLModel::getXMI()
{
- std::string x;
-// int v;
-
- x = xmi_begin;
-
-// x += xmi_class1;
-// x += state_diagrams[0].getXMI();
-// x += xmi_class2;
- x += state_diagrams[1].getXMI();
-
-
-
- // get the xmi for each state diagram
-// for (v = 0; v < state_diagrams.size(); ++v) {
-// state_diagrams[v].printXMI();
-// x+=state_diagrams[v].getXMI();
-// }
-
- x += xmi_end;
-
- return x;
-}
-
-double cUMLModel::formalizeModel(cWorld* world)
-{
printXMI();
- std::string temp = xmi;
-
-
-/*( if (temp == organism->getParentXMI()) {
- ctx.task_success_complete += organism->getParentBonusInfo("hydra");
- organism->setBonusInfo("hydra", organism->getParentBonusInfo("hydra"));
- return organism->getParentBonusInfo("hydra");
- }*/
-
-
- world->GetStats().HydraAttempt();
-
- double bonus = 0.0;
- unsigned int status_total = 0;
- int status=0;
-
- int to_subavida[2]={0};
- int from_subavida[2]={0};
-
- pipe(to_subavida); //write to 1, read from 0
- pipe(from_subavida);
-
- pid_t subavida = fork();
- if(subavida == 0) {
- //child
- close(to_subavida[1]);
- close(from_subavida[0]);
- dup2(to_subavida[0], STDIN_FILENO); //oldd, newd
- dup2(from_subavida[1], STDOUT_FILENO);
- execl("/usr/bin/java", "-cp .", "-jar", "./hydraulic.jar", 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!)
- do {
- status = write(to_subavida[1], temp.c_str()+status_total, temp.size());
- if (status < 0) {
- break;
- } else {
- status_total += status;
- }
- } while (status_total < temp.size());
- close(to_subavida[1]); // Wakes up subavida.
-
- // Time passes...
-
- // 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[read_size]={0};
- do {
- status = read(from_subavida[0], line, read_size-1);
- if(status > 0) {
- subavida_output += line;
- 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);
-
- // if there are no errors, return 0 from hydraulic. otherwise, return non-zero.
- if(status != 0) {
-// ctx->task_failed = 0;
-// organism->setBonusInfo("hydra", 0.0);
- return 0;
- } else {
- // ctx->task_failed = ctx->task_failed && 1;
-// ctx.task_success_complete += 1;
- world->GetStats().HydraPassed();
-// organism->setBonusInfo("hydra", 1.0);
- return 1;
- }
-
+ return xmi;
}
-double cUMLModel::checkProperty(const std::string& neverclaimFile, int id, cWorld* world) const {
- world->GetStats().SpinAttempt();
- double status=0;
- std::string cmd = "cat " + neverclaimFile + " >> tmp.pr && ./spin -a tmp.pr &> /dev/null";
- if(system(cmd.c_str())!=0) return 0;
- world->GetStats().SpinPassed();
- world->GetStats().PanAttempt();
-
- if(system("/usr/bin/gcc -DMEMLIM=512 pan.c -o pan &> /dev/null")!=0) return 0;
- if(system("./pan -a &> ./pan.out")!=0) return 0;
- if(system("cat pan.out | perl -e 'while(<STDIN>) { if(/errors:\\s(\\d+)/) {exit($1);}}'")!=0) return 0;
-
- if(system("cat pan.out | perl -e 'while(<STDIN>) { if(/unreached/) {exit(1);}}'")!=0) return 1;
-
- std::ostringstream strstrm;
- strstrm << "cp tmp.xmi " << world->GetStats().GetUpdate() << "." << id;
- strstrm << ".xml";
- if(system(strstrm.str().c_str())!=0) return 0.0;
-
- world->GetStats().PanPassed();
- return 3;
-}
-
-double cUMLModel::propertyN1(int deme_id, cWorld* world) const {
- std::string temp = xmi;
- double temp1 = 0;
-
-/*
- if (temp == organism->getParentXMI()) {
- ctx.task_success_complete += organism->getParentBonusInfo("spinn1");
- organism->setBonusInfo("spinn1", organism->getParentBonusInfo("spinn1"));
- return organism->getParentBonusInfo("spinn1");
- }
-*/
-
- // check if the trigger is present in the relevant diagram...
-// if (organism->getStateDiagram()->findTrans(-1,-1,1,"*","*")){
-// temp += 1;
-
- // check property
-// if (ctx.task_success_complete) {
- temp1 += checkProperty("N1", deme_id, world);
-// }
-// }
-
-// organism->setBonusInfo("spinn1", temp1);
- return temp1;
-}
-
-
Modified: branches/uml/source/main/cUMLModel.h
===================================================================
--- branches/uml/source/main/cUMLModel.h 2007-07-05 16:03:54 UTC (rev 1749)
+++ branches/uml/source/main/cUMLModel.h 2007-07-05 16:41:28 UTC (rev 1750)
@@ -2,9 +2,8 @@
#define _C_UMLMODEL_H_
#include "cUMLStateDiagram.h"
-#include "cUMLClassDiagram.h"
-#include "cWorld.h"
-#include "cStats.h"
+//#include "cWorld.h"
+//#include "cStats.h"
#include <string>
#include <iostream>
@@ -19,30 +18,15 @@
public:
cUMLModel();
~cUMLModel();
- std::string getXMI(); // get the XMI version of the model
- void printXMI();
- void resetUMLModel();
- double formalizeModel(cWorld*); // formalize the model using Hydra
- double checkProperty(const std::string& neverclaimFile, int, cWorld*) const; // check for property satisfaction using Spin
- double propertyN1(int, cWorld*) const; // check for property N1
+
+ void seedDiagrams(); // add the building blocks for the diagrams.
- void resetStateDiagrams (int);
- void seedDiagrams();
+ std::string getXMI(); // get the XMI version of the model.
+ void printXMI(); // create the XMI version of the model.
int getStateDiagramSize() { return state_diagrams.size(); }
-
- // Track bonus info for model
- std::map <std::string, double> getBonus() {return self_bonus;}
- void setBonusInfo(std::string x, double y) {self_bonus[x] = y;}
-
cUMLStateDiagram* getStateDiagram (int);
- cUMLClassDiagram* getClassDiagram (int);
- // Determine the "fitness" of the model
- // does the model satisfy the sequence diagrams?
- // does the model meet the properties?
- double evaluateModel(int, cWorld*);
- double checkForSequenceDiagram1();
protected:
static std::string xmi_begin;
@@ -51,11 +35,7 @@
static std::string xmi_class1;
static std::string xmi_class2;
std::vector<cUMLStateDiagram> state_diagrams;
- std::vector<cUMLClassDiagram> class_diagrams;
-
- // UML - Track information about the bonus received for this model.
- std::map <std::string, double> self_bonus;
-
+
};
#endif
Modified: branches/uml/source/main/cUMLStateDiagram.cc
===================================================================
--- branches/uml/source/main/cUMLStateDiagram.cc 2007-07-05 16:03:54 UTC (rev 1749)
+++ branches/uml/source/main/cUMLStateDiagram.cc 2007-07-05 16:41:28 UTC (rev 1750)
@@ -3,96 +3,177 @@
cUMLStateDiagram::cUMLStateDiagram()
{
+ // initialize the state diagram with 10 states.
+ sd0 = state_diagram(10);
+
// initialize / seed UML state diagram here
- orig_state_index = 0;
- dest_state_index = 0;
+// orig_state_index = 0;
+// dest_state_index = 0;
+ orig = vertex(0, sd0);
+ dest = vertex(0, sd0);
+
trans_label_index = 0;
trigger_index = 0;
guard_index = 0;
action_index = 0;
xmi = "";
-
-
- // initialize w/ 10 states
-
- state s;
- for (int i=0; i<11; i++) {
- s.identifier = i;
- s.num_incoming = 0;
- s.num_outgoing = 0;
- states.push_back(s);
- }
-
+
}
cUMLStateDiagram::~cUMLStateDiagram()
{
}
-
-/*
-bool cUMLStateDiagram::findTransLabel(transition_label t) {
- for(std::vector<transition_label>::iterator i=transition_labels.begin(); i!=transition_labels.end(); ++i){
- if ((i->trigger == t.trigger) && (i->guard == t.guard) && (i->action == t.action)) {
- return true;
+float cUMLStateDiagram::findPath(std::deque<std::string> p) {
+ bool res = false;
+ int num_vert = num_vertices(sd0);
+ std::deque<std::string> p_temp = p;
+ int possible_length = p.size();
+ int current_length = 0;
+ int len = 0;
+ float val;
+
+ while (!p.empty()) {
+ for (int i = 0; i<num_vert; i++) {
+ checkForPath(p_temp, vertex(i, sd0), res, len);
+ // check to see if this path is longer than other paths....
+ if (len > current_length) {
+ current_length = len;
+ }
}
- }
- return false;
+ p.pop_front();
+ p_temp = p;
+ res = false;
+ len = 0;
+ }
+
+// std::cout << "Longest path length: " << current_length << std::endl;
+// std::cout << "Possible path length: " << possible_length << std::endl;
+ val = current_length / possible_length;
+ return (val);
}
-
-bool cUMLStateDiagram::findTrans(int orig, int dest, std::string tr, std::string gu, std::string act)
-{
- int tracker = 0;
+void cUMLStateDiagram::checkForPath(std::deque<std::string> path,
+ boost::graph_traits<state_diagram>::vertex_descriptor v, bool& result,
+ int& dist) {
- for(std::vector<trigger_info>::iterator i=triggers.begin(); i!=triggers.end(); i++) {
- if (tr == i->label) {
- return findTrans(orig, dest, tracker, gu, act );
- }
- tracker++;
+ // declare temp strings for triggers, guards, and actions
+ std::string tt, tg, ta, ts;
+
+ // If the path is empty or the result is already true, then
+ // return true to indicate that the path has been found.
+ if ((path.empty()) || (result == true)) {
+ result = true;
+ return;
}
+
+ // Get all outgoing edges
+ boost::graph_traits<state_diagram>::out_edge_iterator out_edge_start, out_edge_end;
+ boost::graph_traits<state_diagram>::edge_descriptor ed;
- return false;
+ // Check to see if any have the same label as the first element of path
+ // If so, then call this function on them with the tail of the path
+ for(tie(out_edge_start, out_edge_end) = out_edges(v, sd0);
+ out_edge_start != out_edge_end; ++out_edge_start) {
+ ed = *out_edge_start;
+ tt = triggers[(sd0[ed]._tr)].operation_id;
+ tg = guards[(sd0[ed]._gu)];
+ ta = actions[(sd0[ed]._act)];
+
+ // eliminate nulls
+ if (tt == "<null>") tt = "";
+ if (tg == "<null>") tg = "";
+ if (ta == "<null>") ta = "";
+
+ ts = tt + tg + ta;
+// std::cout << "Looking for an edge with " << path.front() << std::endl;
+// std::cout << "Found an edge with " << ts << std::endl;
+
+ if (ts == path.front()) {
+// std::cout << "Found an edge with " << ts << std::endl;
+ dist++;
+ path.pop_front();
+ checkForPath(path, target(ed, sd0), result, dist);
+ }
+ }
}
-// Check to see if i->trans.trigger is ever equal to trig
-bool cUMLStateDiagram::findTrans(int orig, int dest, int trig, std::string gu, std::string act)
+
+bool cUMLStateDiagram::findTrans(int origin, int destination, int trig, int gu, int act)
{
- // the wild cards for there are
- // -1 for orig, dest & trigger
- // "*" for guard, and action
- for(std::vector<transition>::iterator i=transitions.begin(); i!=transitions.end(); ++i){
- if (((orig == -1) || (orig == i->orig_state)) &&
- ((dest == -1) || (dest == i->dest_state)) &&
- ((trig == -1) || (trig == i->trans.trigger)) &&
- ((gu == "*") || (gu == i->trans.guard)) &&
- ((act == "*") || (act == i->trans.action))) {
- return true;
- }
- }
- return false;
-}
-*/
+ bool result = false;
+
+ boost::graph_traits<state_diagram>::vertex_descriptor o_temp, d_temp;
+ boost::graph_traits<state_diagram>::edge_iterator edge_start, edge_end;
+ boost::graph_traits<state_diagram>::out_edge_iterator out_edge_start, out_edge_end;
+ boost::graph_traits<state_diagram>::in_edge_iterator in_edge_start, in_edge_end;
+ boost::graph_traits<state_diagram>::edge_descriptor ed;
-bool cUMLStateDiagram::findTrans(int orig, int dest, int trig, int gu, int act)
-{
- for(std::vector<transition>::iterator i=transitions.begin(); i!=transitions.end(); ++i){
- if (((orig == -1) || (orig == i->orig_state)) &&
- ((dest == -1) || (dest == i->dest_state)) &&
- ((trig == -1) || (trig == i->trans.trigger)) &&
- ((gu == -1) || (gu == i->trans.guard)) &&
- ((act == -1) || (act == i->trans.action))) {
- return true;
- }
+ // Get the set of transitions.
+ if ((origin == -1) && (destination == -1)) {
+ for (tie(edge_start, edge_end) = edges(sd0);
+ edge_start != edge_end; ++edge_start) {
+ ed = *edge_start;
+ if (((trig == -1) || (sd0[ed]._tr == trig)) &&
+ ((gu == -1) || (sd0[ed]._gu == gu)) &&
+ ((act == -1) || (sd0[ed]._act == act))) {
+ result = true;
+ break;
+ }
+ }
+ } else if (origin == -1 && destination != -1) {
+ if (destination > num_vertices(sd0)) return result;
+ d_temp = vertex(destination, sd0);
+ for (tie(in_edge_start, in_edge_end) = in_edges(d_temp, sd0);
+ in_edge_start != in_edge_end; ++in_edge_start) {
+ ed = *in_edge_start;
+ if (((trig == -1) || (sd0[ed]._tr == trig)) &&
+ ((gu == -1) || (sd0[ed]._gu == gu)) &&
+ ((act == -1) || (sd0[ed]._act == act))) {
+ result = true;
+ break;
+ }
+ }
+ } else if (origin != -1 && destination == -1) {
+ if (origin > num_vertices(sd0)) return result;
+ o_temp = vertex(origin, sd0);
+
+ for(tie(out_edge_start, out_edge_end) = out_edges(o_temp, sd0);
+ out_edge_start != out_edge_end; ++out_edge_start) {
+ ed = *out_edge_start;
+ if (((trig == -1) || (sd0[ed]._tr == trig)) &&
+ ((gu == -1) || (sd0[ed]._gu == gu)) &&
+ ((act == -1) || (sd0[ed]._act == act))) {
+ result = true;
+ break;
+ }
+ }
+ } else if (origin != -1 && destination != -1) {
+ if ((destination > num_vertices(sd0)) ||
+ (origin > num_vertices(sd0))) return result;
+ o_temp = vertex(origin, sd0);
+ d_temp = vertex(destination, sd0);
+ for(tie(out_edge_start, out_edge_end) = edge_range (o_temp, d_temp, sd0);
+ out_edge_start != out_edge_end; ++out_edge_start) {
+ ed = *out_edge_start;
+ if (((trig == -1) || (sd0[ed]._tr == trig)) &&
+ ((gu == -1) || (sd0[ed]._gu == gu)) &&
+ ((act == -1) || (sd0[ed]._act == act))) {
+ result = true;
+ break;
+ }
+ }
}
- return false;
+
+ return result;
}
+
template <typename T>
bool cUMLStateDiagram::absoluteMoveIndex (T x, int &index, int amount )
{
@@ -113,7 +194,6 @@
}
if (amount > 0) {
-// index += (amount % x.size()); // this provides relative jumping
index += (amount % x.size());
// index is greater than vector
@@ -150,47 +230,26 @@
}
bool cUMLStateDiagram::absoluteJumpOriginState(int jump_amount)
-{
- return absoluteMoveIndex(states, orig_state_index, jump_amount);
+{
+ bool result = false;
+ if (num_vertices(sd0) > jump_amount) {
+ orig = vertex(jump_amount, sd0);
+ result = true;
+ }
+ return result;
}
bool cUMLStateDiagram::absoluteJumpDestinationState(int jump_amount)
-{
- return absoluteMoveIndex(states, dest_state_index, jump_amount);
+{
+ bool result = false;
+ if (num_vertices(sd0) > jump_amount) {
+ dest = vertex(jump_amount, sd0);
+ result = true;
+ }
+ return result;
}
-/*
-bool cUMLStateDiagram::relativeJumpTrigger(int jump_amount)
-{
- return relativeMoveIndex(triggers, trigger_index, jump_amount);
-}
-bool cUMLStateDiagram::relativeJumpGuard(int jump_amount)
-{
- return relativeMoveIndex(guards, guard_index, jump_amount);
-}
-
-bool cUMLStateDiagram::relativeJumpAction(int jump_amount)
-{
- return relativeMoveIndex(actions, action_index, jump_amount);
-}
-
-bool cUMLStateDiagram::relativeJumpTransitionLabel(int jump_amount)
-{
- return relativeMoveIndex(transition_labels, trans_label_index, jump_amount);
-}
-
-bool cUMLStateDiagram::relativeJumpOriginState(int jump_amount)
-{
- return relativeMoveIndex(states, orig_state_index, jump_amount);
-}
-
-bool cUMLStateDiagram::relativeJumpDestinationState(int jump_amount)
-{
- return relativeMoveIndex(states, dest_state_index, jump_amount);
-}
-*/
-
int cUMLStateDiagram::getTriggerIndex()
{
return trigger_index;
@@ -207,32 +266,12 @@
}
-int cUMLStateDiagram::getOrigStateIndex()
-{
- return orig_state_index;
-}
-
-int cUMLStateDiagram::getDestStateIndex()
-{
- return dest_state_index;
-}
transition_label cUMLStateDiagram::getTransLabel()
{
return transition_labels[trans_label_index];
}
-bool cUMLStateDiagram::addState()
-{
- state s;
- s.identifier = states.size();
- s.num_incoming = 0;
- s.num_outgoing = 0;
- states.push_back(s);
-
- return true;
-}
-
bool cUMLStateDiagram::addTrigger(std::string op_id, std::string lab)
{
trigger_info t;
@@ -257,29 +296,6 @@
}
/*
-// Broken - 5/17
-bool cUMLStateDiagram::addTransitionLabel()
-{
- transition_label t;
- t.trigger = getTriggerIndex();
- t.guard = getGuard();
- t.action = getAction();
-
- // no dupes
- if (findTransLabel(t)){
- return false;
- }
-
- transition_labels.push_back(t);
-
- // Move the transition label index to the most recently created
- trans_label_index = transition_labels.size() - 1;
-
- return false;
-}
-*/
-
-
bool cUMLStateDiagram::addTransition()
{
@@ -307,6 +323,7 @@
}
transitions.push_back(t);
+// boost::add_edge(transition_properties());
orig_state_index = 0;
dest_state_index = 0;
@@ -318,6 +335,7 @@
return true;
}
+*/
bool cUMLStateDiagram::addTransitionLabel(int tr, int gu, int act)
{
@@ -332,143 +350,54 @@
}
-
-
-bool cUMLStateDiagram::addTransitionTotal(int o, int d, int t, int g, int a)
+bool cUMLStateDiagram::addTransitionTotal()
{
- if ((states.size() == 0)) {
-
+ // Check that there are two vertices
+ if (num_vertices(sd0) == 0) {
return false;
}
- absoluteMoveIndex(states, orig_state_index, o);
- absoluteMoveIndex(states, dest_state_index, d);
- absoluteMoveIndex(triggers, trigger_index, t);
- absoluteMoveIndex(guards, guard_index, g);
- absoluteMoveIndex(actions, action_index, a);
-
- transition trany;
- trany.orig_state = getOrigStateIndex();
- trany.dest_state = getDestStateIndex();
-
-
- // Do not create transition if the origin state is unreachable.
-// Taken out on 5/22
- if ((trany.orig_state != 0) && (states[trany.orig_state].num_incoming == 0)) {
+ // 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;
}
-
- // increment number of edges for a state
- states[getOrigStateIndex()].num_outgoing += 1;
- states[getDestStateIndex()].num_incoming += 1;
-
- transition_label tl;
- tl.trigger = getTriggerIndex();
- tl.guard = getGuardIndex();
- tl.action = getActionIndex();
- trany.trans = tl;
-
-
- // no dupes
- if (findTrans(trany.orig_state, trany.dest_state, trany.trans.trigger, trany.trans.guard, trany.trans.action)) {
+ // Check that there is not a duplicate transition
+ if (findTrans(orig, dest, trigger_index, guard_index, action_index)) {
return false;
}
-
- transitions.push_back(trany);
+ // Create the transition properties
+ transition_properties tp = transition_properties(trigger_index, guard_index, action_index);
-
-/* // reset all indices
- orig_state_index = 0;
- dest_state_index = 0;
- trigger_index = 0;
- action_index = 0;
- guard_index = 0;*/
+ // Create the transition
+ add_edge(orig, dest, tp, sd0);
- return true;
-
-}
-
-
-bool cUMLStateDiagram::addTransitionTotal()
-{
- if ((states.size() == 0)) {
-
- return false;
- }
-
- transition trany;
- trany.orig_state = getOrigStateIndex();
- trany.dest_state = getDestStateIndex();
-
-
- // Do not create transition if the origin state is unreachable.
-// Taken out on 5/22
- if ((trany.orig_state != 0) && (states[trany.orig_state].num_incoming == 0)) {
- return false;
- }
-
-
- transition_label tl;
- tl.trigger = getTriggerIndex();
- tl.guard = getGuardIndex();
- tl.action = getActionIndex();
- trany.trans = tl;
-
-
- // no dupes
- if (findTrans(trany.orig_state, trany.dest_state, trany.trans.trigger, trany.trans.guard, trany.trans.action)) {
- return false;
- }
-
- // increment number of edges for a state
- states[getOrigStateIndex()].num_outgoing += 1;
- states[getDestStateIndex()].num_incoming += 1;
-
-
- transitions.push_back(trany);
-
-
- // reset all indices
- orig_state_index = 0;
- dest_state_index = 0;
+ // Reset all the indices
trigger_index = 0;
action_index = 0;
guard_index = 0;
+ orig = vertex(0, sd0);
+ dest = vertex(0, sd0);
return true;
}
-bool cUMLStateDiagram::currTrans(int orig, int dest, int tr, int gu, int act)
-{
- if (((orig == -1) || (orig == getOrigStateIndex())) &&
- ((dest == -1) || (dest == getDestStateIndex())) &&
- ((tr == -1) || (tr == getTriggerIndex())) &&
- ((gu == -1) || (gu == getGuardIndex())) &&
- ((act == -1) || (act == getActionIndex()))) {
- return true;
- }
-
- return false;
-
-}
-
-
-
int cUMLStateDiagram::numStates()
{
- return states.size();
+ return num_vertices(sd0);
}
int cUMLStateDiagram::numTrans()
{
- return transitions.size();
-}
+ return num_edges(sd0);
+}
// print the label. Change - signs to _
std::string cUMLStateDiagram::StringifyAnInt(int x) {
@@ -484,6 +413,35 @@
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()
{
printXMI();
@@ -494,6 +452,9 @@
{
std::string temp, temp1, temp2, temp3;
std::string trig_label, trig_op_name;
+
+ boost::graph_traits<state_diagram>::edge_iterator edge_start, edge_end;
+ boost::graph_traits<state_diagram>::edge_descriptor ed;
int s_count = 0;
int t_count = 0;
@@ -502,23 +463,18 @@
// This state is the initial state; thus it should be printed regardless of whether it has an incoming
// edge or not.
if (numStates() > 0) {
- temp = StringifyAnInt(s_count);
+ temp = "_1";
xmi += "<UML:Pseudostate xmi.id=\"s" + temp + "\" kind=\"initial\" outgoing=\"\" name=\"s";
xmi += temp + "\" isSpecification=\"false\"/>\n";
- ++s_count;
}
for (; s_count < numStates(); ++s_count) {
-
- // only print if this state has an incoming edge.
-// if ((states[s_count]).num_incoming > 0) {
- temp = "s" + StringifyAnInt(s_count);
+ temp = "s" + StringifyAnInt(s_count);
xmi+="<UML:CompositeState xmi.id=\"";
xmi+=temp;
xmi+= "\" isConcurrent=\"false\" name=\"";
xmi+= temp;
xmi+= "\" isSpecification=\"false\"/>\n";
-// }
}
// end the set of states....
@@ -530,26 +486,28 @@
xmi+="<UML:StateMachine.transitions>\n";
-
- for (t_count = 0; t_count < numTrans(); ++t_count) {
+ // Get the set of transitions.
+ for (tie(edge_start, edge_end) = edges(sd0);
+ edge_start != edge_end; ++edge_start) {
+
+ ed = *edge_start;
+
// info determined from the trans itself....
temp = "t" + StringifyAnInt(t_count);
- temp1 = "s" + StringifyAnInt(transitions[t_count].orig_state);
- temp2 = "s" + StringifyAnInt(transitions[t_count].dest_state);
+ temp1 = "s" + StringifyAnInt(source(ed, sd0));
+ temp2 = "s" + StringifyAnInt(target(ed, sd0));
temp3 = temp + temp1 + temp2;
-
+
xmi+= "<UML:Transition xmi.id=\"" + temp3 + "\"";
xmi+= " source=\"" + temp1 + "\"";
xmi += " target=\"" + temp2 + "\" name=\"\" isSpecification=\"false\">\n";
// Get guard, trigger, and action
-// temp = transitions[t_count].trans.trigger;
- temp1 = guards[transitions[t_count].trans.guard];
- temp2 = actions[transitions[t_count].trans.action];
- trig_label = triggers[transitions[t_count].trans.trigger].label;
- trig_op_name = triggers[transitions[t_count].trans.trigger].operation_id;
+ temp1 = guards[(sd0[ed]._gu)];
+ temp2 = actions[(sd0[ed]._act)];
+ trig_label = triggers[(sd0[ed]._tr)].label;
+ trig_op_name = triggers[(sd0[ed]._tr)].operation_id;
-
// print trigger, if any
if (trig_label != "<null>") {
xmi+= "<UML:Transition.trigger> <UML:Event> <UML:ModelElement.namespace> <UML:Namespace> ";
@@ -577,9 +535,21 @@
}
xmi += "</UML:Transition>\n";
-
-
+ t_count++;
}
+
+ // Add one transition to connect the init state to state 0
+ temp = "t" + StringifyAnInt(t_count);
+ temp1 = "s" + StringifyAnInt(-1);
+ temp2 = "s" + StringifyAnInt(0);
+ temp3 = temp + temp1 + temp2;
+ xmi+= "<UML:Transition xmi.id=\"" + temp3 + "\"";
+ xmi+= " source=\"" + temp1 + "\"";
+ xmi += " target=\"" + temp2 + "\" name=\"\" isSpecification=\"false\">\n";
+ xmi += "</UML:Transition>\n";
+
return;
}
+
+
Modified: branches/uml/source/main/cUMLStateDiagram.h
===================================================================
--- branches/uml/source/main/cUMLStateDiagram.h 2007-07-05 16:03:54 UTC (rev 1749)
+++ branches/uml/source/main/cUMLStateDiagram.h 2007-07-05 16:41:28 UTC (rev 1750)
@@ -5,21 +5,29 @@
#include <vector>
#include <iostream>
#include <sstream>
+#include <utility>
+#include <algorithm>
+#include <boost/config.hpp>
+#include <boost/graph/graph_traits.hpp>
+#include <boost/graph/adjacency_list.hpp>
+#include <boost/graph/breadth_first_search.hpp>
+#include <boost/graph/visitors.hpp>
+#include <boost/graph/graphviz.hpp>
+struct transition_properties {
+ transition_properties() {}
+ transition_properties(int trigger, int guard, int action)
+ : _tr(trigger), _gu(guard), _act(action) {}
+ int _tr, _gu, _act;
+};
+
struct transition_label {
int trigger;
-// std::string guard;
int guard;
-// std::string action;
int action;
};
-struct transition {
- int orig_state;
- int dest_state;
- transition_label trans;
-};
struct state {
int identifier;
@@ -35,15 +43,14 @@
class cUMLStateDiagram {
protected:
- std::vector<state> states;
std::vector<trigger_info> triggers;
std::vector<std::string> guards;
std::vector<std::string> actions;
- std::vector<transition> transitions;
+// std::vector<transition> transitions;
std::vector<transition_label> transition_labels;
- int orig_state_index;
- int dest_state_index;
+// int orig_state_index;
+// int dest_state_index;
int trans_label_index;
int trigger_index;
int guard_index;
@@ -51,8 +58,7 @@
std::string xmi;
-
-
+
public:
cUMLStateDiagram();
@@ -64,15 +70,14 @@
int numStates();
int numTrans();
-// bool findTrans(int, int, int, std::string, std::string) ;
-// bool findTrans(int, int, std::string, std::string, std::string);
+
bool findTrans(int, int, int, int, int);
- bool findTransLabel(transition_label); // find a specific transition label
- bool currTrans(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,
+ int, transition_properties> state_diagram;
-// These functions have been moved to the organism.
-
template <typename T>
bool absoluteMoveIndex (T x, int &y, int z);
@@ -81,6 +86,36 @@
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);
@@ -88,60 +123,37 @@
bool absoluteJumpTransitionLabel(int);
bool absoluteJumpOriginState(int);
bool absoluteJumpDestinationState(int);
-/*
- bool relativeJumpGuard(int);
- bool relativeJumpAction(int);
- bool relativeJumpTrigger(int);
- bool relativeJumpTransitionLabel(int);
- bool relativeJumpOriginState(int);
- bool relativeJumpDestinationState(int);
-*/
-
-/*
-// The first and last functions do not work since each org maintains its own info about the
-// state diagram, but we don't necessarily know to which state diagram it is referring.
-
-// The first functions jump the index to the beginning of various vectors
- bool firstGuard() {guard_index = 0;}
- bool firstAction() {action_index = 0;}
- bool firstTrigger() {trigger_index = 0;}
- bool firstTransitionLabel() {trans_label_index = 0;}
- bool firstOriginState() {orig_state_index = 0;}
- bool firstDestinationState() {dest_state_index = 0;}
-
-// The last functions jump the index to the end of various vectors
- bool lastGuard() {guard_index = (guards.size()-1);}
- bool lastAction() {action_index = (actions.size()-1);}
- bool lastTrigger() {trigger_index = (triggers.size()-1);}
- bool lastTransitionLabel() {trans_label_index = (transition_labels.size()-1);}
- bool lastOriginState() {orig_state_index = (states.size()-1);}
- bool lastDestinationState() {dest_state_index = (states.size()-1);}
-*/
-
+
+// Implement a scenario check.
+ void checkForPath(std::deque<std::string>, boost::graph_traits<state_diagram>::vertex_descriptor, bool&, int&);
+ float findPath(std::deque<std::string> p);
+
// The get functions get the value of the index of various vectors
-// std::string getTriggerIndex();
-
int getTriggerIndex();
int getGuardIndex();
int getActionIndex();
transition_label getTransLabel();
- int getOrigStateIndex();
- int getDestStateIndex();
+
+// Visit graph
+ void executeVisitor();
+ void printGraphViz();
// Add functions
- bool addState();
-// bool addTransitionLabel();
- bool addTransition();
- bool addTransitionTotal(int, int, int, int, int);
+
+// bool addTransition();
bool addTransitionTotal();
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;
+ boost::graph_traits<state_diagram>::vertex_descriptor dest;
+
};
More information about the Avida-cvs
mailing list