mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
Integration of OCCT 6.5.0 from SVN
This commit is contained in:
98
src/GraphTools/GraphTools.cdl
Executable file
98
src/GraphTools/GraphTools.cdl
Executable file
@@ -0,0 +1,98 @@
|
||||
-- File: GraphTools.cdl
|
||||
-- Created: Thu Mar 7 11:03:52 1991
|
||||
-- Author: Denis Pascal
|
||||
-- <dp@topsn2>
|
||||
---Copyright: Matra Datavision 1991, 1992
|
||||
|
||||
|
||||
package GraphTools
|
||||
|
||||
---Purpose: This package <GraphTools> provides algorithms working
|
||||
-- on a directed graph. Those algorithms are generic for
|
||||
-- user (Graph and Vertex) data, and tool classes.
|
||||
|
||||
|
||||
uses Standard,
|
||||
MMgt,
|
||||
TCollection,
|
||||
TColStd
|
||||
|
||||
is
|
||||
|
||||
|
||||
class ListOfSequenceOfInteger instantiates List from TCollection
|
||||
(SequenceOfInteger from TColStd);
|
||||
|
||||
-- Requirements
|
||||
-- ============
|
||||
|
||||
-- Data
|
||||
-- Vertex
|
||||
-- Graph
|
||||
-- Tools
|
||||
generic class GraphIterator;
|
||||
generic class VertexIterator;
|
||||
|
||||
-- Services (Algorithms)
|
||||
-- =====================
|
||||
|
||||
|
||||
---Purpose: Depth First Search (DFS)
|
||||
|
||||
generic class DFSIterator,
|
||||
DFSMap;
|
||||
|
||||
|
||||
---Purpose: Breath First Search (BFS)
|
||||
|
||||
generic class BFSIterator,
|
||||
BFSMap;
|
||||
|
||||
|
||||
---Purpose: Sorted Strong Components (SC)
|
||||
|
||||
generic class SortedStrgCmptsFromIterator,
|
||||
SCMap;
|
||||
|
||||
generic class SortedStrgCmptsIterator;
|
||||
|
||||
|
||||
---Purpose: Topological Sort (TS)
|
||||
|
||||
class TSNode;
|
||||
|
||||
generic class TopologicalSortFromIterator,
|
||||
TSMap;
|
||||
|
||||
generic class TopologicalSortIterator;
|
||||
|
||||
|
||||
---Purpose: Connected Vertices (CV)
|
||||
|
||||
generic class ConnectedVerticesFromIterator,
|
||||
CVMap,
|
||||
ConnectMap;
|
||||
|
||||
generic class ConnectedVerticesIterator;
|
||||
|
||||
|
||||
---Purpose: Reduced Graph (RG)
|
||||
|
||||
class RGNode;
|
||||
|
||||
class SC;
|
||||
|
||||
class SCList instantiates List from TCollection
|
||||
(SC from GraphTools);
|
||||
|
||||
generic class ReducedGraph,
|
||||
RGMap,
|
||||
SortedSCIterator,
|
||||
AdjSCIterator;
|
||||
|
||||
end GraphTools;
|
||||
|
||||
|
||||
|
||||
|
||||
|
79
src/GraphTools/GraphTools_AdjSCIterator.gxx
Executable file
79
src/GraphTools/GraphTools_AdjSCIterator.gxx
Executable file
@@ -0,0 +1,79 @@
|
||||
// Copyright: Matra-Datavision 1991
|
||||
// File: GraphTools_AdjSCIterator.gxx
|
||||
// Created: Wed Oct 23 16:28:16 1991
|
||||
// Author: Denis PASCAL
|
||||
// <dp>
|
||||
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : GraphTools_AdjSCIterator
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
GraphTools_AdjSCIterator::GraphTools_AdjSCIterator ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : GraphTools_AdjSCIterator
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
GraphTools_AdjSCIterator::GraphTools_AdjSCIterator
|
||||
(const GraphTools_ReducedGraph& RG,
|
||||
const Handle(GraphTools_SC)& SC)
|
||||
{
|
||||
Initialize (RG,SC);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Initialize
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void GraphTools_AdjSCIterator::Initialize
|
||||
(const GraphTools_ReducedGraph& RG,
|
||||
const Handle(GraphTools_SC)& SC)
|
||||
{
|
||||
myIterator.Initialize(SC->GetFrontSC());
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : More
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Standard_Boolean GraphTools_AdjSCIterator::More() const
|
||||
{
|
||||
return myIterator.More();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Next
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void GraphTools_AdjSCIterator::Next()
|
||||
{
|
||||
myIterator.Next();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Value
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Handle(GraphTools_SC) GraphTools_AdjSCIterator::Value () const
|
||||
{
|
||||
return myIterator.Value();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
64
src/GraphTools/GraphTools_BFSIterator.cdl
Executable file
64
src/GraphTools/GraphTools_BFSIterator.cdl
Executable file
@@ -0,0 +1,64 @@
|
||||
-- File: GraphTools_BFSIterator.cdl
|
||||
-- Created: Mon Oct 12 12:58:52 1992
|
||||
-- Author: Denis PASCAL
|
||||
-- <dp@bravox>
|
||||
---Copyright: Matra Datavision 1992
|
||||
|
||||
|
||||
generic class BFSIterator from GraphTools
|
||||
(Graph as any;
|
||||
Vertex as any;
|
||||
VHasher as any;
|
||||
VIterator as any)
|
||||
|
||||
--generic class BFSIterator from GraphTools
|
||||
-- (Graph as any;
|
||||
-- Vertex as any;
|
||||
-- VHasher as MapHasher from TCollection (Vertex);
|
||||
-- VIterator as VertexIterator (Graph,Vertex))
|
||||
|
||||
---Purpose: This generic class implement the Breadth First Search
|
||||
-- algorithm from a Vertex with an iterator to reached
|
||||
-- adjacent vertices of a given one. The interface of
|
||||
-- this algorithm is made as an iterator.
|
||||
|
||||
raises NoMoreObject from Standard,
|
||||
NoSuchObject from Standard
|
||||
|
||||
class BFSMap instantiates IndexedMap from TCollection (Vertex,VHasher);
|
||||
|
||||
is
|
||||
|
||||
Create
|
||||
returns BFSIterator;
|
||||
---Purpose: Create an empty iterator.
|
||||
|
||||
Perform (me : in out; G : Graph; V : Vertex);
|
||||
---Purpose: Initializes the research from <V> member vertex of <G>.
|
||||
---Level: Public
|
||||
|
||||
More (me) returns Boolean from Standard;
|
||||
---Purpose: Returns True if there are other vertices.
|
||||
---Level: Public
|
||||
|
||||
Next(me : in out)
|
||||
---Purpose: Set the iterator to the next vertex.
|
||||
---Level: Public
|
||||
raises NoMoreObject from Standard;
|
||||
|
||||
Value(me) returns any Vertex
|
||||
---Purpose: returns the vertex value for the current
|
||||
-- position of the iterator.
|
||||
---Level: Public
|
||||
---C++: return const &
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
fields
|
||||
|
||||
myVisited : BFSMap from GraphTools;
|
||||
myCurrentIndex : Integer from Standard;
|
||||
|
||||
end BFSIterator;
|
||||
|
||||
|
||||
|
86
src/GraphTools/GraphTools_BFSIterator.gxx
Executable file
86
src/GraphTools/GraphTools_BFSIterator.gxx
Executable file
@@ -0,0 +1,86 @@
|
||||
// File: GraphTools_BFSIterator.gxx
|
||||
// Created: Mon Oct 12 16:34:41 1992
|
||||
// Author: Denis PASCAL
|
||||
// <dp@bravox>
|
||||
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <TColStd_QueueOfInteger.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : GraphTools_BFSIterator
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
GraphTools_BFSIterator::GraphTools_BFSIterator () {}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Perform
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_BFSIterator::Perform
|
||||
(const Graph& G, const Vertex& V)
|
||||
{
|
||||
Standard_Integer index;
|
||||
myVisited.Clear();
|
||||
TColStd_QueueOfInteger myReady;
|
||||
|
||||
index = myVisited.Add(V);
|
||||
myReady.Push(index);
|
||||
while (!myReady.IsEmpty()) {
|
||||
Vertex w1 = myVisited (myReady.Front());
|
||||
myReady.Pop();
|
||||
for (VIterator it(G,w1); it.More(); it.Next()) {
|
||||
Vertex w2 = it.Value();
|
||||
if (!myVisited.Contains(w2)) {
|
||||
index = myVisited.Add(w2);
|
||||
myReady.Push(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
myCurrentIndex = 1;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : More
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean GraphTools_BFSIterator::More () const
|
||||
{
|
||||
return myCurrentIndex <= myVisited.Extent();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Next
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_BFSIterator::Next ()
|
||||
{
|
||||
myCurrentIndex++;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Value
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const Vertex& GraphTools_BFSIterator::Value () const
|
||||
{
|
||||
return myVisited(myCurrentIndex);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
92
src/GraphTools/GraphTools_ConnectedVerticesFromIterator.cdl
Executable file
92
src/GraphTools/GraphTools_ConnectedVerticesFromIterator.cdl
Executable file
@@ -0,0 +1,92 @@
|
||||
-- File: ConnectedVerticesFromIterator.cdl
|
||||
-- Created: Fri Oct 16 15:35:36 1992
|
||||
-- Author: Arnaud BOUZY
|
||||
-- <adn@bravox>
|
||||
---Copyright: Matra Datavision 1992
|
||||
|
||||
|
||||
generic class ConnectedVerticesFromIterator from GraphTools
|
||||
(Graph as any;
|
||||
Vertex as any;
|
||||
VIterator as any)
|
||||
|
||||
|
||||
---Purpose: In a graph, returns subsets of a list of vertices in
|
||||
-- which all vertices are connected.
|
||||
|
||||
uses HArray1OfInteger from TColStd
|
||||
|
||||
class CVMap instantiates IndexedMap from TCollection
|
||||
(Vertex,
|
||||
MapTransientHasher from TColStd);
|
||||
|
||||
class ConnectMap instantiates DataMap from TCollection
|
||||
(Vertex,
|
||||
Integer from Standard,
|
||||
MapTransientHasher from TColStd);
|
||||
|
||||
|
||||
is
|
||||
|
||||
Create
|
||||
---Purpose: Create an empty algorithm.
|
||||
returns ConnectedVerticesFromIterator;
|
||||
|
||||
FromVertex (me : in out; V : Vertex);
|
||||
---Purpose: Add <V> as initial condition. This method is
|
||||
-- cumulative. Use Perform method before visting the
|
||||
-- result of the algorithm.
|
||||
---Level: Public
|
||||
|
||||
Reset (me : in out);
|
||||
---Purpose: Reset the algorithm. It may be reused with new
|
||||
-- conditions.
|
||||
---Level: Public
|
||||
|
||||
Perform (me : in out; G : Graph);
|
||||
---Purpose: Peform the algorithm in <G> from initial setted
|
||||
-- conditions.
|
||||
---Level: Public
|
||||
|
||||
More(me)
|
||||
---Purpose: Returns TRUE if there are others subset of
|
||||
-- connected vertices.
|
||||
---Level: Public
|
||||
returns Boolean from Standard;
|
||||
|
||||
Next (me : in out);
|
||||
---Purpose: Set the iterator to the next subset of connected
|
||||
-- vertices.
|
||||
---Level: Public
|
||||
|
||||
NbVertices (me)
|
||||
returns Integer from Standard;
|
||||
---Purpose: Returns number of vertices of the current subset
|
||||
-- of connected vertices.
|
||||
---Level: Public
|
||||
|
||||
Value (me; index : Integer from Standard)
|
||||
returns any Vertex;
|
||||
---Purpose: Returns a vertex member of the current subset of
|
||||
-- connected vertices.
|
||||
---Level: Public
|
||||
---C++: return const&
|
||||
|
||||
Visit (me : in out; V : Vertex;
|
||||
G : Graph;
|
||||
visited : in out ConnectMap from GraphTools)
|
||||
---Purpose: Recursively called to visit the vertices connected to
|
||||
-- <avert> in <agraph>, with already visited vertices
|
||||
-- <visited>.
|
||||
---Level: Internal
|
||||
is private;
|
||||
|
||||
fields
|
||||
|
||||
initMap : CVMap from GraphTools;
|
||||
tab : HArray1OfInteger from TColStd;
|
||||
myCurrent : Integer from Standard;
|
||||
|
||||
end ConnectedVerticesFromIterator;
|
||||
|
||||
|
201
src/GraphTools/GraphTools_ConnectedVerticesFromIterator.gxx
Executable file
201
src/GraphTools/GraphTools_ConnectedVerticesFromIterator.gxx
Executable file
@@ -0,0 +1,201 @@
|
||||
// Copyright: Matra-Datavision 1992
|
||||
// File: GraphTools_ConnectedVerticesFromIterator.gxx
|
||||
// Created: Mon Oct 19 10:45:58 1992
|
||||
// Author: Arnaud BOUZY
|
||||
// <adn>
|
||||
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : GraphTools_ConnectedVerticesFromIterator
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
GraphTools_ConnectedVerticesFromIterator::GraphTools_ConnectedVerticesFromIterator()
|
||||
{
|
||||
myCurrent = 0;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : FromVertex
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_ConnectedVerticesFromIterator::FromVertex(const Vertex& avert)
|
||||
{
|
||||
initMap.Add(avert);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Reset
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_ConnectedVerticesFromIterator::Reset ()
|
||||
{
|
||||
myCurrent = 0;
|
||||
initMap.Clear();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Perform
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_ConnectedVerticesFromIterator::Perform (const Graph& aGraph)
|
||||
{
|
||||
Standard_Integer nbvert = initMap.Extent();
|
||||
GraphTools_ConnectMap visited;
|
||||
Standard_Integer i;
|
||||
for (i=1;i<=nbvert; i++) {
|
||||
visited.Bind(initMap(i),i);
|
||||
}
|
||||
for (i=1;i<=nbvert; i++) {
|
||||
if (visited(initMap(i)) == i) {
|
||||
myCurrent = i;
|
||||
VIterator vit(aGraph,initMap(i));
|
||||
while (vit.More()) {
|
||||
Visit(vit.Value(),aGraph,visited);
|
||||
vit.Next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tab = new TColStd_HArray1OfInteger(1,nbvert,0);
|
||||
for (i=1; i<= nbvert; i++) {
|
||||
tab->SetValue(i,visited(initMap(i)));
|
||||
}
|
||||
myCurrent = 0;
|
||||
Next();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : More
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean GraphTools_ConnectedVerticesFromIterator::More() const
|
||||
{
|
||||
for (Standard_Integer i=1; i<= tab->Upper(); i++) {
|
||||
if (tab->Value(i) >= myCurrent) {
|
||||
return Standard_True;
|
||||
}
|
||||
}
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Next
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_ConnectedVerticesFromIterator::Next()
|
||||
{
|
||||
Standard_Boolean found=Standard_False;
|
||||
myCurrent++;
|
||||
Standard_Integer nbv = tab->Upper();
|
||||
Standard_Integer i;
|
||||
while (!found && (myCurrent <= nbv)) {
|
||||
for (i=1; (i<= nbv) && !found; i++) {
|
||||
if (tab->Value(i) == myCurrent) {
|
||||
found = Standard_True;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
myCurrent++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : NbVertices
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer GraphTools_ConnectedVerticesFromIterator::NbVertices() const
|
||||
{
|
||||
if (!More()) {
|
||||
Standard_NoSuchObject::Raise();
|
||||
}
|
||||
Standard_Integer res = 0;
|
||||
for (Standard_Integer i=1; i<= tab->Upper(); i++) {
|
||||
if (tab->Value(i) == myCurrent) {
|
||||
res++;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Value
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const Vertex& GraphTools_ConnectedVerticesFromIterator::Value
|
||||
(const Standard_Integer index) const
|
||||
{
|
||||
if (!More()) {
|
||||
Standard_NoSuchObject::Raise();
|
||||
}
|
||||
Standard_Integer current=0;
|
||||
for (Standard_Integer i=1; i<= tab->Upper(); i++) {
|
||||
if (tab->Value(i) == myCurrent) {
|
||||
current++;
|
||||
if (current == index) {
|
||||
return initMap(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Visit
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_ConnectedVerticesFromIterator::Visit
|
||||
(const Vertex& avert,
|
||||
const Graph& agraph,
|
||||
GraphTools_ConnectMap& visited)
|
||||
{
|
||||
Standard_Boolean godown = Standard_False;
|
||||
if (!visited.IsBound(avert)) {
|
||||
visited.Bind(avert,myCurrent);
|
||||
godown = Standard_True;
|
||||
}
|
||||
else {
|
||||
Standard_Integer thebound = visited(avert);
|
||||
if (thebound > myCurrent) {
|
||||
visited(avert) = myCurrent;
|
||||
godown = Standard_True;
|
||||
}
|
||||
else if (thebound < myCurrent) {
|
||||
Standard_Integer rebind = visited(initMap(thebound));
|
||||
for (Standard_Integer i=1; i <= initMap.Extent(); i++) {
|
||||
if ((visited(initMap(i)) == thebound) ||
|
||||
(visited(initMap(i)) == rebind)) {
|
||||
visited(initMap(i)) = myCurrent;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (godown) {
|
||||
VIterator vit(agraph,avert);
|
||||
while (vit.More()) {
|
||||
Visit(vit.Value(),agraph,visited);
|
||||
vit.Next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
93
src/GraphTools/GraphTools_ConnectedVerticesIterator.cdl
Executable file
93
src/GraphTools/GraphTools_ConnectedVerticesIterator.cdl
Executable file
@@ -0,0 +1,93 @@
|
||||
-- File: GraphTools_ConnectedVerticesIterator.cdl
|
||||
-- Created: Thu Mar 18 17:41:39 1993
|
||||
-- Author: Denis PASCAL
|
||||
-- <dp@bravox>
|
||||
---Copyright: Matra Datavision 1993
|
||||
|
||||
|
||||
generic class ConnectedVerticesIterator from GraphTools
|
||||
(Graph as any;
|
||||
Vertex as any;
|
||||
GIterator as any;
|
||||
CVIterator as any)
|
||||
|
||||
--generic class ConnectedVerticesIterator from GraphTools
|
||||
-- (Graph as any;
|
||||
-- Vertex as any;
|
||||
-- GIterator as GraphIterator (Graph,Vertex))
|
||||
-- CVIterator as ConnectedVerticesFromIterator
|
||||
|
||||
---Purpose: In a graph, returns subsets of a list of vertices in
|
||||
-- which all vertices are connected.
|
||||
|
||||
is
|
||||
|
||||
Create
|
||||
---Purpose: Create an empty algorithm.
|
||||
returns ConnectedVerticesIterator from GraphTools;
|
||||
|
||||
Create (G : Graph)
|
||||
---Purpose: Create the algorithm setting each vertex of <G>
|
||||
-- reached by GIterator tool, as initial conditions.
|
||||
-- Use Perform method before visting the result of
|
||||
-- the algorithm.
|
||||
returns ConnectedVerticesIterator from GraphTools;
|
||||
|
||||
FromGraph (me : in out; G : Graph);
|
||||
---Purpose: Add each vertex of <G> reached by GIterator tool
|
||||
-- as initial conditions. Use Perform method
|
||||
-- before visiting the result of the algorithm.
|
||||
---Level: Public;
|
||||
|
||||
FromVertex (me : in out; V : Vertex);
|
||||
---Purpose: Add <V> as research condition. This method is
|
||||
-- cumulative. User must used Perform method before
|
||||
-- visting the result of the algorithm.
|
||||
---Level: Public
|
||||
|
||||
Reset (me : in out);
|
||||
---Purpose: Reset the algorithm. It may be reused with new
|
||||
-- initial conditions.
|
||||
---Level: Public
|
||||
|
||||
Perform (me : in out; G : Graph);
|
||||
---Purpose: Peform the algorithm in <G> from initial setted
|
||||
-- conditions.
|
||||
---Level: Public
|
||||
|
||||
More(me)
|
||||
---Purpose: Returns TRUE if there are others subset of
|
||||
-- connected vertices.
|
||||
---Level: Public
|
||||
returns Boolean from Standard;
|
||||
|
||||
Next (me : in out);
|
||||
---Purpose: Set the iterator to the next subset of connected
|
||||
-- vertices.
|
||||
---Level: Public
|
||||
|
||||
NbVertices (me)
|
||||
returns Integer from Standard;
|
||||
---Purpose: Returns number of vertices of the current subset
|
||||
-- of connected vertices.
|
||||
---Level: Public
|
||||
|
||||
Value (me; index : Integer from Standard)
|
||||
returns any Vertex;
|
||||
---Purpose: Returns a vertex member of the current subset of
|
||||
-- connected vertices.
|
||||
---Level: Public
|
||||
---C++: return const&
|
||||
|
||||
fields
|
||||
|
||||
myIterator : CVIterator;
|
||||
|
||||
end ConnectedVerticesIterator;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
131
src/GraphTools/GraphTools_ConnectedVerticesIterator.gxx
Executable file
131
src/GraphTools/GraphTools_ConnectedVerticesIterator.gxx
Executable file
@@ -0,0 +1,131 @@
|
||||
// Copyright: Matra-Datavision 1991
|
||||
// File: GraphTools_ConnectedVerticesIterator.gxx
|
||||
// Created: Wed May 29 17:42:50 1991
|
||||
// Author: Denis PASCAL
|
||||
// <dp>
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : GraphTools_ConnectedVerticesIterator
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
GraphTools_ConnectedVerticesIterator::GraphTools_ConnectedVerticesIterator ()
|
||||
{}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : GraphTools_TopologicalSortIterator
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
GraphTools_ConnectedVerticesIterator::GraphTools_ConnectedVerticesIterator
|
||||
(const Graph& G)
|
||||
{
|
||||
FromGraph (G);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : FromVertex
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_ConnectedVerticesIterator::FromVertex
|
||||
(const Vertex& V)
|
||||
{
|
||||
myIterator.FromVertex(V);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : GraphTools_ConnectedVerticesIterator
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void GraphTools_ConnectedVerticesIterator::FromGraph (const Graph& G)
|
||||
{
|
||||
for ( GIterator it (G); it.More(); it.Next() ) {
|
||||
myIterator.FromVertex(it.Value());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Perform
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_ConnectedVerticesIterator::Perform
|
||||
(const Graph& G)
|
||||
{
|
||||
myIterator.Perform(G);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Reset
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_ConnectedVerticesIterator::Reset ()
|
||||
{
|
||||
myIterator.Reset();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : More
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Standard_Boolean GraphTools_ConnectedVerticesIterator::More () const
|
||||
{
|
||||
return myIterator.More();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Next
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void GraphTools_ConnectedVerticesIterator::Next ()
|
||||
{
|
||||
myIterator.Next();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : NbVertices
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer GraphTools_ConnectedVerticesIterator::NbVertices() const
|
||||
{
|
||||
return myIterator.NbVertices();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Value
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
const Vertex& GraphTools_ConnectedVerticesIterator::Value
|
||||
(const Standard_Integer I) const
|
||||
{
|
||||
return myIterator.Value(I);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
72
src/GraphTools/GraphTools_DFSIterator.cdl
Executable file
72
src/GraphTools/GraphTools_DFSIterator.cdl
Executable file
@@ -0,0 +1,72 @@
|
||||
-- File: GraphTools_DFSIterator.cdl
|
||||
-- Created: Thu Sep 24 15:57:35 1992
|
||||
-- Author: Denis PASCAL
|
||||
-- <dp@bravox>
|
||||
---Copyright: Matra Datavision 1992
|
||||
|
||||
generic class DFSIterator from GraphTools
|
||||
(Graph as any;
|
||||
Vertex as any;
|
||||
VHasher as any;
|
||||
VIterator as any)
|
||||
|
||||
---Purpose: This generic class implement the Depth First Search
|
||||
-- algorithm from a Vertex with an iterator to reached
|
||||
-- adjacent vertices of a given one. The interface of
|
||||
-- this algorithm is made as an iterator.
|
||||
|
||||
--generic class DFSIterator from GraphTools
|
||||
-- (Graph as any;
|
||||
-- Vertex as any;
|
||||
-- VHasher as MapHasher from TCollection (Vertex);
|
||||
-- VIterator as VertexIterator (Graph,Vertex))
|
||||
|
||||
raises NoMoreObject from Standard,
|
||||
NoSuchObject from Standard
|
||||
|
||||
class DFSMap instantiates IndexedMap from TCollection (Vertex,VHasher);
|
||||
|
||||
is
|
||||
|
||||
Create
|
||||
returns DFSIterator;
|
||||
---Purpose: Create an empty iterator.
|
||||
|
||||
Perform (me : in out; G : Graph; V : Vertex);
|
||||
---Purpose: Initializes the research from <V> member vertex of
|
||||
-- <G>.
|
||||
---Level: Public
|
||||
|
||||
More (me) returns Boolean from Standard;
|
||||
---Purpose: Returns True if there are other vertices.
|
||||
---Level: Public
|
||||
|
||||
Next(me : in out)
|
||||
---Purpose: Set the iterator to the next vertex.
|
||||
---Level: Public
|
||||
raises NoMoreObject from Standard;
|
||||
|
||||
Value (me) returns any Vertex
|
||||
---Purpose: returns the vertex value for the current position
|
||||
-- of the iterator.
|
||||
---C++: return const &
|
||||
---Level: Public
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
|
||||
fields
|
||||
|
||||
myVisited : DFSMap from GraphTools;
|
||||
myCurrentIndex : Integer from Standard;
|
||||
|
||||
end DFSIterator;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
78
src/GraphTools/GraphTools_DFSIterator.gxx
Executable file
78
src/GraphTools/GraphTools_DFSIterator.gxx
Executable file
@@ -0,0 +1,78 @@
|
||||
// File: GraphTools_DFSIterator.gxx
|
||||
// Created: Mon Oct 12 16:34:15 1992
|
||||
// Author: Denis PASCAL
|
||||
// <dp@bravox>
|
||||
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <TColStd_StackOfInteger.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : GraphTools_DFSIterator
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
GraphTools_DFSIterator::GraphTools_DFSIterator () {}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Perform
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_DFSIterator::Perform
|
||||
(const Graph& G, const Vertex& V)
|
||||
{
|
||||
Standard_Integer index;
|
||||
myVisited.Clear();
|
||||
TColStd_StackOfInteger myReady;
|
||||
|
||||
index = myVisited.Add(V);
|
||||
myReady.Push(index);
|
||||
while (!myReady.IsEmpty()) {
|
||||
Vertex w1 = myVisited (myReady.Top());
|
||||
myReady.Pop();
|
||||
for (VIterator it(G,w1); it.More(); it.Next()) {
|
||||
Vertex w2 = it.Value();
|
||||
if (!myVisited.Contains(w2)) {
|
||||
index = myVisited.Add(w2);
|
||||
myReady.Push(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
myCurrentIndex = 1;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : More
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean GraphTools_DFSIterator::More () const
|
||||
{
|
||||
return myCurrentIndex <= myVisited.Extent();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Next
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_DFSIterator::Next ()
|
||||
{
|
||||
myCurrentIndex++;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Value
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const Vertex& GraphTools_DFSIterator::Value () const
|
||||
{
|
||||
return myVisited(myCurrentIndex);
|
||||
}
|
||||
|
60
src/GraphTools/GraphTools_GraphIterator.cdl
Executable file
60
src/GraphTools/GraphTools_GraphIterator.cdl
Executable file
@@ -0,0 +1,60 @@
|
||||
-- File: GraphTools_GraphIterator.cdl
|
||||
-- Created: Wed Mar 6 18:20:11 1991
|
||||
-- Author: Denis Pascal
|
||||
-- <dp@topsn3>
|
||||
---Copyright: Matra Datavision 1991, 1992
|
||||
|
||||
|
||||
generic class GraphIterator from GraphTools (Graph as any;
|
||||
Vertex as any)
|
||||
|
||||
-- template class GraphIterator from GraphTools (Graph as any;
|
||||
-- Vertex as any)
|
||||
|
||||
---Purpose: Template class which defines signatures of an
|
||||
-- iterator to visit each vertex, member of the
|
||||
-- underlying graph.
|
||||
|
||||
|
||||
raises NoMoreObject from Standard,
|
||||
NoSuchObject from Standard
|
||||
|
||||
is
|
||||
|
||||
Create (G : Graph) returns GraphIterator;
|
||||
|
||||
More (me) returns Boolean;
|
||||
---Purpose: Returns TRUE if there are other vertices.
|
||||
---Level: Public
|
||||
|
||||
Next (me : in out)
|
||||
--- Purpose : Set the iterator to the next Vertex.
|
||||
---Level: Public
|
||||
raises NoMoreObject from Standard;
|
||||
|
||||
Value (me) returns Vertex
|
||||
--- Purpose: Returns the vertex value for the current position
|
||||
-- of the iterator
|
||||
---Level: Public
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
end GraphIterator;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
4
src/GraphTools/GraphTools_GraphIterator.gxx
Executable file
4
src/GraphTools/GraphTools_GraphIterator.gxx
Executable file
@@ -0,0 +1,4 @@
|
||||
// File: GraphTools_GraphIterator.gxx
|
||||
// Created: Mon Sep 27 18:12:51 1993
|
||||
// Author: Denis PASCAL
|
||||
// <dp@bravox>
|
43
src/GraphTools/GraphTools_RGNode.cdl
Executable file
43
src/GraphTools/GraphTools_RGNode.cdl
Executable file
@@ -0,0 +1,43 @@
|
||||
-- File: GraphTools_RGNode.cdl
|
||||
-- Created: Wed Sep 29 14:41:03 1993
|
||||
-- Author: Denis PASCAL
|
||||
-- <dp@bravox>
|
||||
---Copyright: Matra Datavision 1993
|
||||
|
||||
class RGNode from GraphTools
|
||||
|
||||
uses SC from GraphTools,
|
||||
SequenceOfInteger from TColStd
|
||||
|
||||
is
|
||||
|
||||
Create returns RGNode;
|
||||
|
||||
Reset (me : in out);
|
||||
|
||||
SetVisited (me : in out; v : Integer from Standard);
|
||||
|
||||
GetVisited (me)
|
||||
returns Integer from Standard;
|
||||
|
||||
AddAdj (me : in out; adj : Integer from Standard);
|
||||
|
||||
NbAdj (me)
|
||||
returns Integer from Standard;
|
||||
|
||||
GetAdj (me; index : Integer from Standard)
|
||||
returns Integer from Standard;
|
||||
|
||||
SetSC (me : in out; SC : SC from GraphTools);
|
||||
|
||||
GetSC (me)
|
||||
returns SC from GraphTools;
|
||||
|
||||
fields
|
||||
|
||||
visited : Integer from Standard;
|
||||
myAdj : SequenceOfInteger from TColStd;
|
||||
mySC : SC from GraphTools;
|
||||
|
||||
end RGNode;
|
||||
|
108
src/GraphTools/GraphTools_RGNode.cxx
Executable file
108
src/GraphTools/GraphTools_RGNode.cxx
Executable file
@@ -0,0 +1,108 @@
|
||||
|
||||
// File: GraphTools_RGNode.cxx
|
||||
// Created: Wed Sep 29 15:15:45 1993
|
||||
// Author: Denis PASCAL
|
||||
// <dp@bravox>
|
||||
|
||||
|
||||
#include <GraphTools_RGNode.ixx>
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : GraphTools_RGNode
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
GraphTools_RGNode::GraphTools_RGNode()
|
||||
{
|
||||
visited = 0;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Reset
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_RGNode::Reset()
|
||||
{
|
||||
visited = 0;
|
||||
myAdj.Clear();
|
||||
mySC.Nullify();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetVisited
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_RGNode::SetVisited(const Standard_Integer v)
|
||||
{
|
||||
visited = v;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : GetVisited
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer GraphTools_RGNode::GetVisited() const
|
||||
{
|
||||
return visited;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : AddAdj
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_RGNode::AddAdj (const Standard_Integer adj)
|
||||
{
|
||||
myAdj.Append(adj);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : NbAdj
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer GraphTools_RGNode::NbAdj() const
|
||||
{
|
||||
return myAdj.Length();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : GetAdj
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer GraphTools_RGNode::GetAdj
|
||||
(const Standard_Integer index) const
|
||||
{
|
||||
return myAdj(index);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : SetSC
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_RGNode::SetSC (const Handle(GraphTools_SC)& SC)
|
||||
{
|
||||
mySC = SC;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : GetSC
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(GraphTools_SC) GraphTools_RGNode::GetSC () const
|
||||
{
|
||||
return mySC;
|
||||
}
|
244
src/GraphTools/GraphTools_ReducedGraph.cdl
Executable file
244
src/GraphTools/GraphTools_ReducedGraph.cdl
Executable file
@@ -0,0 +1,244 @@
|
||||
-- File: GraphTools_ReducedGraph.cdl
|
||||
-- Created: Wed Jan 6 10:55:11 1993
|
||||
-- Author: Denis PASCAL
|
||||
-- <dp@bravox>
|
||||
---Copyright: Matra Datavision 1993
|
||||
|
||||
|
||||
generic class ReducedGraph from GraphTools
|
||||
(Graph as any;
|
||||
Vertex as any;
|
||||
VHasher as any;
|
||||
VIterator as any;
|
||||
GIterator as any)
|
||||
|
||||
--signature class ReducedGraph from GraphTools
|
||||
-- Graph as any;
|
||||
-- Vertex as any;
|
||||
-- VHasher as MapHasher from TCollection (Vertex);
|
||||
-- VIterator as VertexIterator (Graph,Vertex);
|
||||
-- GIterator as GraphIterator (Graph,Vertex))
|
||||
|
||||
---Purpose: this generic class defines an algorithm to build and
|
||||
-- visit the reduced graph of a given directed graph.
|
||||
--
|
||||
-- A reduced graph is defined itself as a graph where
|
||||
-- each vertex represents a strong component. Each
|
||||
-- strong component is a subset of vertices of the
|
||||
-- underlying graph which are mutually dependant in the
|
||||
-- way that there is always a path to go from a given
|
||||
-- vertex to another vertex and back (Definition of a
|
||||
-- cycle) . Of course the Reduced Graph (or Condensed
|
||||
-- Graph) is a DAG (Directed Acyclic Graph).
|
||||
--
|
||||
-- After initialisation conditions (methods FromXXX) the
|
||||
-- user has to build the reduced graph using the method
|
||||
-- Perfrom. So each vertex of the underlying graph will
|
||||
-- be encapsulated in a strong component (class SC of the
|
||||
-- package). The algorithm may be reused using the
|
||||
-- method Reset.
|
||||
--
|
||||
-- nested iterators and methods provides services to
|
||||
-- visit the reduced graph:
|
||||
--
|
||||
-- * class SortedSCIterator defines an iterator to visit
|
||||
-- each strong component. This visit is done according
|
||||
-- to topologiacl sort of the reduced graph (which is a
|
||||
-- DAG).
|
||||
--
|
||||
-- * class AdjSCIterator defines an iterator to visit
|
||||
-- each adjacent StrongComponent of a given one.
|
||||
--
|
||||
-- * The methods NbVertices and GetVertex of the reduced
|
||||
-- graph returned the number and each vertex member of a
|
||||
-- strong component. The method GetSC returned for a
|
||||
-- given vertex its strong component.e
|
||||
--
|
||||
-- Warning: Noone method may be used on SC class. This class is only
|
||||
-- here to identify a StrongComponent.
|
||||
|
||||
uses SC from GraphTools,
|
||||
SCList from GraphTools,
|
||||
ListIteratorOfSCList from GraphTools,
|
||||
StackOfInteger from TColStd
|
||||
|
||||
raises NoSuchObject from Standard,
|
||||
NoMoreObject from Standard,
|
||||
OutOfRange from Standard
|
||||
|
||||
private class RGMap instantiates IndexedDataMap from TCollection
|
||||
(Vertex,
|
||||
RGNode from GraphTools,
|
||||
VHasher);
|
||||
|
||||
class SortedSCIterator from GraphTools
|
||||
|
||||
uses SC from GraphTools,
|
||||
ListIteratorOfSCList from GraphTools
|
||||
|
||||
raises NoMoreObject from Standard,
|
||||
NoSuchObject from Standard
|
||||
|
||||
is
|
||||
|
||||
Create returns SortedSCIterator from GraphTools;
|
||||
|
||||
Create (RG : ReducedGraph from GraphTools)
|
||||
returns SortedSCIterator from GraphTools;
|
||||
|
||||
Initialize (me : in out; RG : ReducedGraph from GraphTools);
|
||||
---Level: Public
|
||||
|
||||
More (me) returns Boolean from Standard;
|
||||
---Purpose: Returns True if there are others Strong
|
||||
-- Components.
|
||||
---Level: Public
|
||||
|
||||
Next (me : in out)
|
||||
raises NoMoreObject from Standard;
|
||||
---Level: Public
|
||||
|
||||
Value (me) returns SC from GraphTools
|
||||
raises NoSuchObject from Standard;
|
||||
---Level: Public
|
||||
|
||||
fields
|
||||
|
||||
myIterator : ListIteratorOfSCList;
|
||||
|
||||
end SortedSCIterator;
|
||||
|
||||
|
||||
class AdjSCIterator from GraphTools
|
||||
|
||||
uses SC from GraphTools,
|
||||
ListIteratorOfSCList from GraphTools
|
||||
|
||||
raises NoMoreObject from Standard,
|
||||
NoSuchObject from Standard,
|
||||
OutOfRange from Standard
|
||||
|
||||
is
|
||||
|
||||
Create returns AdjSCIterator from GraphTools;
|
||||
|
||||
Create (RG : ReducedGraph from GraphTools;
|
||||
SC : SC from GraphTools)
|
||||
returns AdjSCIterator from GraphTools;
|
||||
|
||||
Initialize (me : in out; RG : ReducedGraph from GraphTools;
|
||||
SC : SC from GraphTools);
|
||||
---Level: Public
|
||||
|
||||
More (me) returns Boolean from Standard;
|
||||
---Level: Public
|
||||
|
||||
Next (me : in out)
|
||||
raises NoMoreObject from Standard;
|
||||
---Level: Public
|
||||
|
||||
Value (me) returns SC from GraphTools
|
||||
---Level: Public
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
fields
|
||||
|
||||
myIterator : ListIteratorOfSCList;
|
||||
|
||||
end AdjSCIterator;
|
||||
|
||||
is
|
||||
|
||||
Create
|
||||
---Purpose: Create an empty algorithm
|
||||
returns ReducedGraph from GraphTools;
|
||||
|
||||
|
||||
Create (G : Graph)
|
||||
---Purpose: Create the algorithm, set each vertex of <G>
|
||||
-- reached by GIterator, as research conditions, and
|
||||
-- perform the algorithm. User may directly visit
|
||||
-- (nested class xxxIterator) the result of the
|
||||
-- algorithm.
|
||||
returns ReducedGraph from GraphTools;
|
||||
|
||||
FromGraph (me : in out; G : Graph);
|
||||
---Purpose: Add each vertex of <G> reached by GIterator tool
|
||||
-- as research conditions. User must used Perform
|
||||
-- method before visiting the result of the algorithm.
|
||||
---Level: Public
|
||||
|
||||
FromVertex (me : in out; V : Vertex);
|
||||
---Purpose: Add <V> as research condition. This method is
|
||||
-- cumulative. User must used Perform method before
|
||||
-- visting the result of the algorithm.
|
||||
---Level: Public
|
||||
|
||||
Perform (me : in out; G : Graph);
|
||||
---Purpose: Perform the algorithm IN <G> FROM previous
|
||||
-- initialisation condition(s).
|
||||
---Level: Public
|
||||
|
||||
Reset (me : in out);
|
||||
---Purpose: Clear initialisation conditions. The algorithm may
|
||||
-- be initialized and performed again from new
|
||||
-- conditions. In that case new nested SCIterator and
|
||||
-- AdjSCIterator may be reinitialized.
|
||||
---Level: Public
|
||||
|
||||
IsRoot (me; SC : SC from GraphTools)
|
||||
returns Boolean from Standard;
|
||||
---Level: Public
|
||||
|
||||
IsLeaf (me; SC : SC from GraphTools)
|
||||
returns Boolean from Standard;
|
||||
---Level: Public
|
||||
|
||||
NbVertices (me; SC : SC from GraphTools)
|
||||
---Purpose: returns number of vertices, members of <me>.
|
||||
---Level: Public
|
||||
returns Integer from Standard;
|
||||
|
||||
GetVertex (me; SC : SC from GraphTools;
|
||||
index : Integer from Standard)
|
||||
returns any Vertex
|
||||
---C++: return const&
|
||||
---Level: Public
|
||||
raises OutOfRange from Standard;
|
||||
|
||||
GetSC (me; V : Vertex)
|
||||
---Purpose: Returns the SC which contains <V>.
|
||||
---Level: Public
|
||||
returns SC from GraphTools;
|
||||
|
||||
Visit (me : in out; k : Integer from Standard;
|
||||
G : Graph)
|
||||
---Level: Public
|
||||
returns Integer from Standard
|
||||
is private;
|
||||
|
||||
fields
|
||||
|
||||
-- conditions
|
||||
myVertices : RGMap from GraphTools;
|
||||
-- algorithm
|
||||
performed : Boolean from Standard;
|
||||
myNowIndex : Integer from Standard;
|
||||
myStack : StackOfInteger from TColStd;
|
||||
-- result
|
||||
mySort : SCList from GraphTools;
|
||||
|
||||
friends
|
||||
|
||||
class SortedSCIterator from GraphTools
|
||||
|
||||
end ReducedGraph;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
249
src/GraphTools/GraphTools_ReducedGraph.gxx
Executable file
249
src/GraphTools/GraphTools_ReducedGraph.gxx
Executable file
@@ -0,0 +1,249 @@
|
||||
// Copyright: Matra-Datavision 1991
|
||||
// File: GraphTools_ReducedGraph.cxx
|
||||
// Created: Wed Oct 23 16:28:16 1991
|
||||
// Author: Denis PASCAL
|
||||
// <dp>
|
||||
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <GraphTools_RGNode.hxx>
|
||||
#include <GraphTools_ListIteratorOfSCList.hxx>
|
||||
|
||||
static Standard_Boolean ContainsBack (const Handle(GraphTools_SC)& SC1,
|
||||
const Handle(GraphTools_SC)& SC2)
|
||||
{
|
||||
GraphTools_ListIteratorOfSCList it (SC1->GetBackSC());
|
||||
for (;it.More();it.Next()) {
|
||||
if (it.Value() == SC2) return Standard_True;
|
||||
}
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
static Standard_Boolean ContainsFront (const Handle(GraphTools_SC)& SC1,
|
||||
const Handle(GraphTools_SC)& SC2)
|
||||
{
|
||||
GraphTools_ListIteratorOfSCList it (SC1->GetFrontSC());
|
||||
for (;it.More();it.Next()) {
|
||||
if (it.Value() == SC2) return Standard_True;
|
||||
}
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GraphTools_ReducedGraph
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
GraphTools_ReducedGraph::GraphTools_ReducedGraph ()
|
||||
{
|
||||
performed = Standard_False;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : GraphTools_ReducedGraph
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
GraphTools_ReducedGraph::GraphTools_ReducedGraph
|
||||
(const Graph& G)
|
||||
{
|
||||
FromGraph(G);
|
||||
Perform(G);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : FromGraph
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_ReducedGraph::FromGraph (const Graph& G)
|
||||
{
|
||||
performed = Standard_False;
|
||||
for (GIterator itG (G); itG.More(); itG.Next() ) {
|
||||
GraphTools_RGNode newnode;
|
||||
myVertices.Add (itG.Value(),newnode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : FromVertex
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_ReducedGraph::FromVertex (const Vertex& V)
|
||||
{
|
||||
performed = Standard_False;
|
||||
GraphTools_RGNode newnode;
|
||||
myVertices.Add(V,newnode);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Perform
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_ReducedGraph::Perform (const Graph& G)
|
||||
{
|
||||
performed = Standard_True;
|
||||
myNowIndex = 0;
|
||||
myStack.Clear();
|
||||
mySort.Clear();
|
||||
Standard_Integer visited;
|
||||
Standard_Integer index = 1;
|
||||
while (index <= myVertices.Extent()) {
|
||||
visited = myVertices(index).GetVisited();
|
||||
if (visited == 0) Visit(index,G);
|
||||
index++;
|
||||
}
|
||||
// front and back strong components of a given one : Update
|
||||
Standard_Integer curV,nbV,adjV,nbadjV;
|
||||
Handle(GraphTools_SC) curSC,adjSC;
|
||||
GraphTools_ListIteratorOfSCList it;
|
||||
for (it.Initialize(mySort); it.More(); it.Next()) {
|
||||
curSC = it.Value();
|
||||
nbV = curSC->NbVertices();
|
||||
for (Standard_Integer j = 1; j <= nbV; j++) {
|
||||
curV = curSC->GetVertex(j);
|
||||
nbadjV = myVertices(curV).NbAdj();
|
||||
for (Standard_Integer k = 1; k <= nbadjV; k++) {
|
||||
adjV = myVertices(curV).GetAdj(k);
|
||||
adjSC = myVertices(adjV).GetSC();
|
||||
if (adjSC != curSC) {
|
||||
if (!ContainsFront(curSC,adjSC)) curSC->AddFrontSC (adjSC);
|
||||
if (!ContainsBack(adjSC,curSC)) adjSC->AddBackSC (curSC);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Reset
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_ReducedGraph::Reset ()
|
||||
{
|
||||
performed = Standard_False;
|
||||
myVertices.Clear();
|
||||
myNowIndex = 0;
|
||||
myStack.Clear();
|
||||
mySort.Clear();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : IsRoot
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Standard_Boolean GraphTools_ReducedGraph::IsRoot
|
||||
(const Handle(GraphTools_SC)& SC) const
|
||||
{
|
||||
return (SC->GetBackSC().IsEmpty());
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : IsLeaf
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Standard_Boolean GraphTools_ReducedGraph::IsLeaf
|
||||
(const Handle(GraphTools_SC)& SC) const
|
||||
{
|
||||
return (SC->GetFrontSC().IsEmpty());
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : NbVertices
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer GraphTools_ReducedGraph::NbVertices
|
||||
(const Handle(GraphTools_SC)& SC) const
|
||||
{
|
||||
return SC->NbVertices();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : GetVertex
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const Vertex& GraphTools_ReducedGraph::GetVertex
|
||||
(const Handle(GraphTools_SC)& SC,
|
||||
const Standard_Integer index) const
|
||||
{
|
||||
return myVertices.FindKey(SC->GetVertex(index));
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : GetSC
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Handle(GraphTools_SC) GraphTools_ReducedGraph::GetSC
|
||||
(const Vertex& V) const
|
||||
{
|
||||
if (!performed) Standard_DomainError::Raise();
|
||||
return myVertices.FindFromKey(V).GetSC();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Visit
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer GraphTools_ReducedGraph::Visit
|
||||
(const Standard_Integer k, const Graph& G)
|
||||
{
|
||||
Standard_Integer MIN;
|
||||
Standard_Integer M;
|
||||
myNowIndex++;
|
||||
myVertices(k).SetVisited(myNowIndex);
|
||||
MIN = myNowIndex;
|
||||
myStack.Push(k);
|
||||
Standard_Integer currentVisited;
|
||||
currentVisited = myVertices(k).GetVisited();
|
||||
Standard_Integer adjacentIndex;
|
||||
Standard_Integer adjacentVisited;
|
||||
for (VIterator itV (G,myVertices.FindKey(k)); itV.More(); itV.Next()) {
|
||||
adjacentIndex = myVertices.FindIndex(itV.Value());
|
||||
if (adjacentIndex == 0) {
|
||||
GraphTools_RGNode newnode;
|
||||
adjacentIndex = myVertices.Add (itV.Value(),newnode);
|
||||
adjacentVisited = 0;
|
||||
}
|
||||
else adjacentVisited = myVertices(adjacentIndex).GetVisited();
|
||||
myVertices(k).AddAdj(adjacentIndex);
|
||||
if (adjacentVisited == 0) M = Visit (adjacentIndex,G);
|
||||
else M = adjacentVisited;
|
||||
if (M < MIN) MIN = M;
|
||||
}
|
||||
if (MIN == currentVisited) {
|
||||
Handle(GraphTools_SC) SC = new GraphTools_SC();
|
||||
Standard_Boolean more;
|
||||
do {
|
||||
SC->AddVertex(myStack.Top());
|
||||
myVertices(myStack.Top()).SetVisited(IntegerLast());
|
||||
myVertices(myStack.Top()).SetSC(SC);
|
||||
more = myStack.Top() != k;
|
||||
myStack.Pop() ;
|
||||
}
|
||||
while (more);
|
||||
mySort.Prepend(SC);
|
||||
}
|
||||
return MIN;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
58
src/GraphTools/GraphTools_SC.cdl
Executable file
58
src/GraphTools/GraphTools_SC.cdl
Executable file
@@ -0,0 +1,58 @@
|
||||
-- File: GraphTools_SC.cdl
|
||||
-- Created: Thu Sep 30 15:41:02 1993
|
||||
-- Author: Denis PASCAL
|
||||
-- <dp@bravox>
|
||||
---Copyright: Matra Datavision 1993
|
||||
|
||||
|
||||
class SC from GraphTools inherits TShared from MMgt
|
||||
|
||||
---Purpose: This class is used to identify a Strong Component.
|
||||
-- The user has not to used its methods.
|
||||
|
||||
uses SCList from GraphTools,
|
||||
SequenceOfInteger from TColStd
|
||||
|
||||
raises OutOfRange from Standard,
|
||||
NoSuchObject from Standard
|
||||
|
||||
is
|
||||
|
||||
Create returns mutable SC;
|
||||
|
||||
Reset (me : mutable);
|
||||
---Level: Public
|
||||
|
||||
AddVertex (me : mutable; V : Integer from Standard);
|
||||
---Level: Public
|
||||
|
||||
NbVertices (me) returns Integer from Standard;
|
||||
---Level: Public
|
||||
|
||||
GetVertex (me; index: Integer from Standard)
|
||||
---Level: Public
|
||||
returns Integer from Standard;
|
||||
|
||||
AddFrontSC (me : mutable; SC : SC from GraphTools);
|
||||
---Level: Public
|
||||
|
||||
GetFrontSC (me) returns SCList from GraphTools;
|
||||
---Level: Public
|
||||
---C++: return const &
|
||||
|
||||
AddBackSC (me : mutable; SC : SC from GraphTools);
|
||||
---Level: Public
|
||||
|
||||
GetBackSC (me) returns SCList from GraphTools;
|
||||
---Level: Public
|
||||
---C++: return const &
|
||||
|
||||
fields
|
||||
|
||||
myBackSC : SCList from GraphTools;
|
||||
myVertices : SequenceOfInteger from TColStd;
|
||||
myFrontSC : SCList from GraphTools;
|
||||
|
||||
end SC;
|
||||
|
||||
|
106
src/GraphTools/GraphTools_SC.cxx
Executable file
106
src/GraphTools/GraphTools_SC.cxx
Executable file
@@ -0,0 +1,106 @@
|
||||
|
||||
// File: GraphTools_SC.gxx
|
||||
// Created: Thu Sep 30 17:50:19 1993
|
||||
// Author: Denis PASCAL
|
||||
// <dp@bravox>
|
||||
|
||||
#include <GraphTools_SC.ixx>
|
||||
|
||||
//=======================================================================
|
||||
//function : GraphTools_SC
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
GraphTools_SC::GraphTools_SC () {}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Reset
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_SC::Reset()
|
||||
{
|
||||
myBackSC.Clear();
|
||||
myVertices.Clear();
|
||||
myFrontSC.Clear();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : AddVertex
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_SC::AddVertex(const Standard_Integer V)
|
||||
{
|
||||
myVertices.Append (V);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : NbVertices
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer GraphTools_SC::NbVertices() const
|
||||
{
|
||||
return myVertices.Length();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : GetVertex
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer GraphTools_SC::GetVertex
|
||||
(const Standard_Integer index) const
|
||||
{
|
||||
return myVertices(index);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : AddFrontSC
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_SC::AddFrontSC(const Handle(GraphTools_SC)& SC)
|
||||
{
|
||||
myFrontSC.Append(SC);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : GetFrontSC
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const GraphTools_SCList& GraphTools_SC::GetFrontSC() const
|
||||
{
|
||||
return myFrontSC;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : AddBackSC
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_SC::AddBackSC(const Handle(GraphTools_SC)& SC)
|
||||
{
|
||||
myBackSC.Append(SC);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetBackSC
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const GraphTools_SCList& GraphTools_SC::GetBackSC() const
|
||||
{
|
||||
return myBackSC;
|
||||
}
|
||||
|
||||
|
78
src/GraphTools/GraphTools_SortedSCIterator.gxx
Executable file
78
src/GraphTools/GraphTools_SortedSCIterator.gxx
Executable file
@@ -0,0 +1,78 @@
|
||||
// Copyright: Matra-Datavision 1991
|
||||
// File: GraphTools_SortedSCIterator.cxx
|
||||
// Created: Wed Oct 23 16:28:16 1991
|
||||
// Author: Denis PASCAL
|
||||
// <dp>
|
||||
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : GraphTools_SortedSCIterator
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
GraphTools_SortedSCIterator::GraphTools_SortedSCIterator ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : GraphTools_SortedSCIterator
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
GraphTools_SortedSCIterator::GraphTools_SortedSCIterator
|
||||
(const GraphTools_ReducedGraph& RG)
|
||||
{
|
||||
Initialize (RG);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Initialize
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_SortedSCIterator::Initialize
|
||||
(const GraphTools_ReducedGraph& RG)
|
||||
{
|
||||
myIterator.Initialize(RG.mySort);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : More
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean GraphTools_SortedSCIterator::More() const
|
||||
{
|
||||
return myIterator.More();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Next
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_SortedSCIterator::Next()
|
||||
{
|
||||
myIterator.Next();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Value
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(GraphTools_SC) GraphTools_SortedSCIterator::Value () const
|
||||
{
|
||||
return myIterator.Value();
|
||||
}
|
||||
|
||||
|
||||
|
120
src/GraphTools/GraphTools_SortedStrgCmptsFromIterator.cdl
Executable file
120
src/GraphTools/GraphTools_SortedStrgCmptsFromIterator.cdl
Executable file
@@ -0,0 +1,120 @@
|
||||
-- File: GraphTools_SortedStrgCmptsFromIterator.cdl
|
||||
-- Created: Wed Oct 23 12:07:20 1991
|
||||
-- Author: Denis PASCAL
|
||||
-- <dp@topsn2>
|
||||
---Copyright: Matra Datavision 1991, 1992
|
||||
|
||||
|
||||
generic class SortedStrgCmptsFromIterator from GraphTools
|
||||
(Graph as any;
|
||||
Vertex as any;
|
||||
VHasher as any;
|
||||
VIterator as any)
|
||||
|
||||
---Purposes: This generic class implements the Strong Components
|
||||
-- Research algorithm from a set of vertices. An
|
||||
-- iterator on adjacent vertices of a given one, are
|
||||
-- requested. Each Strong Component encapsulates
|
||||
-- vertices which are part of a cycle, in the underlying
|
||||
-- graph. The interface of this algorithm is made as an
|
||||
-- iterator. A each step it is possible to know the
|
||||
-- number of vertices, which are members of the current
|
||||
-- Strong Components, and to visit each one. Strong
|
||||
-- Components are visited in such an order than noone is
|
||||
-- returned before an other which point to it.
|
||||
|
||||
|
||||
uses StackOfInteger from TColStd,
|
||||
ListOfSequenceOfInteger from GraphTools,
|
||||
ListIteratorOfListOfSequenceOfInteger from GraphTools
|
||||
|
||||
raises NoMoreObject from Standard,
|
||||
NoSuchObject from Standard,
|
||||
DomainError from Standard
|
||||
|
||||
|
||||
private class SCMap instantiates IndexedDataMap from TCollection
|
||||
(Vertex,Integer,VHasher);
|
||||
|
||||
is
|
||||
|
||||
Create
|
||||
---Purpose: Create an empty algorithm.
|
||||
returns SortedStrgCmptsFromIterator from GraphTools;
|
||||
|
||||
FromVertex (me : in out; V : Vertex)
|
||||
---Purpose: Add <V> as initial condition. This method is
|
||||
-- cumulative. Use Perform method before visting the
|
||||
-- result of the algorithm.
|
||||
---Level: Public
|
||||
raises DomainError from Standard;
|
||||
|
||||
Reset (me : in out);
|
||||
---Purpose: Reset the algorithm. It may be reused with new
|
||||
-- conditions.
|
||||
---Level: Public
|
||||
|
||||
Perform (me : in out; G : Graph);
|
||||
---Purpose: Peform the algorithm in <G> from initial setted
|
||||
-- conditions.
|
||||
---Level: Public
|
||||
|
||||
More(me)
|
||||
returns Boolean from Standard;
|
||||
---Purpose: returns True if there are others strong
|
||||
-- components.
|
||||
---Level: Public
|
||||
|
||||
Next(me : in out)
|
||||
---Purpose: Set the iterator to the next strong component.
|
||||
---Level: Public
|
||||
raises NoMoreObject from Standard;
|
||||
|
||||
NbVertices (me)
|
||||
returns Integer from Standard
|
||||
---Purpose: Returns number of vertices of the current Strong
|
||||
-- Components.
|
||||
---Level: Public
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
Value(me; index : Integer from Standard)
|
||||
returns any Vertex
|
||||
---Purpose: returns the vertex of index <I> of the current
|
||||
-- Strong Component.
|
||||
---Level: Public
|
||||
---C++: return const &
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
Visit (me : in out; k : Integer from Standard;
|
||||
G : Graph)
|
||||
---Level: Internal
|
||||
returns Integer from Standard;
|
||||
|
||||
fields
|
||||
|
||||
-- conditions
|
||||
myVertices : SCMap from GraphTools;
|
||||
-- algorithm
|
||||
myNowIndex : Integer from Standard;
|
||||
myStack : StackOfInteger from TColStd;
|
||||
-- result
|
||||
mySort : ListOfSequenceOfInteger from GraphTools;
|
||||
myIterator : ListIteratorOfListOfSequenceOfInteger from GraphTools;
|
||||
|
||||
end SortedStrgCmptsFromIterator;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
188
src/GraphTools/GraphTools_SortedStrgCmptsFromIterator.gxx
Executable file
188
src/GraphTools/GraphTools_SortedStrgCmptsFromIterator.gxx
Executable file
@@ -0,0 +1,188 @@
|
||||
// Copyright: Matra-Datavision 1991
|
||||
// File: GraphTools_SortedStrgCmptsFromIterator.gxx
|
||||
// Created: Wed Oct 23 16:28:16 1991
|
||||
// Author: Denis PASCAL
|
||||
// <dp>
|
||||
|
||||
#include <Standard_DomainError.hxx>
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <TColStd_SequenceOfInteger.hxx>
|
||||
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : GraphTools_SortedStrgCmptsFromIterator
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
GraphTools_SortedStrgCmptsFromIterator::
|
||||
GraphTools_SortedStrgCmptsFromIterator ()
|
||||
{
|
||||
myNowIndex = 0;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : FromVertex
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_SortedStrgCmptsFromIterator::FromVertex (const Vertex& V)
|
||||
{
|
||||
#ifdef DEB
|
||||
Standard_Integer index =
|
||||
#endif
|
||||
myVertices.Add (V,0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Perform
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_SortedStrgCmptsFromIterator::Perform (const Graph& G)
|
||||
{
|
||||
myNowIndex = 0;
|
||||
mySort.Clear();
|
||||
Standard_Integer visited;
|
||||
Standard_Integer temp;
|
||||
Standard_Integer index = 1;
|
||||
while (index <= myVertices.Extent()) {
|
||||
visited = myVertices.FindFromIndex(index);
|
||||
if (visited == 0) temp = Visit(index,G);
|
||||
index ++;
|
||||
}
|
||||
myIterator.Initialize(mySort);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Reset
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_SortedStrgCmptsFromIterator::Reset ()
|
||||
{
|
||||
myVertices.Clear();
|
||||
myNowIndex = 0;
|
||||
myStack.Clear();
|
||||
mySort.Clear();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : More
|
||||
//purpose : declenche l'algorithme de recherche des Strong Components
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean GraphTools_SortedStrgCmptsFromIterator::More() const
|
||||
{
|
||||
return myIterator.More();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Next
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_SortedStrgCmptsFromIterator::Next()
|
||||
{
|
||||
myIterator.Next();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : NbVertices
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer GraphTools_SortedStrgCmptsFromIterator::NbVertices() const
|
||||
{
|
||||
return myIterator.Value().Length();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Value
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const Vertex& GraphTools_SortedStrgCmptsFromIterator::Value
|
||||
(const Standard_Integer I) const
|
||||
{
|
||||
Standard_Integer indexvertex = myIterator.Value().Value(I);
|
||||
return myVertices.FindKey (indexvertex);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Visit
|
||||
//purpose : private
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer GraphTools_SortedStrgCmptsFromIterator::Visit
|
||||
(const Standard_Integer k, const Graph& G)
|
||||
{
|
||||
Standard_Integer MIN;
|
||||
Standard_Integer M;
|
||||
myNowIndex++;
|
||||
myVertices(k) = myNowIndex;
|
||||
MIN = myNowIndex;
|
||||
myStack.Push(k);
|
||||
Standard_Integer currentVisited;
|
||||
currentVisited = myVertices.FindFromIndex (k);
|
||||
Standard_Integer adjacentIndex;
|
||||
Standard_Integer adjacentVisited;
|
||||
for (VIterator itV (G,myVertices.FindKey(k)); itV.More(); itV.Next()) {
|
||||
adjacentIndex = myVertices.FindIndex(itV.Value());
|
||||
if (adjacentIndex == 0) {
|
||||
adjacentIndex = myVertices.Add (itV.Value(),0);
|
||||
adjacentVisited = 0;
|
||||
}
|
||||
else adjacentVisited = myVertices.FindFromIndex (adjacentIndex);
|
||||
if (adjacentVisited == 0) M = Visit(adjacentIndex,G);
|
||||
else M = adjacentVisited;
|
||||
if (M < MIN) MIN = M;
|
||||
}
|
||||
if (MIN == currentVisited) {
|
||||
TColStd_SequenceOfInteger theSequence;
|
||||
mySort.Prepend(theSequence);
|
||||
TColStd_SequenceOfInteger& newSC = mySort.First();
|
||||
Standard_Boolean more;
|
||||
do {
|
||||
newSC.Append(myStack.Top());
|
||||
myVertices(myStack.Top()) = IntegerLast();
|
||||
more = myStack.Top() != k;
|
||||
myStack.Pop() ;
|
||||
}
|
||||
while (more);
|
||||
}
|
||||
return MIN;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
107
src/GraphTools/GraphTools_SortedStrgCmptsIterator.cdl
Executable file
107
src/GraphTools/GraphTools_SortedStrgCmptsIterator.cdl
Executable file
@@ -0,0 +1,107 @@
|
||||
-- File: GraphTools_SortedStrgCmptsIterator.cdl
|
||||
-- Created: Wed Oct 23 12:07:20 1991
|
||||
-- Author: Denis PASCAL
|
||||
-- <dp@topsn2>
|
||||
---Copyright: Matra Datavision 1991, 1992
|
||||
|
||||
generic class SortedStrgCmptsIterator from GraphTools
|
||||
(Graph as any;
|
||||
Vertex as any;
|
||||
GIterator as any;
|
||||
SSCIterator as any)
|
||||
|
||||
--generic class SortedStrgCmptsIterator from GraphTools
|
||||
-- (Graph as any;
|
||||
-- Vertex as any;
|
||||
-- GIterator as GraphIterator (Graph,Vertex))
|
||||
-- SSCIterator as SortedStrgCmptsFromIterator
|
||||
|
||||
---Purposes: This generic class implements the
|
||||
-- SortedStrgCptsFromIterator with all vertices of <G>
|
||||
-- reached by the Tool GIterator.
|
||||
|
||||
raises NoMoreObject from Standard,
|
||||
NoSuchObject from Standard
|
||||
|
||||
is
|
||||
|
||||
|
||||
Create
|
||||
returns SortedStrgCmptsIterator from GraphTools;
|
||||
---Purpose: Create an empty algorithm.
|
||||
|
||||
Create (G : Graph)
|
||||
---Purpose: Create the algorithm setting each vertex of <G>
|
||||
-- reached by GIterator tool, as initial conditions.
|
||||
-- Use Perform method before visting the result of
|
||||
-- the algorithm.
|
||||
returns SortedStrgCmptsIterator from GraphTools;
|
||||
|
||||
FromGraph (me : in out; G : Graph);
|
||||
---Purpose: Add each vertex of <G> reached by GIterator tool
|
||||
-- as initial conditions. Use Perform method
|
||||
-- before visiting the result of the algorithm.
|
||||
---Level: Public
|
||||
|
||||
FromVertex (me : in out; V : Vertex);
|
||||
---Purpose: Add <V> as initial condition. This method is
|
||||
-- cumulative. Use Perform method before visting the
|
||||
-- result of the algorithm.
|
||||
---Level: Public
|
||||
|
||||
Reset (me : in out);
|
||||
---Purpose: Reset the algorithm. It may be reused with new
|
||||
-- initial conditions.
|
||||
---Level: Public
|
||||
|
||||
Perform (me : in out; G : Graph);
|
||||
---Purpose: Peform the algorithm in <G> from initial setted
|
||||
-- conditions.
|
||||
---Level: Public
|
||||
|
||||
More(me) returns Boolean from Standard;
|
||||
---Purpose: returns True if there are others strong
|
||||
-- components.
|
||||
---Level: Public
|
||||
|
||||
Next(me : in out)
|
||||
---Purpose: Set the iterator to the next strong component.
|
||||
---Level: Public
|
||||
raises NoMoreObject from Standard;
|
||||
|
||||
NbVertices (me) returns Integer from Standard
|
||||
---Purpose: Returns number of vertices of the current Strong
|
||||
-- Components.
|
||||
---Level: Public
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
Value(me; I : Integer from Standard)
|
||||
returns any Vertex
|
||||
---Purpose: returns the vertex of index <I> of the current
|
||||
-- Strong Component.
|
||||
---C++: return const &
|
||||
---Level: Public
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
fields
|
||||
|
||||
myIterator : SSCIterator;
|
||||
|
||||
end SortedStrgCmptsIterator;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
128
src/GraphTools/GraphTools_SortedStrgCmptsIterator.gxx
Executable file
128
src/GraphTools/GraphTools_SortedStrgCmptsIterator.gxx
Executable file
@@ -0,0 +1,128 @@
|
||||
// Copyright: Matra-Datavision 1991
|
||||
// File: GraphTools_SortedStrgCmptsIterator.cxx
|
||||
// Created: Wed Oct 23 16:28:16 1991
|
||||
// Author: Denis PASCAL
|
||||
// <dp>
|
||||
|
||||
//=======================================================================
|
||||
//function : GraphTools_SortedStrgCmptsIterator
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
GraphTools_SortedStrgCmptsIterator::GraphTools_SortedStrgCmptsIterator ()
|
||||
{}
|
||||
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : GraphTools_SortedStrgCmptsIterator
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
GraphTools_SortedStrgCmptsIterator::GraphTools_SortedStrgCmptsIterator
|
||||
(const Graph& G)
|
||||
{
|
||||
FromGraph(G);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : FromVertex
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_SortedStrgCmptsIterator::FromVertex
|
||||
(const Vertex& V)
|
||||
{
|
||||
myIterator.FromVertex(V);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : FromGraph
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_SortedStrgCmptsIterator::FromGraph
|
||||
(const Graph& G)
|
||||
{
|
||||
for ( GIterator it (G); it.More(); it.Next() ) {
|
||||
myIterator.FromVertex(it.Value());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Perform
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_SortedStrgCmptsIterator::Perform
|
||||
(const Graph& G)
|
||||
{
|
||||
myIterator.Perform(G);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Reset
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_SortedStrgCmptsIterator::Reset ()
|
||||
{
|
||||
myIterator.Reset();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : More
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean GraphTools_SortedStrgCmptsIterator::More() const
|
||||
{
|
||||
return myIterator.More();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Next
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_SortedStrgCmptsIterator::Next()
|
||||
{
|
||||
myIterator.Next();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : NbVertices
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer GraphTools_SortedStrgCmptsIterator::NbVertices() const
|
||||
{
|
||||
return myIterator.NbVertices();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Value
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const Vertex& GraphTools_SortedStrgCmptsIterator::Value
|
||||
(const Standard_Integer I) const
|
||||
{
|
||||
return myIterator.Value(I);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
40
src/GraphTools/GraphTools_TSNode.cdl
Executable file
40
src/GraphTools/GraphTools_TSNode.cdl
Executable file
@@ -0,0 +1,40 @@
|
||||
-- File: GraphTools_TSNode.cdl
|
||||
-- Created: Tue Sep 28 17:02:15 1993
|
||||
-- Author: Denis PASCAL
|
||||
-- <dp@bravox>
|
||||
---Copyright: Matra Datavision 1993
|
||||
|
||||
|
||||
class TSNode from GraphTools
|
||||
|
||||
uses SequenceOfInteger from TColStd
|
||||
|
||||
is
|
||||
|
||||
Create returns TSNode from GraphTools;
|
||||
|
||||
Reset (me : in out);
|
||||
|
||||
IncreaseRef (me : in out);
|
||||
|
||||
DecreaseRef (me : in out);
|
||||
|
||||
NbRef (me) returns Integer from Standard;
|
||||
|
||||
AddSuccessor (me : in out; s : Integer from Standard);
|
||||
|
||||
NbSuccessors (me) returns Integer from Standard;
|
||||
|
||||
GetSuccessor (me; index : Integer from Standard)
|
||||
returns Integer from Standard;
|
||||
|
||||
fields
|
||||
|
||||
referenceCount : Integer from Standard;
|
||||
mySuccessors : SequenceOfInteger from TColStd;
|
||||
|
||||
end TSNode;
|
||||
|
||||
|
||||
|
||||
|
93
src/GraphTools/GraphTools_TSNode.cxx
Executable file
93
src/GraphTools/GraphTools_TSNode.cxx
Executable file
@@ -0,0 +1,93 @@
|
||||
|
||||
// Copyright: Matra-Datavision 1991
|
||||
// File: GraphTools_TSNode.cxx
|
||||
// Created: Thu Jun 20 15:46:35 1991
|
||||
// Author: Denis PASCAL
|
||||
// <dp>
|
||||
|
||||
#include <GraphTools_TSNode.ixx>
|
||||
|
||||
//=======================================================================
|
||||
//function : GraphTools_TSNode
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
GraphTools_TSNode::GraphTools_TSNode ()
|
||||
{
|
||||
referenceCount = 0;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Reset
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_TSNode::Reset ()
|
||||
{
|
||||
referenceCount = 0;
|
||||
mySuccessors.Clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : IncreaseRef
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_TSNode::IncreaseRef() { referenceCount++; }
|
||||
|
||||
//=======================================================================
|
||||
//function : DecreaseRef
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_TSNode::DecreaseRef() { referenceCount--; }
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : NbRef
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer GraphTools_TSNode::NbRef() const
|
||||
{
|
||||
return referenceCount;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : AddSuccessor
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_TSNode::AddSuccessor(const Standard_Integer s)
|
||||
{
|
||||
mySuccessors.Append(s);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : NbSuccessors
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer GraphTools_TSNode::NbSuccessors() const
|
||||
{
|
||||
return mySuccessors.Length();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetSuccessor
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer GraphTools_TSNode::GetSuccessor
|
||||
(const Standard_Integer index) const
|
||||
{
|
||||
return mySuccessors(index);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
105
src/GraphTools/GraphTools_TopologicalSortFromIterator.cdl
Executable file
105
src/GraphTools/GraphTools_TopologicalSortFromIterator.cdl
Executable file
@@ -0,0 +1,105 @@
|
||||
-- File: GraphTools_TopologicalSortFromIterator.cdl
|
||||
-- Created: Thu Dec 24 14:07:47 1992
|
||||
-- Author: Denis PASCAL
|
||||
-- <dp@bravox>
|
||||
---Copyright: Matra Datavision 1992
|
||||
|
||||
|
||||
generic class TopologicalSortFromIterator from GraphTools
|
||||
(Graph as any;
|
||||
Vertex as any;
|
||||
VHasher as any;
|
||||
VIterator as any)
|
||||
|
||||
--generic class TopologicalSortFromIterator from GraphTools
|
||||
-- (Graph as any;
|
||||
-- Vertex as any;
|
||||
-- VHasher as MapHasher from TCollection (Vertex);
|
||||
-- VIterator as VertexIterator (Graph,Vertex))
|
||||
|
||||
---Purpose: This generic class defines an iterator to visit
|
||||
-- each vertex of the underlying graph, in such an
|
||||
-- order that noone vertex is reach before any vertex
|
||||
-- that point to it. In general the order produced by
|
||||
-- topological sort is not unique. Usefull for DAG
|
||||
-- Topological Sort. The option <ignoreSelfLoop>
|
||||
-- allows the user to ignore (or not) any vertex wich
|
||||
-- contains a self loop. The option <processCycle>
|
||||
-- allows the user to visit (or not> vertices which
|
||||
-- are in a cycle.
|
||||
|
||||
|
||||
uses SequenceOfInteger from TColStd
|
||||
|
||||
raises NoSuchObject from Standard,
|
||||
NoMoreObject from Standard,
|
||||
DomainError from Standard
|
||||
|
||||
private class TSMap instantiates IndexedDataMap from TCollection
|
||||
(Vertex,TSNode from GraphTools,VHasher);
|
||||
|
||||
is
|
||||
|
||||
Create
|
||||
---Purpose: Create an empty algorithm.
|
||||
returns TopologicalSortFromIterator from GraphTools;
|
||||
|
||||
FromVertex (me : in out; V : Vertex);
|
||||
---Purpose: Add <V> as initial condition. This method is
|
||||
-- cumulative. Use Perform method before visting the
|
||||
-- result of the algorithm.
|
||||
---Level: Public
|
||||
|
||||
Reset (me : in out);
|
||||
---Purpose: Reset the algorithm. It may be reused with new
|
||||
-- initial conditions.
|
||||
---Level: Public
|
||||
|
||||
Perform (me : in out; G : Graph;
|
||||
ignoreSelfLoop : Boolean from Standard;
|
||||
processCycle : Boolean from Standard);
|
||||
---Purpose: Peform the algorithm in <G> from initial setted
|
||||
-- conditions according to the two following flags.
|
||||
-- * <ignoreSelfLoop> allows the user to ignore (or
|
||||
-- not) any vertex wich contains a self loop.
|
||||
-- * <processCycle> allows the user to visit (or not>
|
||||
-- vertex which is in a cycle.
|
||||
---Level: Public
|
||||
|
||||
More (me)
|
||||
returns Boolean from Standard;
|
||||
---Level: Public
|
||||
|
||||
Next (me : in out)
|
||||
raises NoMoreObject from Standard;
|
||||
---Level: Public
|
||||
|
||||
Value (me)
|
||||
returns any Vertex
|
||||
---Level: Public
|
||||
---C++: return const &
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
IsInCycle (me)
|
||||
returns Boolean from Standard
|
||||
---Purpose: Returns TRUE if the current vertex is in a cycle.
|
||||
---Level: Public
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
|
||||
fields
|
||||
|
||||
-- conditions
|
||||
myVertices : TSMap from GraphTools;
|
||||
myIgnoreSelfLoop : Boolean from Standard;
|
||||
myProcessCycle : Boolean from Standard;
|
||||
-- result
|
||||
mySort : SequenceOfInteger from TColStd;
|
||||
myCycles : Integer from Standard;
|
||||
myCurrent : Integer from Standard;
|
||||
|
||||
end TopologicalSortFromIterator;
|
||||
|
||||
|
||||
|
||||
|
213
src/GraphTools/GraphTools_TopologicalSortFromIterator.gxx
Executable file
213
src/GraphTools/GraphTools_TopologicalSortFromIterator.gxx
Executable file
@@ -0,0 +1,213 @@
|
||||
// Copyright: Matra-Datavision 1991
|
||||
// File: GraphTools_TopologicalSortFromIterator.gxx
|
||||
// Created: Wed May 29 17:42:50 1991
|
||||
// Author: Denis PASCAL
|
||||
// <dp>
|
||||
|
||||
#include <Standard_NoMoreObject.hxx>
|
||||
#include <Standard_NoSuchObject.hxx>
|
||||
#include <Standard_DomainError.hxx>
|
||||
#include <TColStd_QueueOfInteger.hxx>
|
||||
#include <GraphTools_TSNode.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : GraphTools_TopologicalSortFromIterator
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
GraphTools_TopologicalSortFromIterator::GraphTools_TopologicalSortFromIterator () {}
|
||||
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : FromVertex
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_TopologicalSortFromIterator::FromVertex (const Vertex& V)
|
||||
{
|
||||
GraphTools_TSNode newnode;
|
||||
myVertices.Add(V,newnode);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Perform
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_TopologicalSortFromIterator::Perform
|
||||
(const Graph& G,
|
||||
const Standard_Boolean ignoreSelfLoop,
|
||||
const Standard_Boolean processCycle)
|
||||
{
|
||||
myIgnoreSelfLoop = ignoreSelfLoop;
|
||||
myProcessCycle = processCycle;
|
||||
myCurrent = 1;
|
||||
mySort.Clear();
|
||||
// algorithm DS
|
||||
Standard_Integer i, indexcurrent, indexadjacent, nbadjacent;
|
||||
indexcurrent = 1;
|
||||
while (indexcurrent <= myVertices.Extent()) {
|
||||
VIterator itV (G,myVertices.FindKey(indexcurrent));
|
||||
for ( ; itV.More(); itV.Next()) {
|
||||
indexadjacent = myVertices.FindIndex(itV.Value());
|
||||
if (indexadjacent == 0) {
|
||||
GraphTools_TSNode newnode;
|
||||
indexadjacent = myVertices.Add(itV.Value(),newnode);
|
||||
}
|
||||
if (! (indexcurrent == indexadjacent && myIgnoreSelfLoop)) {
|
||||
myVertices(indexcurrent).AddSuccessor(indexadjacent);
|
||||
myVertices(indexadjacent).IncreaseRef();
|
||||
}
|
||||
}
|
||||
indexcurrent++;
|
||||
}
|
||||
// current root vertices queue
|
||||
TColStd_QueueOfInteger processQueue;
|
||||
Standard_Integer nbVertices = myVertices.Extent();
|
||||
for (i = 1 ; i <= nbVertices; i++) {
|
||||
if (myVertices(i).NbRef() == 0) processQueue.Push(i);
|
||||
}
|
||||
// acyclic processing
|
||||
while (!processQueue.IsEmpty()) {
|
||||
indexcurrent = processQueue.Front();
|
||||
mySort.Append(indexcurrent);
|
||||
nbadjacent = myVertices(indexcurrent).NbSuccessors();
|
||||
for (i = 1; i <= nbadjacent; i++) {
|
||||
indexadjacent = myVertices(indexcurrent).GetSuccessor(i);
|
||||
myVertices(indexadjacent).DecreaseRef();
|
||||
if (myVertices(indexadjacent).NbRef() == 0) {
|
||||
processQueue.Push (indexadjacent);
|
||||
}
|
||||
}
|
||||
processQueue.Pop();
|
||||
}
|
||||
// cyclic processing
|
||||
myCycles = mySort.Length() + 1;
|
||||
if (myProcessCycle) {
|
||||
for (i = 1 ; i <= nbVertices; i++) {
|
||||
if (myVertices(i).NbRef() != 0) mySort.Append(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Reset
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_TopologicalSortFromIterator::Reset ()
|
||||
{
|
||||
myVertices.Clear();
|
||||
// myIgnoreSelfLoop : Boolean from Standard;
|
||||
// myProcessCycle : Boolean from Standard;
|
||||
mySort.Clear();
|
||||
// myCycles : Integer from Standard;
|
||||
myCurrent = 1;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : More
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean GraphTools_TopologicalSortFromIterator::More () const
|
||||
{
|
||||
return myCurrent <= mySort.Length();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Next
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_TopologicalSortFromIterator::Next ()
|
||||
{
|
||||
if (!More()) Standard_NoMoreObject::Raise();
|
||||
myCurrent ++;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Value
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const Vertex& GraphTools_TopologicalSortFromIterator::Value () const {
|
||||
if (!More()) Standard_NoSuchObject::Raise();
|
||||
return myVertices.FindKey (mySort(myCurrent));
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : IsInCycle
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean GraphTools_TopologicalSortFromIterator::IsInCycle () const
|
||||
{
|
||||
if (!More()) Standard_NoSuchObject::Raise();
|
||||
return myCurrent >= myCycles;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
98
src/GraphTools/GraphTools_TopologicalSortIterator.cdl
Executable file
98
src/GraphTools/GraphTools_TopologicalSortIterator.cdl
Executable file
@@ -0,0 +1,98 @@
|
||||
-- File: GraphTools_TopologicalSortIterator.cdl
|
||||
-- Created: Thu Dec 24 14:07:47 1992
|
||||
-- Author: Denis PASCAL
|
||||
-- <dp@bravox>
|
||||
---Copyright: Matra Datavision 1992
|
||||
|
||||
|
||||
generic class TopologicalSortIterator from GraphTools
|
||||
(Graph as any;
|
||||
Vertex as any;
|
||||
GIterator as any;
|
||||
TSIterator as any)
|
||||
|
||||
--generic class TopologicalSorIterator from GraphTools
|
||||
-- (Graph as any;
|
||||
-- Vertex as any;
|
||||
-- GIterator as GraphIterator (Graph,Vertex))
|
||||
-- TSIterator as TopologicalSortFromIterator
|
||||
|
||||
---Purpose: This generic class defines an iterator to visit
|
||||
-- each vertex of the underlying graph, in such an
|
||||
-- order that noone vertex is reach before any vertex
|
||||
-- that point to it. In general the order produced by
|
||||
-- topological sort is not unique. Usefull for DAG
|
||||
-- Topological Sort.
|
||||
|
||||
raises NoSuchObject from Standard,
|
||||
NoMoreObject from Standard
|
||||
|
||||
|
||||
is
|
||||
|
||||
Create
|
||||
---Purpose: Create an empty algorithm.
|
||||
returns TopologicalSortIterator from GraphTools;
|
||||
|
||||
Create (G : Graph)
|
||||
---Purpose: Create the algorithm setting each vertex of <G>
|
||||
-- reached by GIterator tool, as initial conditions.
|
||||
-- Use Perform method before visting the result of
|
||||
-- the algorithm.
|
||||
returns TopologicalSortIterator from GraphTools;
|
||||
|
||||
FromGraph (me : in out; G : Graph);
|
||||
---Purpose: Add each vertex of <G> reached by GIterator tool
|
||||
-- as initial conditions. Use Perform method
|
||||
-- before visiting the result of the algorithm.
|
||||
---Level: Public
|
||||
|
||||
FromVertex (me : in out; V : Vertex);
|
||||
---Purpose: Add <V> as initial condition. This method is
|
||||
-- cumulative. Use Perform method before visting the
|
||||
-- result of the algorithm.
|
||||
---Level: Public
|
||||
|
||||
Reset (me : in out);
|
||||
---Purpose: Reset the algorithm. It may be reused with new
|
||||
-- initial conditions.
|
||||
---Level: Public
|
||||
|
||||
Perform (me : in out; G : Graph ;
|
||||
ignoreSelfLoop : Boolean from Standard;
|
||||
processCycle : Boolean from Standard);
|
||||
---Purpose: Peform the algorithm in <G> from initial setted
|
||||
-- conditions according to the two following flags.
|
||||
-- * <ignoreSelfLoop> allows the user to ignore (or
|
||||
-- not) any vertex wich contains a self loop.
|
||||
-- * <processCycle> allows the user to visit (or not>
|
||||
-- vertex which is in a cycle.
|
||||
---Level: Public
|
||||
|
||||
More (me)
|
||||
returns Boolean from Standard;
|
||||
---Level: Public
|
||||
|
||||
Next (me : in out)
|
||||
raises NoMoreObject from Standard;
|
||||
---Level: Public
|
||||
|
||||
Value (me) returns any Vertex
|
||||
---Level: Public
|
||||
---C++: return const &
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
IsInCycle (me) returns Boolean from Standard
|
||||
---Purpose: Returns TRUE if the current vertex is in a cycle.
|
||||
---Level: Public
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
fields
|
||||
|
||||
myIterator : TSIterator;
|
||||
|
||||
end TopologicalSortIterator;
|
||||
|
||||
|
||||
|
||||
|
142
src/GraphTools/GraphTools_TopologicalSortIterator.gxx
Executable file
142
src/GraphTools/GraphTools_TopologicalSortIterator.gxx
Executable file
@@ -0,0 +1,142 @@
|
||||
// Copyright: Matra-Datavision 1991
|
||||
// File: GraphTools_TopologicalSortIterator.gxx
|
||||
// Created: Wed May 29 17:42:50 1991
|
||||
// Author: Denis PASCAL
|
||||
// <dp>
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : GraphTools_TopologicalSortIterator
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
GraphTools_TopologicalSortIterator::GraphTools_TopologicalSortIterator ()
|
||||
{}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : GraphTools_TopologicalSortIterator
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
GraphTools_TopologicalSortIterator::GraphTools_TopologicalSortIterator
|
||||
(const Graph& G)
|
||||
{
|
||||
FromGraph (G);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : FromVertex
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_TopologicalSortIterator::FromVertex
|
||||
(const Vertex& V)
|
||||
{
|
||||
myIterator.FromVertex(V);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : FromGraph
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_TopologicalSortIterator::FromGraph
|
||||
(const Graph& G)
|
||||
{
|
||||
for ( GIterator it (G); it.More(); it.Next() ) {
|
||||
myIterator.FromVertex(it.Value());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Perform
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_TopologicalSortIterator::Perform
|
||||
(const Graph& G,
|
||||
const Standard_Boolean ignoreSelfLoops,
|
||||
const Standard_Boolean processCycle)
|
||||
{
|
||||
myIterator.Perform(G,ignoreSelfLoops,processCycle);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Reset
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_TopologicalSortIterator::Reset ()
|
||||
{
|
||||
myIterator.Reset();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : More
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean GraphTools_TopologicalSortIterator::More () const
|
||||
{
|
||||
return myIterator.More();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Next
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void GraphTools_TopologicalSortIterator::Next ()
|
||||
{
|
||||
myIterator.Next();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Value
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const Vertex& GraphTools_TopologicalSortIterator::Value () const
|
||||
{
|
||||
return myIterator.Value();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : IsInCycle
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean GraphTools_TopologicalSortIterator::IsInCycle () const
|
||||
{
|
||||
return myIterator.IsInCycle();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
60
src/GraphTools/GraphTools_VertexIterator.cdl
Executable file
60
src/GraphTools/GraphTools_VertexIterator.cdl
Executable file
@@ -0,0 +1,60 @@
|
||||
-- File: GraphTools_VertexIterator.cdl
|
||||
-- Created: Wed Mar 6 18:20:11 1991
|
||||
-- Author: Denis Pascal
|
||||
-- <dp@topsn3>
|
||||
---Copyright: Matra Datavision 1991, 1992
|
||||
|
||||
|
||||
generic class VertexIterator from GraphTools (Graph as any;
|
||||
Vertex as any)
|
||||
|
||||
--template class VertexIterator from GraphTools (Graph as any,
|
||||
-- Vertex as any)
|
||||
|
||||
---Purpose: Template class which defines Signature of an iterator
|
||||
-- to visit each adjacent vertex of a given one in the
|
||||
-- underlying graph.
|
||||
|
||||
|
||||
raises NoMoreObject from Standard,
|
||||
NoSuchObject from Standard
|
||||
|
||||
is
|
||||
|
||||
Create (G : Graph; V : Vertex) returns VertexIterator;
|
||||
|
||||
More (me) returns Boolean;
|
||||
---Purpose: Returns TRUE if there are other vertices.
|
||||
---Level: Public
|
||||
|
||||
Next(me : in out)
|
||||
--- Purpose : Set the iterator to the next Vertex.
|
||||
---Level: Public
|
||||
raises NoMoreObject from Standard;
|
||||
|
||||
Value(me) returns Vertex
|
||||
--- Purpose: Returns the vertex value for the current position
|
||||
-- of the iterator.
|
||||
---Level: Public
|
||||
raises NoSuchObject from Standard;
|
||||
|
||||
end VertexIterator;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
4
src/GraphTools/GraphTools_VertexIterator.gxx
Executable file
4
src/GraphTools/GraphTools_VertexIterator.gxx
Executable file
@@ -0,0 +1,4 @@
|
||||
// File: GraphTools_VertexIterator.gxx
|
||||
// Created: Mon Sep 27 18:12:07 1993
|
||||
// Author: Denis PASCAL
|
||||
// <dp@bravox>
|
Reference in New Issue
Block a user