Prefer to use VS2013 for compiling and testing on AppVeyor
[TortoiseGit.git] / ext / OGDF / src / simultaneous / SimDrawCreator.cpp
blobd1fbeca305bc999b6097e264b27613df5fa694d5
1 /*
2 * $Revision: 2554 $
4 * last checkin:
5 * $Author: gutwenger $
6 * $Date: 2012-07-06 11:39:38 +0200 (Fr, 06. Jul 2012) $
7 ***************************************************************/
9 /** \file
10 * \brief Offers variety of possible SimDraw creations.
12 * \author Michael Schulz and Daniel Lueckerath
14 * \par License:
15 * This file is part of the Open Graph Drawing Framework (OGDF).
17 * \par
18 * Copyright (C)<br>
19 * See README.txt in the root directory of the OGDF installation for details.
21 * \par
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
26 * for details.
28 * \par
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.
34 * \par
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>
46 namespace ogdf {
48 //*************************************************************
49 //sets all edgeSubGraph values to zero
51 void SimDrawCreator::clearESG()
53 edge e;
54 forall_edges(e,*m_G)
55 m_GA->subGraphBits(e) = 0;
57 }//end clearESG
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 );
68 clearESG();
70 edge e;
71 forall_edges(e,*m_G)
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);
81 else
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);
90 }//end randomESG2
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 );
102 clearESG();
104 edge e;
105 forall_edges(e,*m_G)
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);
124 else
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);
133 }//end randomESG3
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;
144 edge e;
145 forall_edges(e,*m_G)
147 int randomESGValue = 1 + rand() % max;
148 m_GA->subGraphBits(e) = randomESGValue;
151 }//end randomESG
154 //*************************************************************
157 void SimDrawCreator::createRandom(int numberOfNodes,
158 int numberOfEdges,
159 int numberOfBasicGraphs)
161 OGDF_ASSERT( 0 < numberOfBasicGraphs && numberOfBasicGraphs < 32 );
162 randomSimpleGraph(*m_G, numberOfNodes, numberOfEdges);
163 randomESG(numberOfBasicGraphs);
165 }//end createRandom
168 } // end namespace ogdf