|
From: <koc...@us...> - 2009-07-08 14:39:03
|
Revision: 261
http://scstudio.svn.sourceforge.net/scstudio/?rev=261&view=rev
Author: kocianon
Date: 2009-07-08 14:39:02 +0000 (Wed, 08 Jul 2009)
Log Message:
-----------
some comments added.
Modified Paths:
--------------
trunk/src/check/time/hmsc_all_paths.cpp
trunk/src/check/time/hmsc_all_paths.h
trunk/src/check/time/hmsc_tighten.h
trunk/src/check/time/time_consistency.h
trunk/tests/incon_test.cpp
Modified: trunk/src/check/time/hmsc_all_paths.cpp
===================================================================
--- trunk/src/check/time/hmsc_all_paths.cpp 2009-07-07 15:09:15 UTC (rev 260)
+++ trunk/src/check/time/hmsc_all_paths.cpp 2009-07-08 14:39:02 UTC (rev 261)
@@ -1,2 +1,66 @@
#include "check/time/hmsc_all_paths.h"
+HMscAllPaths AllPaths::get_set_of_paths()
+{
+ m_paths.clear();
+ m_contains_cycle_globally=false;
+ bool contains_cycle_locally = false;
+ std::list<HMscNodePtr> path_prefix;
+ m_nodes_set = m_hmsc->get_nodes();
+
+ HMscNodePtrSet::iterator it;
+ for(it=m_nodes_set.begin();it!=m_nodes_set.end();it++)
+ set_number(*it,0);
+
+ // TODO check origin of relation
+ all_paths(m_relation->get_ref_node_a(),path_prefix,contains_cycle_locally);
+
+ return std::make_pair(m_paths,m_contains_cycle_globally);
+}
+
+void AllPaths::all_paths(
+HMscNodePtr node,
+std::list<HMscNodePtr> path_prefix,
+bool contains_cycle_locally
+)
+{
+ path_prefix.push_back(node);
+ if(node == m_relation->get_ref_node_b())
+ {
+ m_paths.push_back(std::make_pair(path_prefix,contains_cycle_locally));
+ }
+
+ set_number(node,get_number(node)+1);
+ PredecessorNode * pre;
+ pre = dynamic_cast<PredecessorNode*>(node.get());
+
+ if(pre == NULL)
+ {
+ path_prefix.pop_back();
+ set_number(node, 0);
+ return;
+ }
+
+ NodeRelationPtrSet set_succ = pre->get_successors();
+ NodeRelationPtrSet::const_iterator rel;
+ 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)<=1)
+ {
+ bool contains_cycle_locally_new = contains_cycle_locally;
+ if(get_number(new_node)==1)
+ {
+ contains_cycle_locally_new = true;
+ m_contains_cycle_globally = true;
+ }
+ all_paths(new_node,path_prefix, contains_cycle_locally_new);
+
+ }
+
+ }
+ path_prefix.pop_back();
+ set_number(node, get_number(node)-1);
+ return;
+}
Modified: trunk/src/check/time/hmsc_all_paths.h
===================================================================
--- trunk/src/check/time/hmsc_all_paths.h 2009-07-07 15:09:15 UTC (rev 260)
+++ trunk/src/check/time/hmsc_all_paths.h 2009-07-08 14:39:02 UTC (rev 261)
@@ -17,7 +17,8 @@
std::list<HMscPath> m_paths;
public:
AllPaths(HMscPtr hmsc, TimeRelationRefNodePtr relation,
- const std::string& number="AllPathAlg"):m_hmsc(hmsc),m_relation(relation),m_number(number)
+ const std::string& number="AllPathAlg")
+ :m_hmsc(hmsc),m_relation(relation),m_number(number)
{
}
@@ -45,75 +46,18 @@
}
- static HMscAllPaths get_all_paths(HMscPtr hmsc, TimeRelationRefNodePtr relation)
+ static HMscAllPaths get_all_paths(
+ HMscPtr hmsc,
+ TimeRelationRefNodePtr relation
+ )
{
AllPaths allpaths(hmsc,relation);
return allpaths.get_set_of_paths();
}
- HMscAllPaths get_set_of_paths()
- {
+ HMscAllPaths get_set_of_paths();
- m_paths.clear();
- m_contains_cycle_globally=false;
- bool contains_cycle_locally = false;
- std::list<HMscNodePtr> path_prefix;
- m_nodes_set = m_hmsc->get_nodes();
+ void all_paths(HMscNodePtr, std::list<HMscNodePtr>, bool);
- HMscNodePtrSet::iterator it;
- for(it=m_nodes_set.begin();it!=m_nodes_set.end();it++)
- set_number(*it,0);
-
- // TODO check origin of relation
- all_paths(m_relation->get_ref_node_a(),path_prefix,contains_cycle_locally);
-
- return std::make_pair(m_paths,m_contains_cycle_globally);
- }
-
-
- void all_paths(HMscNodePtr node, std::list<HMscNodePtr> path_prefix, bool contains_cycle_locally)
- {
-
- path_prefix.push_back(node);
- if(node == m_relation->get_ref_node_b())
- {
- m_paths.push_back(std::make_pair(path_prefix,contains_cycle_locally));
- }
-
- set_number(node,get_number(node)+1);
- PredecessorNode * pre;
- pre = dynamic_cast<PredecessorNode*>(node.get());
-
- if(pre == NULL)
- {
- path_prefix.pop_back();
- set_number(node, 0);
- return;
- }
-
-
- NodeRelationPtrSet set_succ = pre->get_successors();
- NodeRelationPtrSet::const_iterator rel;
- 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)<=1)
- {
- bool contains_cycle_locally_new = contains_cycle_locally;
- if(get_number(new_node)==1)
- {
- contains_cycle_locally_new = true;
- m_contains_cycle_globally = true;
- }
- all_paths(new_node,path_prefix, contains_cycle_locally_new);
-
- }
-
- }
- path_prefix.pop_back();
- set_number(node, get_number(node)-1);
- return;
- }
};
#endif
Modified: trunk/src/check/time/hmsc_tighten.h
===================================================================
--- trunk/src/check/time/hmsc_tighten.h 2009-07-07 15:09:15 UTC (rev 260)
+++ trunk/src/check/time/hmsc_tighten.h 2009-07-08 14:39:02 UTC (rev 261)
@@ -28,7 +28,11 @@
}
*/
- MscTimeIntervalSetD tighten(HMscAllPaths paths, MscTimeIntervalSetD i, HMscPtr hmsc)
+ MscTimeIntervalSetD tighten(
+ HMscAllPaths paths,
+ MscTimeIntervalSetD i,
+ HMscPtr hmsc
+ )
{
@@ -108,47 +112,40 @@
if(from_node)
m_msc = from_node;
-
}
else
{
-
- BMscPtr msc_tmp;
- ReferenceNode* ref_node = dynamic_cast<ReferenceNode*>((*n_path).get());
- BMscPtr from_node = ref_node->get_bmsc();
- if(from_node)
- msc_tmp = from_node;
+ BMscPtr msc_tmp;
+ ReferenceNode* ref_node = dynamic_cast<ReferenceNode*>((*n_path).get());
+ BMscPtr from_node = ref_node->get_bmsc();
+ if(from_node)
+ msc_tmp = from_node;
-// m_msc = concatenate(m_msc, msc_tmp); //TODO:concatenation
+// m_msc = concatenate(m_msc, msc_tmp); //TODO:concatenation
}
-
-
- }
+ }
- ConstMatrixPair pair;
- if(m_msc_list.empty())
- {
-
- TightenBMsc tighten_msc(m_msc);
- pair = tighten_msc.tighten_msc(i);
+ ConstMatrixPair pair;
+ if(m_msc_list.empty())
+ {
+ TightenBMsc tighten_msc(m_msc);
+ pair = tighten_msc.tighten_msc(i);
m_t = pair.second;
i_prime_prime = MscTimeIntervalSetD::set_intersection(i_prime_prime,pair.first);
-
- }
- else
- {
+ }
+ else
+ {
m_msc_list.push_back(m_msc);
- MscTimeIntervalSetD i_prime_prime_prime;
-// TightenMsgPath tighten_msg_path(m_msc_list); //TODO: MSG PATH
- i_prime_prime_prime = tighten_msg_path(m_msc_list,m_constr,i);
+ MscTimeIntervalSetD i_prime_prime_prime;
+// TightenMsgPath tighten_msg_path(m_msc_list); //TODO: MSG PATH
+ i_prime_prime_prime = tighten_msg_path(m_msc_list,m_constr,i);
- i_prime_prime = MscTimeIntervalSetD::set_intersection(i_prime_prime,pair.first);
- }
-
- }
+ i_prime_prime = MscTimeIntervalSetD::set_intersection(i_prime_prime,pair.first);
+ }
+ }
HMscNodePtrList::iterator path_it;
@@ -166,7 +163,6 @@
relation_copy->set_interval_set(interval_set);
}
-
}
//TODO:upravit nakopirovat povodne obmedzenia naspat
@@ -191,106 +187,110 @@
std::set<BMscPtr>::iterator b_it2;
for(b_it2 = m_bmsc_copy2.begin(); b_it2!= m_bmsc_copy2.end(); b_it2++)
- {
- //TODO:write get_all_constraints
- std::set<TimeRelationEventPtr> constraints;
-// constraints = get_all_constraints(*b_it);
- std::set<TimeRelationEventPtr>::iterator tr_it2;
+ {
+ //TODO:write get_all_constraints
+ std::set<TimeRelationEventPtr> constraints;
+// constraints = get_all_constraints(*b_it);
+ std::set<TimeRelationEventPtr>::iterator tr_it2;
- for(tr_it2 = constraints.begin(); tr_it2 != constraints.end(); tr_it2++)
- {
- TimeRelationEvent* relation_copy = dynamic_cast<TimeRelationEvent*>((*tr_it2)->get_original());
+ for(tr_it2 = constraints.begin(); tr_it2 != constraints.end(); tr_it2++)
+ {
+ TimeRelationEvent* relation_copy = dynamic_cast<TimeRelationEvent*>((*tr_it2)->get_original());
- //TODO:upravit
- relation_copy->set_interval_set((*tr_it2)->get_interval_set());
+ //TODO:upravit
+ relation_copy->set_interval_set((*tr_it2)->get_interval_set());
- }
+ }
- }
+ }
-return i_prime_prime;
+ return i_prime_prime;
+ }
+
+ MscTimeIntervalSetD tighten_msg_path(
+ std::list<BMscPtr> list_bmsc,
+ std::list<TimeRelationRefNodePtr> constr,
+ MscTimeIntervalSetD interval
+ )
+ {
+ MscTimeIntervalSetD tmp_interval(interval);
+ std::vector<MscTimeIntervalSetD> durations;
+ for(int i=0;i<list_bmsc.size();i++)
+ {
+ MscTimeIntervalSetD tmp;
+
+ tmp.insert(MscTimeIntervalD(0,D::infinity()));
+ durations.push_back(tmp);
+ }
+
+ MscTimeIntervalSetD s_interval;
+ do {
+ s_interval = tmp_interval;
+ std::list<BMscPtr>::iterator bmsc;
+
+ int i=0;
+ for(bmsc=list_bmsc.begin();bmsc!=list_bmsc.end();bmsc++,i++)
+ {
+ MscTimeIntervalSetD tmp_i=tmp_interval;
+ for(int j=0;j<list_bmsc.size();j++)
+ {
+ if(i==j)
+ continue;
+ tmp_i = tmp_i - durations[j];
+ }
+ std::list<TimeRelationRefNodePtr>::iterator c_it;
+ for(c_it=constr.begin();c_it!=constr.end();c_it++)
+ tmp_i = tmp_i - (*c_it)->get_interval_set();
+
+ durations[i]=TightenBMsc::tight(*bmsc,MscTimeIntervalSetD::set_intersection(tmp_i,durations[i]));
}
+ MscTimeIntervalSetD interval_set;
- MscTimeIntervalSetD tighten_msg_path(std::list<BMscPtr> list_bmsc,std::list<TimeRelationRefNodePtr> constr,MscTimeIntervalSetD interval)
+ std::list<TimeRelationRefNodePtr>::iterator c_it2;
+ for(c_it2=constr.begin();c_it2!=constr.end();c_it2++)
{
- MscTimeIntervalSetD tmp_interval(interval);
- std::vector<MscTimeIntervalSetD> durations;
- for(int i=0;i<list_bmsc.size();i++)
+ interval_set = (*c_it2)->get_interval_set();
+ MscTimeIntervalSetD tmp_i=tmp_interval;
+ for(int j=0;j<list_bmsc.size();j++)
{
- MscTimeIntervalSetD tmp;
-
- tmp.insert(MscTimeIntervalD(0,D::infinity()));
- durations.push_back(tmp);
+ tmp_i = tmp_i - durations[j];
+ }
+ interval_set = (*c_it2)->get_interval_set();
+ std::list<TimeRelationRefNodePtr>::iterator c_it;
+ for(c_it=constr.begin();c_it!=constr.end();c_it++)
+ {
+ interval_set = (*c_it2)->get_interval_set();
+ if(*c_it==*c_it2)
+ continue;
+ tmp_i = tmp_i - (*c_it)->get_interval_set();
}
- MscTimeIntervalSetD s_interval;
- do {
- s_interval = tmp_interval;
- std::list<BMscPtr>::iterator bmsc;
- int i=0;
- for(bmsc=list_bmsc.begin();bmsc!=list_bmsc.end();bmsc++,i++)
- {
- MscTimeIntervalSetD tmp_i=tmp_interval;
- for(int j=0;j<list_bmsc.size();j++)
- {
- if(i==j)
- continue;
- tmp_i = tmp_i - durations[j];
- }
- std::list<TimeRelationRefNodePtr>::iterator c_it;
- for(c_it=constr.begin();c_it!=constr.end();c_it++)
- tmp_i = tmp_i - (*c_it)->get_interval_set();
+ interval_set = (*c_it2)->get_interval_set();
+ (*c_it2)->set_interval_set(MscTimeIntervalSetD::set_intersection((*c_it2)->get_interval_set(),tmp_i));
+ interval_set = (*c_it2)->get_interval_set();
+ }
- durations[i]=TightenBMsc::tight(*bmsc,MscTimeIntervalSetD::set_intersection(tmp_i,durations[i]));
- }
- MscTimeIntervalSetD interval_set;
+ MscTimeIntervalSetD tmp;
+ tmp.insert(MscTimeIntervalD(0,0));
- std::list<TimeRelationRefNodePtr>::iterator c_it2;
- for(c_it2=constr.begin();c_it2!=constr.end();c_it2++)
- {
- interval_set = (*c_it2)->get_interval_set();
- MscTimeIntervalSetD tmp_i=tmp_interval;
- for(int j=0;j<list_bmsc.size();j++)
- {
- tmp_i = tmp_i - durations[j];
- }
- interval_set = (*c_it2)->get_interval_set();
- std::list<TimeRelationRefNodePtr>::iterator c_it;
- for(c_it=constr.begin();c_it!=constr.end();c_it++)
- {
- interval_set = (*c_it2)->get_interval_set();
- if(*c_it==*c_it2)
- continue;
- tmp_i = tmp_i - (*c_it)->get_interval_set();
- }
- interval_set = (*c_it2)->get_interval_set();
- (*c_it2)->set_interval_set(MscTimeIntervalSetD::set_intersection((*c_it2)->get_interval_set(),tmp_i));
- interval_set = (*c_it2)->get_interval_set();
- }
+ for(int j=0;j<list_bmsc.size();j++)
+ {
+ tmp = tmp + durations[j];
+ }
- MscTimeIntervalSetD tmp;
- tmp.insert(MscTimeIntervalD(0,0));
+ std::list<TimeRelationRefNodePtr>::iterator c_it;
+ for(c_it=constr.begin();c_it!=constr.end();c_it++)
+ {
+ MscTimeIntervalSetD uu = (*c_it)->get_interval_set();
+ tmp = uu + tmp;
+ }
- for(int j=0;j<list_bmsc.size();j++)
- {
- tmp = tmp + durations[j];
- }
-
- std::list<TimeRelationRefNodePtr>::iterator c_it;
- for(c_it=constr.begin();c_it!=constr.end();c_it++)
- {
- MscTimeIntervalSetD uu = (*c_it)->get_interval_set();
- tmp = uu + tmp;
- }
-
- tmp_interval = MscTimeIntervalSetD::set_intersection(tmp_interval,tmp);
-
+ tmp_interval = MscTimeIntervalSetD::set_intersection(tmp_interval,tmp);
-
- } while(s_interval!=tmp_interval);
+ } while(s_interval!=tmp_interval);
- return tmp_interval;
- }
+ return tmp_interval;
+ }
};
Modified: trunk/src/check/time/time_consistency.h
===================================================================
--- trunk/src/check/time/time_consistency.h 2009-07-07 15:09:15 UTC (rev 260)
+++ trunk/src/check/time/time_consistency.h 2009-07-08 14:39:02 UTC (rev 261)
@@ -48,8 +48,10 @@
class MatrixFunc
{
public:
- static void fill_matrix(IntervalMatrix& matrix, MscTimeIntervalD c,\
- unsigned x,unsigned y)
+ //! adding to the matrix INTERVAL c to (x,y) and its inverse to (y,x)
+ static
+ void fill_matrix(IntervalMatrix& matrix, MscTimeIntervalD c,\
+ unsigned x,unsigned y)
{
if(x>=matrix.size1()||y>=matrix.size2())
throw matrix.size1();
@@ -57,6 +59,7 @@
matrix(y,x) = MscTimeIntervalD::interval_inverse(c);
}
+ //! adding to the matrix-set INTERVAL SET c to (x,y) and its inverse to (y,x)
static
void fill_matrix(IntervalSetMatrix& matrix, MscTimeIntervalSetD c, \
unsigned x,unsigned y)
@@ -67,6 +70,7 @@
matrix(y,x) = MscTimeIntervalSetD::interval_inverse(c);
}
+ //! adding to the matrix-set INTERVAL c to (x,y) and its inverse to (y,x)
static
void fill_matrix(IntervalSetMatrix& matrix, MscTimeIntervalD c, \
unsigned x,unsigned y)
@@ -77,6 +81,7 @@
matrix(y,x).insert(MscTimeIntervalD::interval_inverse(c));
}
+ //! check whether two matrices are equal
static
bool is_equal(
IntervalSetMatrix lhs,
@@ -99,7 +104,7 @@
}
return true;
}
-
+ static
void print_out(IntervalSetMatrix matrix)
{
std::cout << "matrix: " << matrix.size1() << "x" <<
@@ -108,14 +113,14 @@
{
for(unsigned j=0;j<matrix.size2();j++)
{
- std::cout.width(15); std::cout << std::left << matrix(i,j);
+ std::cout << " {" << matrix(i,j) << "}";
}
std::cout << std::endl;
}
}
};
-
+//! time inconsistency exception
class MscTimeInconsistencyException : public std::exception
{
@@ -127,7 +132,7 @@
};
-
+//! Abstract class to the tightener
class MscIntervalTightener
{
public:
@@ -136,13 +141,14 @@
};
+//! Abstract class to the Consistency checker
class MscIntervalConsistencyCheck
{
public:
virtual bool check_consistency(const IntervalMatrix&)=0;
};
-
+//! Floyd Warshall: consistency checker and tightener, IntervalMatrix
class SCTIME_EXPORT FloydWarshall:
public MscIntervalTightener,
public MscIntervalConsistencyCheck
@@ -150,7 +156,7 @@
public:
FloydWarshall()
{}
-
+
const IntervalMatrix tight(const IntervalMatrix&)
throw(MscTimeInconsistencyException);
@@ -187,20 +193,15 @@
class SCTIME_EXPORT BmscMatrixConverter:public WhiteEventFoundListener
{
private:
- // Vector of all events - event <-- matrix number
- EventPVector m_events;
- // Map of event and its first successors
- EventPMap m_succs;
- // main matrix of Interval Sets
- IntervalSetMatrix m_matrix;
- // keeping number of colum/row of event in matrix, event --> matrix
- std::string m_number;
+ EventPVector m_events; //!< Vector of all events - event <-- matrix number
+ EventPMap m_succs; //!< Map of event and its first successors
+ IntervalSetMatrix m_matrix; //!< main matrix of Interval Sets
+ std::string m_number; //!< attribute,event(m_number=number) --> matrix
VisualClosureInitiator closure_initiator;
TopologicalOrderListener topology_listener;
DFSEventsTraverser traverser;
- // bmsc to be converted to matrix
- BMscPtr m_bmsc;
+ BMscPtr m_bmsc; //!< bmsc to be converted to the matrix
void get_first_area_events(EventArea*,Event*);
@@ -281,7 +282,6 @@
BmscMatrixConverter(const std::string number="bmsc_matrix_converter_number")
:m_number(number)
{
- std::cerr << "uuuuu" << std::endl;
}
bool is_leq(Event* a,Event *b)
Modified: trunk/tests/incon_test.cpp
===================================================================
--- trunk/tests/incon_test.cpp 2009-07-07 15:09:15 UTC (rev 260)
+++ trunk/tests/incon_test.cpp 2009-07-08 14:39:02 UTC (rev 261)
@@ -231,7 +231,7 @@
karel(4,0) = MscTimeIntervalDSet::interval_inverse(ins5);
std::cerr << karel << std::endl;
-
+ MatrixFunc::print_out(karel);
std::cout << sol.solve(karel) << std::endl;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|