6 * $Date: 2012-07-06 11:39:38 +0200 (Fr, 06. Jul 2012) $
7 ***************************************************************/
10 * \brief Offers variety of possible SimDraw creations.
12 * \author Michael Schulz and Daniel Lueckerath
15 * This file is part of the Open Graph Drawing Framework (OGDF).
19 * See README.txt in the root directory of the OGDF installation for details.
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License
24 * Version 2 or 3 as published by the Free Software Foundation;
25 * see the file LICENSE.txt included in the packaging of this file
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public
36 * License along with this program; if not, write to the Free
37 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
38 * Boston, MA 02110-1301, USA.
40 * \see http://www.gnu.org/copyleft/gpl.html
41 ***************************************************************/
43 #include <ogdf/simultaneous/SimDrawCreator.h>
44 #include <ogdf/basic/graph_generators.h>
48 //*************************************************************
49 //sets all edgeSubGraph values to zero
51 void SimDrawCreator::clearESG()
55 m_GA
->subGraphBits(e
) = 0;
60 //*************************************************************
61 //gives each edge in m_G a random edgeSubGraph value
62 //works with two graphs
63 void SimDrawCreator::randomESG2(int doubleESGProbability
)
65 OGDF_ASSERT( doubleESGProbability
<= 100 );
66 OGDF_ASSERT( doubleESGProbability
>= 0 );
73 //all edges have a chance of doubleESGProbability (in percent)
74 //to belong to both input graphs
75 int doubleESGRandom
= rand() % 100;
76 if(doubleESGRandom
< doubleESGProbability
)
78 m_GA
->addSubGraph(e
, 0);
79 m_GA
->addSubGraph(e
, 1);
83 // all edges, which do not belong to both input graphs
84 // have a 50/50 chance to belong to graph 0 or to graph 1
85 int singleESGRandom
= rand() % 2;
86 m_GA
->addSubGraph(e
, singleESGRandom
);
93 //*************************************************************
94 //gives each edge in m_G a random edgeSubGraph value
95 //works with three graphs
96 void SimDrawCreator::randomESG3(int doubleESGProbability
, int tripleESGProbability
)
98 OGDF_ASSERT( doubleESGProbability
+ tripleESGProbability
<= 100 );
99 OGDF_ASSERT( doubleESGProbability
>= 0 );
100 OGDF_ASSERT( tripleESGProbability
>= 0 );
107 /*All edges have a chance of tripleESGProbability (in percent)
108 to belong to all three graphs.*/
109 int multipleESGRandom
= rand() % 100;
110 if(multipleESGRandom
< doubleESGProbability
+ tripleESGProbability
)
112 m_GA
->addSubGraph(e
,0);
113 m_GA
->addSubGraph(e
,1);
114 m_GA
->addSubGraph(e
,2);
116 /*Furthermore, all edges have a chance of doubleESGProbability
117 to belong to two of three graphs.*/
118 if(multipleESGRandom
>= tripleESGProbability
)
120 int removeESGRandom
= rand() % 3;
121 m_GA
->removeSubGraph(e
, removeESGRandom
);
126 //all edges, which do not belong to two or three graphs
127 //have a 33 percent chance to belong to one of the three graphs.
128 int singleESGRandom
= rand() % 3;
129 m_GA
->addSubGraph(e
, singleESGRandom
);
136 //*************************************************************
137 //gives each edge a random edgeSubgraph value
138 //works with graphNumber number of graphs
139 void SimDrawCreator::randomESG(int graphNumber
)
141 OGDF_ASSERT( 0 < graphNumber
&& graphNumber
< 32 );
143 int max
= (int)pow((double)2,graphNumber
+1)-1;
147 int randomESGValue
= 1 + rand() % max
;
148 m_GA
->subGraphBits(e
) = randomESGValue
;
154 //*************************************************************
157 void SimDrawCreator::createRandom(int numberOfNodes
,
159 int numberOfBasicGraphs
)
161 OGDF_ASSERT( 0 < numberOfBasicGraphs
&& numberOfBasicGraphs
< 32 );
162 randomSimpleGraph(*m_G
, numberOfNodes
, numberOfEdges
);
163 randomESG(numberOfBasicGraphs
);
168 } // end namespace ogdf