|
From: <ob...@us...> - 2013-05-27 01:44:42
|
Revision: 1824
http://sourceforge.net/p/scstudio/code/1824
Author: obouda
Date: 2013-05-27 01:44:38 +0000 (Mon, 27 May 2013)
Log Message:
-----------
implemented basic version of conditions evaluation on AllPaths traverser
Modified Paths:
--------------
branches/conditions/src/check/time/hmsc_all_paths.cpp
branches/conditions/src/check/time/hmsc_all_paths.h
branches/conditions/src/data/msc/ConditionNode.cpp
branches/conditions/src/data/msc/ConditionNode.h
branches/conditions/src/data/msc_types.h
branches/conditions/tests/time/time_race/CMakeLists.txt
Added Paths:
-----------
branches/conditions/tests/time/time_race/race_cond_pos1.mpr
branches/conditions/tests/time/time_race/race_cond_pos1.vsd
Modified: branches/conditions/src/check/time/hmsc_all_paths.cpp
===================================================================
--- branches/conditions/src/check/time/hmsc_all_paths.cpp 2013-05-26 17:54:35 UTC (rev 1823)
+++ branches/conditions/src/check/time/hmsc_all_paths.cpp 2013-05-27 01:44:38 UTC (rev 1824)
@@ -1,4 +1,5 @@
#include "hmsc_all_paths.h"
+#include <vector>
void AllPaths::traverse()
{
@@ -14,10 +15,9 @@
}
-void AllPaths::all_paths(
-HMscNodePtr node,
-MscElementPList path_prefix2
-)
+//#define MYDBG
+
+void AllPaths::all_paths(HMscNodePtr node, MscElementPList path_prefix2, SystemState system_state)
{
HMscNodePtrSet::iterator last_it;
std::list<PathFoundListener*>::iterator listener_it;
@@ -46,7 +46,7 @@
}
}
- set_number(node,get_number(node)+1); //increment occurence counter of node
+ set_number(node, get_number(node, system_state)+1, system_state); //increment occurence counter of node
//check whether node has successors
PredecessorNode * pre;
@@ -58,10 +58,29 @@
//keep poping until reference node is reached
while(!dynamic_cast<HMscNode*>(path_prefix2.back()))
path_prefix2.pop_back();
- set_number(node, 0);
+ set_number(node, 0, system_state);
return;
}
+ // update the system state
+ ConditionNodePtr cond = boost::dynamic_pointer_cast<ConditionNode>(node);
+ if (cond != NULL)
+ {
+ const std::vector<std::string> names = cond->get_names();
+ switch (cond->get_type())
+ {
+ case ConditionNode::SETTING:
+ for (std::vector<std::string>::const_iterator i = names.begin(); i != names.end(); ++i)
+ system_state.insert(*i);
+ break;
+ case ConditionNode::UNSETTING:
+ for (std::vector<std::string>::const_iterator i = names.begin(); i != names.end(); ++i)
+ system_state.erase(*i);
+ break;
+ default:
+ ; // other condition types have no effect on the system state
+ }
+ }
//traverse all successors which do not occur in path_prefix more than m_occurence
NodeRelationPtrVector set_succ = pre->get_successors();
@@ -69,15 +88,31 @@
for(rel=set_succ.begin(); rel!=set_succ.end();rel++)
{
const NodeRelationPtr& node_relation = *rel;
- HMscNodePtr new_node(dynamic_cast<HMscNode*>(node_relation.get()->get_successor()));
- if(get_number(new_node)<m_occurence)
+ HMscNodePtr new_node(dynamic_cast<HMscNode*>(node_relation->get_successor()));
+ if(get_number(new_node, system_state)<m_occurence)
{
-
- path_prefix2.push_back(node_relation.get()); //update attribute
- all_paths(new_node,path_prefix2);
-
+ // check for an unsatisfied guard
+ ConditionNodePtr new_cond_node = boost::dynamic_pointer_cast<ConditionNode>(new_node);
+ if (new_cond_node != NULL)
+ {
+ if (new_cond_node->get_type() == ConditionNode::GUARDING)
+ {
+ bool satisfied = false;
+ const std::vector<std::string> names = new_cond_node->get_names();
+ for (std::vector<std::string>::const_iterator i = names.begin(); i != names.end(); ++i)
+ if (system_state.find(*i) != system_state.end())
+ {
+ satisfied = true;
+ break;
+ }
+ if (!satisfied)
+ continue;
+ }
+ }
+
+ path_prefix2.push_back(node_relation.get()); //update attribute
+ all_paths(new_node,path_prefix2, system_state);
}
-
}
//all successors have been traversed-> update attributes and finish.
@@ -85,6 +120,6 @@
//keep poping until reference node is reached
while(!dynamic_cast<HMscNode*>(path_prefix2.back()))
path_prefix2.pop_back();
- set_number(node, get_number(node)-1);
+ set_number(node, get_number(node, system_state)-1, system_state);
return;
}
Modified: branches/conditions/src/check/time/hmsc_all_paths.h
===================================================================
--- branches/conditions/src/check/time/hmsc_all_paths.h 2013-05-26 17:54:35 UTC (rev 1823)
+++ branches/conditions/src/check/time/hmsc_all_paths.h 2013-05-27 01:44:38 UTC (rev 1824)
@@ -3,6 +3,8 @@
#include "time_pseudocode.h"
#include "data/session_attribute.h"
+#include <set>
+#include <string>
//typedef std::pair<std::list<HMscNodePtr>,bool> HMscPath;
//typedef std::pair<std::list<HMscPath>,bool> HMscAllPaths;
@@ -20,7 +22,7 @@
HMscNodePtrSet m_last;
int m_occurence; // how many times node can occur in path
std::list<PathFoundListener*> m_path_found_listeners;
- SessionAttribute<int> m_attr_number;
+ SessionAttribute<std::map<SystemState, int> > m_attr_number;
//preconditions: every path from node first to end node should go through some node from last
@@ -28,9 +30,8 @@
AllPaths(HMscPtr hmsc, //TimeRelationRefNodePtr relation,
HMscNodePtr first, HMscNodePtrSet last, int occurence,
const std::string& number="AllPathAlg")
- :m_hmsc(hmsc),m_first(first),m_last(last),m_occurence(occurence),m_attr_number("attr_number",-1)
+ :m_hmsc(hmsc),m_first(first),m_last(last),m_occurence(occurence),m_attr_number("attr_number", std::map<SystemState, int>())
{
-
}
~AllPaths()
@@ -38,14 +39,21 @@
m_attr_number.clean_up();
}
- void set_number(HMscNodePtr e,int number)
+ void set_number(HMscNodePtr e, int number, SystemState system_state = SystemState())
{
- return m_attr_number.set(e.get(), number);
+ std::map<SystemState, int> num_map = m_attr_number.get(e.get());
+ num_map[system_state] = number;
+ m_attr_number.set(e.get(), num_map);
}
- int get_number(HMscNodePtr e)
+ int get_number(HMscNodePtr e, SystemState system_state = SystemState())
{
- return m_attr_number.get(e.get());
+ std::map<SystemState, int> num_map = m_attr_number.get(e.get());
+ std::map<SystemState, int>::iterator num = num_map.find(system_state);
+ if (num == num_map.end())
+ return -1;
+ else
+ return num->second;
}
@@ -68,7 +76,7 @@
void traverse();
- void all_paths(HMscNodePtr, MscElementPList);
+ void all_paths(HMscNodePtr, MscElementPList, std::set<std::string> system_state = std::set<std::string>());
/**
* Adds PathFoundListener
Modified: branches/conditions/src/data/msc/ConditionNode.cpp
===================================================================
--- branches/conditions/src/data/msc/ConditionNode.cpp 2013-05-26 17:54:35 UTC (rev 1823)
+++ branches/conditions/src/data/msc/ConditionNode.cpp 2013-05-27 01:44:38 UTC (rev 1824)
@@ -57,6 +57,11 @@
m_type = GUARDING;
state = STATE_NAME;
}
+ else if(lowcase_token == "unset")
+ {
+ m_type = UNSETTING;
+ state = STATE_NAME;
+ }
else if(lowcase_token == "for")
{
m_type = RANDOM;
@@ -151,6 +156,10 @@
text << "when ";
/* no break */
case SETTING:
+ case UNSETTING:
+ if (m_type == UNSETTING)
+ text << "unset ";
+
for(std::vector<std::string>::const_iterator npos = m_names.begin();
npos != m_names.end(); npos++)
{
Modified: branches/conditions/src/data/msc/ConditionNode.h
===================================================================
--- branches/conditions/src/data/msc/ConditionNode.h 2013-05-26 17:54:35 UTC (rev 1823)
+++ branches/conditions/src/data/msc/ConditionNode.h 2013-05-27 01:44:38 UTC (rev 1824)
@@ -28,6 +28,23 @@
public HMscNode, public PredecessorNode, public SuccessorNode
{
public:
+ enum ConditionType
+ {
+ SETTING, // <state1>, <state2>
+ UNSETTING, // unset <state1>, <state2>
+ GUARDING, // when <state1>, <state2>
+ RANDOM, // for 50%
+ OTHERWISE
+ };
+
+private:
+ ConditionType m_type;
+
+ std::vector<std::string> m_names;
+ //! probability (0-1) this condition is applied
+ double m_probability;
+
+public:
ConditionNode():HMscNode(),PredecessorNode(),SuccessorNode(),
m_type(OTHERWISE), m_probability(1.0)
{
@@ -60,14 +77,6 @@
void assign_label(const std::string& label);
std::string get_label() const;
- enum ConditionType
- {
- SETTING, // <state1>, <state2>
- GUARDING, // when <state1>, <state2>
- RANDOM, // for 50%
- OTHERWISE
- };
-
//! Setter of m_type
void set_type(ConditionType type)
{
@@ -103,13 +112,6 @@
{
return m_probability;
}
-
-private:
- ConditionType m_type;
-
- std::vector<std::string> m_names;
- //! probability (0-1) this condition is applied
- double m_probability;
};
#endif // #ifndef _CONDITIONNODE_H
Modified: branches/conditions/src/data/msc_types.h
===================================================================
--- branches/conditions/src/data/msc_types.h 2013-05-26 17:54:35 UTC (rev 1823)
+++ branches/conditions/src/data/msc_types.h 2013-05-27 01:44:38 UTC (rev 1824)
@@ -29,6 +29,7 @@
#include <algorithm>
#include <list>
#include <map>
+#include <set>
#include <string>
#if defined(_MSC_VER)
#include <comutil.h> // _bstr_t
@@ -206,6 +207,9 @@
}
}
+
+typedef std::set<std::string> SystemState;
+
#endif /* _MSC_TYPES_H */
// $Id$
Modified: branches/conditions/tests/time/time_race/CMakeLists.txt
===================================================================
--- branches/conditions/tests/time/time_race/CMakeLists.txt 2013-05-26 17:54:35 UTC (rev 1823)
+++ branches/conditions/tests/time/time_race/CMakeLists.txt 2013-05-27 01:44:38 UTC (rev 1824)
@@ -38,3 +38,5 @@
ADD_CHECKER_TEST(sctime "Time Race" race_pos27.mpr 1)
ADD_CHECKER_TEST(sctime "Time Race" race_pos28.mpr 1)
+ADD_CHECKER_TEST(sctime "Time Race" race_cond_pos1.mpr 1)
+
Added: branches/conditions/tests/time/time_race/race_cond_pos1.mpr
===================================================================
--- branches/conditions/tests/time/time_race/race_cond_pos1.mpr (rev 0)
+++ branches/conditions/tests/time/time_race/race_cond_pos1.mpr 2013-05-27 01:44:38 UTC (rev 1824)
@@ -0,0 +1,42 @@
+mscdocument impl_example.vsd;
+msc Cond;
+initial connect L0;
+L0: connect L1, L2;
+L1: condition X connect L3;
+L2: condition Y connect L3;
+L3: connect L4, L5;
+L4: condition when X connect L6;
+L5: connect L7;
+L6: reference A connect L5;
+L7: connect L8, L9;
+L8: condition when Y connect L10;
+L9: connect L11;
+L10: reference C connect L9;
+L11: final;
+endmsc;
+msc A;
+inst A;
+inst B;
+inst C;
+A: instance;
+out m,0 to B;
+endinstance;
+B: instance;
+in m,0 from A;
+endinstance;
+C: instance;
+endinstance;
+endmsc;
+msc C;
+inst A;
+inst B;
+inst C;
+A: instance;
+endinstance;
+B: instance;
+in m,0 from C;
+endinstance;
+C: instance;
+out m,0 to B;
+endinstance;
+endmsc;
Added: branches/conditions/tests/time/time_race/race_cond_pos1.vsd
===================================================================
(Binary files differ)
Index: branches/conditions/tests/time/time_race/race_cond_pos1.vsd
===================================================================
--- branches/conditions/tests/time/time_race/race_cond_pos1.vsd 2013-05-26 17:54:35 UTC (rev 1823)
+++ branches/conditions/tests/time/time_race/race_cond_pos1.vsd 2013-05-27 01:44:38 UTC (rev 1824)
Property changes on: branches/conditions/tests/time/time_race/race_cond_pos1.vsd
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+application/msword
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|