|
From: <ma...@us...> - 2010-05-10 23:14:25
|
Revision: 754
http://scstudio.svn.sourceforge.net/scstudio/?rev=754&view=rev
Author: madzin
Date: 2010-05-10 23:14:18 +0000 (Mon, 10 May 2010)
Log Message:
-----------
Some refactoring of membership
Modified Paths:
--------------
trunk/src/membership/membership_alg.cpp
trunk/tests/membership/CMakeLists.txt
Modified: trunk/src/membership/membership_alg.cpp
===================================================================
--- trunk/src/membership/membership_alg.cpp 2010-05-10 21:55:44 UTC (rev 753)
+++ trunk/src/membership/membership_alg.cpp 2010-05-10 23:14:18 UTC (rev 754)
@@ -35,55 +35,173 @@
HMscPtr search_bmsc(BMscPtr bmsc, BMscPtr bmsc_f);
HMscPtr search_hmsc(HMscPtr hmsc, BMscPtr bmsc_f);
+/*
+ * checks whole branch from defined node in HMSC
+ */
bool check_branch(HMscNodePtr node, ConfigurationPtr b);
+/*
+ * adds searched configuration to map of checked configurations
+ *
+ * configuration - state of node in searched HMSC and state of bMSC which is looked for
+ */
void add_checked_branch(ReferenceNodePtr ref_node, ConfigurationPtr searched_conf);
+/*
+ * checks if instance contains any event
+ */
bool is_empty_instance(InstancePtrList node_instances, InstancePtrList b_instances);
+/*
+ * compares strict order area from HMSC node with matching strict order area from bMSC which is looked for
+ *
+ * parameters: node_events - events of HMSC node cut
+ * b_events - events of bMSC cut
+ * type: membership - checks matching events and adds receive ordering
+ * receive_ordering - checks receive ordering
+ */
bool strict_strict(std::vector<Event*>& node_events, std::vector<Event*>& b_events, enum check_type type);
+/*
+ * compares coregion area from HMSC node with matching strict order area from bMSC which is looked for
+ *
+ * parameters: node_events - events of HMSC node cut
+ * b_events - events of bMSC cut
+ * type: membership - checks matching events and adds receive ordering
+ * receive_ordering - checks receive ordering
+ */
+bool coregion_strict(std::vector<Event*>& node_events, std::vector<Event*>& b_events, enum check_type type);
+
+/*
+ * compares strict order area from HMSC node and coregion area from bMSC which is looked for
+ *
+ * DEVELOPMENT WAS STOPPED
+ */
bool strict_coregion(StrictOrderAreaPtr node_strict, std::vector<Event*>& node_events,
CoregionAreaPtr b_coregion, std::vector<Event*>& b_events);
-bool coregion_strict(std::vector<Event*>& node_events, std::vector<Event*>& b_events, enum check_type type);
-
+/*
+ * compares coretion area from HMSC node and coregion area from bMSC which is looked for
+ *
+ * DEVELOPMENT WAS STOPPED
+ */
bool coregion_coretion(CoregionAreaPtr node_coregion, std::vector<Event*>& node_events,
CoregionAreaPtr b_coregion, std::vector<Event*>& b_events);
+/*
+ * compares two events
+ */
bool compare_events(Event* a, Event* b);
+/*
+ * compares events attributes
+ */
bool compare_events_attribute(Event* a, Event* b);
+/*
+ * tries to find configuration into map of seared configuration
+ */
bool look_at_checked_conf(ReferenceNodePtr node, ConfigurationPtr b);
+/*
+ * compares one instance from HMSC node with matching instance from bMSC which is looked for
+ *
+ * parameters: node_instance - instance from HMSC node
+ * type: membership - checks matching events and adds receive ordering
+ * receive_ordering - checks receive ordering
+ * old_position - events where the checking starts
+ */
bool check_instance(InstancePtr node_instance, enum check_type type, PositionPtr old_position);
+/*
+ * compares bMsc from HMSC node with matching scenario in bMSC which is looked for
+ * parameters: node - HMSC node
+ * type: membership - checks matching events and adds receive ordering
+ * receive_ordering - checks receive ordering
+ * old_conf - HMSC node configuration of start searching
+ */
bool check_node(ReferenceNodePtr node, enum check_type type, ConfigurationPtr old_conf);
+/*
+ * in case events are send events, adds attribute to both events and to both receive event in case messages are complete
+ *
+ * parameters: node_e - event from HMSC node
+ * b_e - event from bMSC
+ */
void set_identification(Event* node_e, Event* b_e);
+/*
+ * checks whether node has null pointer to reference bMSC
+ */
bool is_node_null(ReferenceNodePtr node);
+/*
+ * checks whether instance contains any event
+ */
bool is_instance_null(InstancePtr instance);
+/*
+ * checks whether coregion area contains any event
+ */
bool is_cor_area_null(CoregionAreaPtr cor);
+/*
+ * checks whether strict order area contains any event
+ */
bool is_strict_area_null(StrictOrderAreaPtr strict);
+/*
+ * checks time constraints in HMSC node
+ *
+ */
+//TODO skontrolovat co to vlastne robi, a kde kontrolujem casove obmedzenia v ramci bMSC z dajakeho HMSC nodu
bool check_node_time(ReferenceNodePtr node, ConfigurationPtr conf);
+/*
+ * finds the maximum event of HMSC node and returns time interval value of matching event in bMSC
+ *
+ * !!TIME MEMBERSHIP WORKS IF EACH EVENT IN bMSC HAS GOT TIME INTERVAL WITH ONE EVENT (the same for all events) AND NO MORE!!
+ */
int get_max_interval(ReferenceNodePtr node, ConfigurationPtr conf);
+/*
+ * finds the minimum event of HMSC node and returns time interval value of matching event in bMSC
+ *
+ * !!TIME MEMBERSHIP WORKS IF EACH EVENT IN bMSC HAS GOT TIME INTERVAL WITH ONE EVENT (the same for all events) AND NO MORE!!
+ */
int get_min_interval(ConfigurationPtr conf);
-Event* get_last_instance_event(Event* start, int id = INT_MAX);
+/*
+ * returns the last event on instance
+ */
+std::vector<Event*> get_last_instance_event(Event* start);
+/*
+ * returns maximal events of coregion area
+ */
+std::vector<Event*> get_last_coregion_events(CoregionArea* cor);
+
+/*
+ * compares events time relations
+ *
+ * paramterers: a - HMSC node
+ * b - bMSC node
+ */
bool compare_events_time_relations(Event* a, Event* b);
-Event* find_event_on_instance_by_id(std::wstring label, int id);
+/*
+ * finds event in bMSC on instance by id
+ *
+ * parameters: label - label of instance where the event should be
+ * id - id of event which is looked for
+ */
+Event* find_event_on_instance_by_id(std::wstring label, int id, StrictEventPtr start_event = NULL);
+/*
+ * removes event attribute "indentification"
+ */
void remove_events_attributes(std::vector<Event*> vec);
+
/*
* Returns precondition list of the membership algorithm
*/
@@ -104,7 +222,7 @@
if (bmsc_f == NULL)
{
print_report(RS_ERROR,
- stringize() << "Searched flow must be a basic MSC.");
+ stringize() << "MSC which is looked for, must be bMSC.");
return NULL;
}
@@ -115,12 +233,18 @@
else
{
BMscPtr bmsc = boost::dynamic_pointer_cast<BMsc > (msc);
- return search_bmsc(bmsc, bmsc_f);
+ if(bmsc != NULL)
+ return search_bmsc(bmsc, bmsc_f);
+ else
+ {
+ print_report(RS_ERROR, stringize() << "Membership algorithm cannot recognize a type of browsed MSC");
+ return NULL;
+ }
}
}
/*
- * Tries finding bMSC in HMSC
+ * Tries to find bMSC in HMSC
*/
HMscPtr search_hmsc(HMscPtr hmsc, BMscPtr bmsc_f)
{
@@ -139,7 +263,9 @@
std::cout << "top size " << top.size() << std::endl;
*/
-dup_hmsc = hmsc; // dup_hmsc = duplicator.duplicate(hmsc);
+ //dup_hmsc should be MSC graph. Due to that duplicatior throws exception during copying time intervals, membership workes just with MSC graphs.
+ dup_hmsc = hmsc;
+// dup_hmsc = dup_hmsc = duplicator.duplicate(hmsc);
/*
start = dup_hmsc->get_start();
@@ -157,6 +283,7 @@
StartNodePtr start_node = dup_hmsc->get_start();
+ //strt of searching
if (check_branch(start_node, searched_conf))
{
return new HMsc(); //TODO return path in hmsc
@@ -177,8 +304,9 @@
*/
bool check_branch(HMscNodePtr hmsc_node, ConfigurationPtr b)
{
+ //remove attributes from previous computation
if(!attributed_events.empty())
- std::cerr << "Internal warning: some event has got attribute" << std::endl;
+ remove_events_attributes(attributed_events);
//checks end node
EndNodePtr end = boost::dynamic_pointer_cast<EndNode > (hmsc_node);
@@ -218,8 +346,6 @@
}
else
{
- //TODO add this check to while cycle
-
//when deosn't exist empty path to EndNode
if (b->is_null() && !is_node_null(node))
return false;
@@ -233,18 +359,21 @@
old_config_I = new Configuration(b);
old_config_II = new Configuration(b);
+ //tries to matching events between searched MSC and bMSC which is looked for
if (!check_node(node, membership, b))
{
remove_events_attributes(attributed_events);
return false;
}
+ //checks time constraints for this node
if(!check_node_time(node, old_config_II))
{
remove_events_attributes(attributed_events);
return false;
}
+ //checks the ordering of events (by attribute which was set at check_node(node, membership,b))
if (!check_node(node, receive_ordering, old_config_I))
{
remove_events_attributes(attributed_events);
@@ -258,6 +387,7 @@
SuccessorNode* succ;
HMscNode* hmsc_succ;
+ //continue with browsing node's seccessors
for (it = successors.begin(); it != successors.end(); it++)
{
succ = (*it)->get_successor();
@@ -547,6 +677,9 @@
*/
}
+/*
+ * finds instance by the name
+ */
InstancePtr find_instance(InstancePtrList instances, std::wstring name)
{
@@ -561,13 +694,27 @@
return NULL;
}
-//TODO
-
/*
* Add checked branch to map of checked branches
*/
void add_checked_branch(ReferenceNodePtr ref_node, ConfigurationPtr conf)
{
+ BMscPtr bmsc = ref_node->get_bmsc();
+
+ if(bmsc == NULL)
+ {
+ std::cerr << "Internal error: checked_branch" << std::endl;
+ return;
+ }
+
+ std::wstring bmsc_name = bmsc->get_label();
+ std::set<ConfigurationPtr> conf_set;
+ conf_set.insert(conf);
+
+ if(checked.find(bmsc_name) == checked.end())
+ checked.insert(std::make_pair(bmsc_name, conf_set));
+ else
+ checked.find(bmsc_name)->second.insert(conf);
}
/*
@@ -698,6 +845,7 @@
double a_time = a_interval.get_begin_value();
double b_time = b_interval.get_begin_value();
+//TODO skontrolovat, nepaci sa mi ze by sa na evente z HMSC nastavovala nula
if(time_a_intervals.size() > 1)
a_time = 0;
@@ -721,29 +869,40 @@
return true;
}
-Event* find_event_on_instance_by_id(std::wstring label, int id)
+Event* find_event_on_instance_by_id(std::wstring label, int id, StrictEventPtr start_event)
{
- InstancePtrList instances = global_bmsc->get_instances();
- InstancePtrList::iterator it;
- InstancePtr instance;
+ EventAreaPtr first;
- for(it = instances.begin(); it != instances.end(); it++)
+ if(start_event == NULL)
{
- if((*it)->get_label() == label)
+ InstancePtrList instances = global_bmsc->get_instances();
+ InstancePtrList::iterator it;
+ InstancePtr instance;
+
+ for(it = instances.begin(); it != instances.end(); it++)
{
- instance = *it;
- break;
+ if((*it)->get_label() == label)
+ {
+ instance = *it;
+ break;
+ }
}
+
+ first = instance->get_first();
}
+ else
+ {
+ first = start_event->get_general_area();
+ }
- EventAreaPtr first = instance->get_first();
StrictOrderAreaPtr strict = boost::dynamic_pointer_cast<StrictOrderArea>(first);
StrictEventPtr str = strict->get_first();
+ //function finds event only in bMSC which is looked for, so coregion area is not allowed
if(str == NULL)
{
- std::cerr << "Error: Unexpected behaviour 5" << std::endl;
+ std::cerr << "Error: bMSC which is looked for contains coregion area" << std::endl;
return NULL;
}
@@ -752,12 +911,6 @@
event_id = str->get_attribute("identification", -1, event_set);
- if(event_set)
- {
- std::cerr << "Error: Unexpected behaviour 4" << std::endl;
- return NULL;
- }
-
StrictEventPtr old;
while(event_id != id)
@@ -788,12 +941,6 @@
}
event_id = str->get_attribute("identification", -1, event_set);
-
- if(event_set)
- {
- std::cerr << "Error: Unexpected behaviour 4" << std::endl;
- return NULL;
- }
}
return str.get();
@@ -826,7 +973,7 @@
node->add_successor(succ);
else
{
- std::cout << "Error: Unexpected behaviour" << std::endl;
+ std::cout << "Error: Unexpected behaviour 43" << std::endl;
return false;
}
@@ -841,7 +988,7 @@
node->add_successor(succ);
else
{
- std::cout << "Error: Unexpected behaviour" << std::endl;
+ std::cout << "Error: Unexpected behaviour 23" << std::endl;
return false;
}
@@ -988,7 +1135,7 @@
if (node_events.empty())
node_events.push_back(node_strict->get_first().get());
else
- std::cout << "Error: Unexpected error" << std::endl;
+ std::cout << "Error: Unexpected error 24" << std::endl;
}
bool result;
@@ -1098,7 +1245,11 @@
BMscPtr bmsc = boost::dynamic_pointer_cast<BMsc > (msc);
if (bmsc == NULL)
+ {
+// print_report(RS_ERROR, stringize() << "Error: Some reference node does not refers to bMSC");
+ std::cerr << "Error: Some reference node does not refers to bMSC." << std::endl;
return false;
+ }
InstancePtrList node_instances = bmsc->get_instances();
InstancePtrList b_instances = conf->get_instances();
@@ -1444,11 +1595,6 @@
}
-bool check_interval(TimeRelationRefNodePtr relation, TopBottom point)
-{
- return false;
-}
-
int get_min_interval(ConfigurationPtr conf)
{
std::set<PositionPtr> positions = conf->get_positions();
@@ -1463,22 +1609,31 @@
if(events.size() == 0)
continue;
+//TODO dopracovat coregiony => events.size mozeb byt > 1
time_intervals = events.front()->get_time_relations();
if(time_intervals.size() > 1)
min = 0;
+ if(time_intervals.size() == 0)
+ {
+ std::cerr << "Error: Unexpected behaviour, some event in bMSC, which is looked for, has not got time interval" << std::endl;
+ return min;
+ }
+
MscTimeIntervalSetD time_set = time_intervals.front()->get_interval_set();
if(time_set.is_empty())
{
- std::cerr << "Error: Unexpected behaviour " << std::endl;
+ std::cerr << "Error: Unexpected behaviour, some time interval of event in bMSC, which is looked for, is empty" << std::endl;
+ return min;
}
MscTimeInterval<double> temp = time_set.get_set().front();
+ //this implementation assumes that each time interval is defined as [number].
if(min > temp.get_begin_value())
- min = (int)temp.get_begin_value();
+ min = temp.get_begin_value();
}
return min;
@@ -1496,7 +1651,7 @@
BMscPtr bmsc = boost::dynamic_pointer_cast<BMsc>(msc);
if(bmsc == NULL)
- std::cerr << "Error: Unexpected behaviur" << std::endl;
+ std::cerr << "Error: Unexpected behaviur 35" << std::endl;
InstancePtrList instances = bmsc->get_instances();
InstancePtrList::iterator inst_it;
@@ -1508,6 +1663,7 @@
StrictOrderArea* strict;
CoregionArea* cor;
+ //mozna uprava, brat instancie z conf a ked sa instancia nenachadza v HMSC node tak sa berie event z conf
for(inst_it = instances.begin(); inst_it != instances.end(); inst_it++)
{
area = (*inst_it)->get_first().get();
@@ -1517,7 +1673,9 @@
{
start = strict->get_first();
std::vector<int> identifications;
- Event* e = get_last_instance_event(start.get());
+ std::vector<Event*> e_set = get_last_instance_event(start.get());
+//TODO dopracovat coregiony
+ Event* e = e_set.front();
if(e == NULL)
continue;
@@ -1525,6 +1683,7 @@
int it_id;
bool it_set = true;
+ //mozno by to chcelo prerobit na is_set_attribure aby sa tu zbytocne nedavali nove hodnoty do attributu, potom by sa mohlo zmazat remove_attribure z check node.
it_id = e->get_attribute("identification", -1, it_set);
if(!it_set)
@@ -1569,7 +1728,9 @@
continue;
}
+ //spoliehame sa na strict order area takze tam vzdy bude iba jeden event
Event* e = events.front();
+ StrictEvent* s_e = dynamic_cast<StrictEvent*> (e);
std::map <std::wstring, std::vector<int> >::iterator node_last_it;
node_last_it = node_last_events.find(e->get_instance()->get_label());
@@ -1582,8 +1743,8 @@
for(unsigned int i = 0; i < node_events.size(); i++)
{
-
- Event* last = get_last_instance_event(e, node_events[i]);
+ //porozmyslat ci by sa to nedalo nahradit pomocou find_event_on_instance_by_id
+ Event* last = find_event_on_instance_by_id(e->get_instance()->get_label(), node_events[i], s_e);
if(last == NULL)
continue;
@@ -1594,103 +1755,83 @@
if(time_set.is_empty())
{
- std::cerr << "Error: Unexpected behaviour" << std::endl;
+ std::cerr << "Error: Unexpected behaviour 53" << std::endl;
}
+ //spoliehame sa na to ze casy su zadane takto: [number]
MscTimeInterval<double> temp = time_set.get_set().front();
if(max < temp.get_begin_value())
- max = (int)temp.get_begin_value();
+ max = temp.get_begin_value();
}
}
return max;
}
-Event* get_last_instance_event(Event* start, int id)
+std::vector<Event*> get_last_instance_event(Event* start)
{
+ std::vector<Event*> result;
+
if(start == NULL)
- return NULL;
+ return result;
EventArea* area = start->get_general_area();
+ EventArea* not_null_area = area;
- if(area->get_next() == NULL)
+ StrictOrderArea* str;
+ CoregionArea* cor;
+
+ while(area->get_next() != NULL)
{
- StrictOrderArea* str = dynamic_cast<StrictOrderArea*>(area);
-
- if(!is_strict_area_null(str))
+ area = area->get_next().get();
+ str = dynamic_cast<StrictOrderArea*>(area);
+ cor = dynamic_cast<CoregionArea*>(area);
+
+ if(str == NULL)
{
- if(id != INT_MAX)
- {
- StrictEventPtr e = str->get_first();
-
- int it_id;
- bool it_set = true;
-
- it_id = e->get_attribute("identification", -1, it_set);
-
- while(!it_set && it_id != id)
- {
- e = e->get_successor();
- it_id = e->get_attribute("identification", -1, it_set);
- }
-
- if(it_set)
- std::cerr << "Error: Unexpected behaviour" << std::endl;
- else
- return e.get();
- }
+ if(!is_strict_area_null(str))
+ not_null_area = str;
}
+ else
+ if(!is_cor_area_null(cor))
+ not_null_area = cor;
}
+ str = dynamic_cast<StrictOrderArea*>(not_null_area);
+ cor = dynamic_cast<CoregionArea*>(not_null_area);
- while (area->get_next() != NULL)
+ if(str != NULL)
{
- StrictOrderArea* str = dynamic_cast<StrictOrderArea*>(area->get_next().get());
+ result.push_back(str->get_last().get());
+ return result;
+ }
+ else
+ return get_last_coregion_events(cor);
+}
- if(!is_strict_area_null(str))
- {
- if(id != INT_MAX)
- {
- StrictEventPtr e = str->get_first();
+std::vector<Event*> get_last_coregion_events(CoregionArea* cor)
+{
+ std::vector<Event*> result;
- int it_id;
- bool it_set = true;
+ CoregionEventPVector vec = cor->get_maximal_events();
+ CoregionEventPVector::iterator it;
- it_id = e->get_attribute("identification", -1, it_set);
-
- while(!it_set && it_id != id)
- {
- e = e->get_successor();
-
- if(e == NULL)
- break;
-
- it_id = e->get_attribute("identification", -1, it_set);
- }
-
- if(it_set)
- std::cerr << "Error: Unexpected behaviour" << std::endl;
- else
- return e.get();
- }
- else
- area = area->get_next().get();
- }
-
+ for(it = vec.begin(); it != vec.end(); it++)
+ {
+ EventPtr e = *it;
+ result.push_back(e.get());
}
-
- StrictOrderArea* strict = dynamic_cast<StrictOrderArea*>(area);
-
- if(strict == NULL)
- std::cerr << "Error: Pattern bMSC contains coretion" << std::endl;
-
- return strict->get_last().get();
+
+ return result;
}
void remove_events_attributes(std::vector<Event*> vec)
{
std::vector<Event*>::iterator it;
+
for(it = vec.begin(); it != vec.end(); it++)
(*it)->remove_attribute<int>("identification");
+
+ vec.clear();
}
Modified: trunk/tests/membership/CMakeLists.txt
===================================================================
--- trunk/tests/membership/CMakeLists.txt 2010-05-10 21:55:44 UTC (rev 753)
+++ trunk/tests/membership/CMakeLists.txt 2010-05-10 23:14:18 UTC (rev 754)
@@ -92,7 +92,9 @@
ADD_TEST(membership_test-37 ${MEMBERSHIP_TEST_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_hmsc18.mpr ${CMAKE_CURRENT_SOURCE_DIR}/test_bmsc18_3.mpr 0)
-ADD_TEST(membership_test-38 ${MEMBERSHIP_TEST_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_hmsc19.mpr ${CMAKE_CURRENT_SOURCE_DIR}/test_bmsc19.mpr 1)
+#due to duplicator, membership works only over MSC graph
+#ADD_TEST(membership_test-38 ${MEMBERSHIP_TEST_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_hmsc19.mpr ${CMAKE_CURRENT_SOURCE_DIR}/test_bmsc19.mpr 1)
+ADD_TEST(membership_test-38 ${MEMBERSHIP_TEST_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_hmsc19.mpr ${CMAKE_CURRENT_SOURCE_DIR}/test_bmsc19.mpr 0)
#test bMSC x bMSC
ADD_TEST(membership_test-39 ${MEMBERSHIP_TEST_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_bmsc19.mpr ${CMAKE_CURRENT_SOURCE_DIR}/test_bmsc19.mpr 1)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|