Citation
Heuristic search methods for discovering thickness N graphs

Material Information

Title:
Heuristic search methods for discovering thickness N graphs
Creator:
Flower, Jess
Place of Publication:
Denver, CO
Publisher:
University of Colorado Denver
Publication Date:
Language:
English

Thesis/Dissertation Information

Degree:
Master's ( Master of science)
Degree Grantor:
University of Colorado Denver
Degree Divisions:
Department of Computer Science and Engineering, CU Denver
Degree Disciplines:
Computer science
Committee Chair:
Gethner, Ellen
Committee Members:
Chlebus, Bogdan
Hartke, Stephen

Record Information

Source Institution:
University of Colorado Denver
Holding Location:
Auraria Library
Rights Management:
Copyright Jeff Flower. Permission granted to University of Colorado Denver to digitize and display this item for non-profit research and educational purposes. Any reuse of this item in excess of fair use or other copyright exemptions requires permission of the copyright holder.

Downloads

This item has the following downloads:


Full Text
HEURISTIC SEARCH METHODS FOR DISCOVERING THICKNESS N
GRAPHS
by
JEFF FLOWER
B.M., SUNY-Fredonia, 2003
A thesis submitted to the Faculty of the Graduate School of the University of Colorado in partial fulfillment of the requirements for the degree of Master of Science Computer Science Program
2017


This thesis for the Master of Science degree by Jeff Flower
has been approved for the Computer Science Program by
Ellen Gethner, Chair Bogdan Chlebus Stephen Hartke
Date: July 29, 2017
n


Flower, Jeff (M.S.,Computer Science)
Heuristic Search Methods For Discovering Thickness n Graphs Thesis directed by Associate Professor Dr. Ellen Gethner
ABSTRACT
An Earth/Moon, or thickness 2, graph is a graph whose edges can be distributed between two planar layers. More broadly, a graph is said to have thickness t if its edges can be distributed among t layers. The chromatic number of a graph is the minimum number of colors needed to properly color a graph. The maximum number of colors needed to color all thickness 2 graphs is known to lie in {9,10,11,12}, but the exact number remains an open question. Ant Colony Optimization is an artificial intelligence technique for finding acceptable solutions to difficult optimization problems. Previous work has used a technique developed by Gethner and Sulanke within an Ant Colony algorithm to produce new graphs of varying thickness and chromatic number. We seek to increase the speed and efficiency of implementing other AI methods using Gethner and Sulanke’s technique by introducing a modular process and software tools. Additionally we implement our own Ant Colony algorithm and propose new avenues for future research and development.
The form and content of this abstract are approved. I recommend its publication.
Approved: Ellen Gethner
m


For my wife, Lisa, and our two wonderful boys.


ACKNOWLEDGMENTS
Kha Man, for your time and suggestions regarding ant algorithms. Peter Hoesley, it’s rare to find a manager so concerned for the well being of his employees. Your support and flexibility were greatly appreciated. Most importantly, Dr. Ellen Gethner, for the time you’ve dedicated and the opportunities you’ve afforded me. Even while on sabbatical you were willing to help me, and for that I’m grateful.
v


TABLE OF CONTENTS
CHAPTER
I. INTRODUCTION...................................................... 1
Overview............................................................ 1
Motivation.......................................................... 1
Heuristic Methods................................................... 1
Section Overview ................................................... 2
II. DEFINITIONS...................................................... 3
Graphs ............................................................. 3
Visibility Graphs .................................................. 7
III. LITERATURE REVIEW.................................................. 9
Graph Coloring and Thickness........................................ 9
Coloring Maps and Planar Graphs................................. 9
Empire Graphs................................................... 9
Heawood’s Theorem........................................... 9
Maximum Colors ............................................ 10
Thickness n Graphs ............................................ 11
Earth/Moon Graphs ......................................... 11
Coloring Earth/Moon Graphs ................................ 11
Beyond Thickness 2 Graphs ................................. 12
Other Surfaces................................................. 12
Rectangle Visibility Graphs........................................ 13
Characteristics................................................ 13
Topological RVG................................................ 14
Artificial Intelligence Algorithms................................. 15
Introduction .................................................. 15
Traveling Salesman Problem..................................... 16
vi


Metaheuristics
16
Ant Colony Optimization........................................... 17
Overview...................................................... 17
Ant Colony Optimization Metaheuristic......................... 17
Common Parameters............................................. 18
Ant System ................................................... 19
Ant Colony System............................................. 20
Setting Parameters............................................ 21
Applications.................................................. 22
Tabu Search....................................................... 22
Local Search.................................................. 22
Guiding Principles............................................ 22
Simple Tabu Search............................................ 23
Additional Strategies......................................... 25
Extended Techniques........................................... 26
Applications.................................................. 26
IV. RESEARCH METHODS....................................................... 27
Background ............................................................ 27
Procedure ............................................................. 27
Generate Solution Candidate....................................... 28
Confirm Solution.................................................. 28
Confirm Solution Uniqueness....................................... 29
Existing Software Tools................................................ 29
Problems With Existing Tools........................................... 29
Building A Process .................................................... 30
Process Definition ............................................... 30
Input/Output Formats.............................................. 31
vii


Triangulation Generation Output/Solution Generation....... 31
Solution Output/Coloring Input............................ 31
Implementation of Solution Confirmation ...................... 33
Ant Colony Implementation ........................................ 33
V. FINDINGS ......................................................... 35
Results........................................................... 35
Ant Tuning.................................................... 35
Beta...................................................... 35
Further Tuning ........................................... 36
Selecting Targets............................................. 36
Targets and Results .......................................... 37
Future Study...................................................... 40
BIBLIOGRAPHY ....................................................... 41
APPENDIX
A. Triangle Generation................................................ 45
B. Ant Colony ........................................................ 60
C. New Graphs........................................................ 105
Thickness = 2, V = 17, Km removed = 3............................ 105
D. Tuning Results ................................................... 114
viii


TABLES
TABLE
2.1 By 2.17, the upper boundary of edges e for genus g, 0 < g < 4....... 7
3.1 Results for the first five values of 3.4.............................. 12
3.2 Results for the first five values of 3.5.............................. 13
3.3 Some values for 3.6. M values run across the top and g values are on the
left................................................................ 13
5.1 Recommended settings by Dorigo for ACS implementations.............. 35
5.2 Results For ^ = 10 Search........................................... 40
3.1 Layer 1 Adjacencies, Ku decomposition.............................. 106
3.2 Layer 2 Adjacencies, K14 decomposition.............................. 107
3.3 Layer 1 Adjacencies, K15 decomposition.............................. 108
3.4 Layer 2 Adjacencies, K15 decomposition.............................. 109
3.5 Layer 1 Adjacencies, Kw decomposition.............................. 110
3.6 Layer 2 Adjacencies, Kw decomposition.............................. Ill
3.7 Layer 1 Adjacencies, Ku decomposition............................... 112
3.8 Layer 2 Adjacencies, Ku decomposition............................... 113
4.1 Tuning Results for f3 = 2........................................... 114
4.2 Tuning Results for [3 = 3........................................... 115
4.3 Tuning Results for f3 = 4........................................... 115
4.4 Tuning Results for f3 = 5........................................... 116
IX


FIGURES
FIGURE
2.1 A graph with 6 vertices and 7 edges ...................................... 3
2.2 A graph and its complement............................................. 4
2.3 K5, the complete graph on 5 vertices.................................. 4
2.4 Three different ways of drawing K±. Either of the last two drawings show
K4 is planar......................................................... 5
2.5 A graph with 6 faces. The outer face of the graph is included in the count. 5
2.6 A graph G highlighted in blue and its dual G* highlighted in red .... 6
2.7 A 3-coloring of a graph. No vertex is adjacent to a vertex of the same color. 6
2.8 Surfaces of genus = 0, 1 and 2........................................ 7
4.1 Example output from the triangulation generation step.................. 32
4.2 Example output from phase 2............................................ 32
x


CHAPTER I INTRODUCTION
Overview
Graphs can be used to represent a wide range of things from city streets to airline flights to the connections shared between Facebook users. Begun in 1736 by Euler, graph theory is still relatively young with many difficult questions still to be answered.
A proper coloring of a graph assigns a color to each vertex so that no adjacent vertex receives the same color. The chromatic number of a graph is the minimum number of colors needed to perform a proper coloring of a graph [WesOl]. Finding the chromatic number of a graph is known to be WP-hard [GJ02],
Thickness is one way to measure how close a graph is to achieving planarity. The thickness t of a graph G is the minimum number of planar layers G can be decomposed into such that their union constitutes G [WesOl]. Thickness has important applications to VLSI computer chip design [BDHS97]. Finding the thickness of a graph is also known to be VP-hard [Man83].
Motivation
Since Ringel introduced the Earth/Moon Graph, the following question has remained open:
What is the maximum number of colors needed to color all graphs of thickness 2?
Currently the largest known chromatic number of a thickness two graph is nine. Relatively few examples of these types of graphs have been discovered. More examples and techniques for Ending thickness two graphs are needed to help further our understanding of them [BGS08].
Heuristic Methods
Due to their computational complexity it is impossible to exhaustively search for a solution to many problems. Heuristic search methods are an artificial intelligence technique for leveraging domain specific knowledge and have been successfully applied to a broad range of problems from job-scheduling to network routing [PR10].
1


First introduced by Dorigo and Colorini, ant algorithms are a heuristic technique inspired by the observed foraging behavior of ants [DBS06]. We use an implementation of Ant Colony System in our search for new thickness two graphs.
Section Overview
In section 3.1 we give a summary of the history of graph coloring and thickness and highlight some of the key results. In section 3.2 we discuss a specific type of thickness two graph, the rectangle visibility graph. Section 3.3 discusses in general heuristic search methods and in depth two specific methods: Ant Colony Optimization and Tabu Search. Chapter 4 discusses the research methods of our study, including a discussion of the procedure used in section 4.2. In section 4.5 we introduce a process that we hope will speed future development and exploration. In section 4.6 we discuss our implementation of Ant Colony System. Finally, in chapter 5 we discuss our results and lay out areas of future study.
2


CHAPTER II DEFINITIONS
Graphs
Definition 2.1 [WesOl] A graph, G = {V, E} is a triple consisting of a vertex set V(G), an edge set, E(G), and a relation that associates with each edge two vertices (not necessarily distinct) called its endpoints.
A graph is represented visually by drawing each vertex as a point and edges as curves joining the endpoints of the edge [WesOl].
Figure 2.1: A graph with 6 vertices and 7 edges
Definition 2.2 [WesOl] When u and v are the endpoints of an edge they are adjacent. The degree of vertex v is the number of vertices adjacent to v.
Lemma 2.3 (Handshaking Lemma) [WesOl] If G is a graph and d{v) is the degree of vertex v in G, then:
£ vev(G)
Proof: An edge is defined by two vertices, therefore summing the degrees of each vertex double counts the edges. â– 
Definition 2.4 [WesOl] A simple graph is a graph having no loops or multiple
edges. We specify a simple graph by its vertex set and edge set, treating the edge set as a set of unordered pairs of vertices and writing e = uv for an edge e with endpoints u and v.
3


Definition 2.5 [WesOl] The complement, Gc, of a simple graph, G, is the simple graph with vertex set V(G) defined by uv G E(GC) if and only if uv E(G).
Figure 2.2: A graph and its complement
Definition 2.6 [WesOl] A clique in a graph is a set of pairwise adjacent vertices. An independent set in a graph is a set of pairwise nonadjacent vertices.
Definition 2.7 [WesOl] A complete graph, Kn, is a simple graph with n, vertices, all of which are pairwise adjacent.
Figure 2.3: /W, the complete graph on 5 vertices
Definition 2.8 [WesOl] A graph is planar if it has a drawing without crossings. Such a drawing is a planar embedding of G.
Definition 2.9 [WesOl] A face is the smallest possible cycle in a graph G such that the region defined by the cycle contains no edges or vertices.
4


Figure 2.4: Three different ways of drawing /i4. Either of the last two drawings show Ah is planar.
Figure 2.5: A graph with 6 faces. The outer face of the graph is included in the count.
Proposition 2.10 [WesOl] If /(Fj) denotes the length of face Fj in a plane graph G, then2|F(G)| = £/(Ft).
Proof: Each edge e in G participates in exactly 2 faces. Therefore summing the length of each face double counts the edges. â– 
Definition 2.11 [WesOl] The dual graph G* of a planar graph G is a planar graph whose vertices correspond to the faces of G. The edges of G* correspond to the edges of G as follows: if e is an edge of G with face X on one side and face Y on the other side, then the endpoints of the dual edge e* G E(G*) are the vertices x, y of G* that represent the faces X, Y of G.
A proper graph coloring assigns a color to a vertex, v, of a graph, G, so that no adjacent vertex of v in G receives the same color. A A>coloring of G is a coloring that uses k colors. In a proper coloring, each color class is an independent set, so G is fc-colorable if and only if V(G) is the union of k independent sets [WesOl].
5


Figure 2.6: A graph G highlighted in blue and its dual G* highlighted in red
Definition 2.12 [WesOl] The chromatic number of a graph G, y(G), is the least k such that G is fc-colorable.
Definition 2.13 [WesOl] A graph G is A>chromatic if y(G) = k. If y(i7) < y(G) for every proper subgraph, H of G, then G is color-critical or A>critical.
Figure 2.7: A 3-coloring of a graph. No vertex is adjacent to a vertex of the same color.
For graphs that are not planar, we may seek to measure how far away they are from achieving planarity. One such measure is thickness [WesOl]. Determining the thickness of a graph is known to be iVP-hard [Man83].
Definition 2.14 [WesOl] The thickness of a graph G, 0(G), is the minimum number of planar graphs in a decomposition of G into planar graphs.
Graphs can be embedded on other surfaces besides the sphere or the plane. We characterize these surfaces in the following way:
6


Definition 2.15 [WesOl] A handle is a tube joining two holes cut in a surface. The torus is the surface obtained by adding one handle to a sphere.
Definition 2.16 [WesOl] The genus of a surface obtained by adding handles to a sphere is the number of handles added; we use A7 for the surface of genus 7. The genus of a graph G is the minimum 7 such that G embeds on S1.
Figure 2.8: Surfaces of genus = 0,1 and 2
Theorem 2.17 (Euler’s Formula) [WesOl] For a graph G with v vertices, e edges and / faces on a surface of genus g:
v - e + / = 2 - 2g (2.2)
The quantity 2 — 2g is known as the Euler Characteristic, e.
Theorem 2.18 [Ale98] If G is a graph with at least three vertices, e edges and v vertices, then e < 3(v — e)
Proof: Every face has at least 3 edges. By 2.10, 3/ < 2e and / < |e. Substituting in 2.17, v — e + |e > e. Simplfying we arrive at e < 3(v — e). ■
Table 2.1: By 2.17, the upper boundary of edges e for genus g, 0 < g < 4
Genus 0 1 2 3 4
e < CO cS 1 3v 3v + 6 3v + 12 3v + 18
Visibility Graphs
7


Some graphs can be visualized in the plane by representing their vertices as rectangles. These visualizations, specifically Rectangle Visibility Graphs, have applications to VLSI design for computer chips [BDHS97].
Definition 2.19 [TT86] A graph G is a bar-visibility graph or BVG if its vertices can be represented by closed horizontal line segments in the plane, pairwise disjoint except possibly for overlapping endpoints, in such a way that two vertices u and w are adjacent if and only if each of the corresponding segments is vertically visible from the other. The vertices u and w are called vertically visible if there is a non-degenerate rectangular region Bu>w (the band of visibility for u and w) with two opposite sides that are subsets of each of these segments, and Bu>w intersects no other segment. A set of segments realizing a BVG is called a layout of the BVG.
Definition 2.20 [TT86] Consider a collection R of rectangles in the plane, where each rectangle has its sides parallel to the axes, and rectangles may share boundary points but not interior points. Two rectangles u and v are visibile if there is a band of visibility Bu v between them. The visibility graph of R is the graph of the visibility relation on the elements of R. A graph G is a rectangle-visibility graph or RVG if it is the visibility graph of some collection R of rectangles; R is called a layout of G.
Definition 2.21 [TT86] A rectangle-visibility layout is noncollinear if no two rectangles have collinear sides. A rectangle-visibility layout is collinear if two rectangles have collinear sides.
Definition 2.22 [TT86] A graph is a weak RVG if it is a subgraph of some RVG.
8


CHAPTER III LITERATURE REVIEW
Graph Coloring and Thickness Coloring Maps and Planar Graphs
In 1852, while trying to color a map of the counties of England, Francis Guthrie conjectured only four colors were necessary to properly color any map of connected regions [BLW76]. To aid in Ending a solution, we represent a map, M, as a planar graph by creating a vertex for each connected region in M and drawing edges between vertices if they share a boundary in M. From this relation we are also able to create a map from a planar graph [Hut93].
Alfred Kempe published a proof in 1879 [Kem79], but in 1890 Heawood published his findings of a flaw in Kempe’s proof [Hea90]. After many small steps, a proof was finally discovered in 1976 by Appel and Haken[AH76, AH77, AHK77] and the following was finally affirmed:
Theorem 3.1 (Four Color Theorem) Every map drawn in the plane (or on the surface of the sphere) can have one of four colors assigned to each connected region so that every pair of regions with a border arc in common receive different colors [Hut93f.
Because of the equivalence between maps and planar graphs, we can also say that all planar graphs can be colored with at most four colors.
Empire Graphs
Unable to find a correction to the flaw he found in Kempe’s proof, Heawood proposed a problem he thought he could solve. Given a map that contains empires, where an empire is a group of countries united under one flag, how many colors would the map need if all countries in an empire must be assigned the same color and no adjacent empires should receive the same color [Hea90]?
Heawood’s Theorem Assume that a map contains empires made of no more than M countries. We call this map an M-pire map. Let the graph, G, be the planar graph
9


representing the M-pire map, with each vertex corresponding to a country and the edges representing adjacent countries. Create the graph, G*, from G by combining the set of vertices belong to an empire into one vertex and removing multiple edges. G* is the M-pire graph of the M-pire map. To solve the empire problem we seek a minimum coloring of the M-pire graph [Hut93].
Let the number of vertices in G* be n* and the number of edges in G* be e*. Each vertex in G* is formed from at most M vertices in G, the planar graph having n vertices and e edges. The edges and vertices of G and G* compare in the following way: Mn* > n and e* < e. Using 2.3, we can say the sum of degrees of G* = 2e* < 2e < 6n — 12 < 6Mn* - 12 [Hea90],
From this, we conclude the average vertex degree in G*: degi+degM---+degn* < 6M — jp- < 6M, and G* must contain a vertex of degree at most 6M — 1 [Hea90].
Heawood use the previous information to prove the following [Hea90]:
Theorem 3.2 (Heawood’s Empire Theorem) Every M-pire graph G* can be 6 M -colored
Proof: By induction on n*. If n* < 6M, then G* can easily be 6M-colored by placing a different color on each vertex. Assume the theorem is true for every M-pire graph with fewer than n* vertices, and let G* be an M-pire graph with n* > 6M vertices.
Find a vertex v of G* of degree at most 6M— 1; delete v and all its incident edges. The resulting graph is still an M-pire graph and so, by induction, can be 6M-colored. Since v in G* is adjacent to at most 6M — 1 different colors, there is a color available to place on v. Thus G* is 6M-colored [Hut93]. ■
Maximum Colors Although Heawood had shown an M-pire graph needed no more than 6M colors, the question still remained, did any M-pire graphs exist that required 6M colors? In 1983 Ringel and Jackson and the question as follows [RJ83]:
10


Theorem 3.3 (M-pire Theorem) For every M > 1 there is an M-pire graph that requires 6M colors. In fact, the graph consisting of 6M mutually adjacent vertices is an M-pire graph.
In other words, the complete graph containing 6M vertices, K$m, is an M-pire graph and is 6M-colorable. This result holds for M > 1 because by the Four-Color Theorem, only four colors are needed for a graph with M = 1.
Thickness n Graphs
Earth/Moon Graphs In 1959, Ringel put forth the following twist on empire coloring [Rin59]: Imagine the moon has been colonized and we have been asked to color a map of the Earth and its colonies on the Moon with the following restrictions:
1. adjacent regions on Earth or on the Moon receive different colors, and
2. a country on Earth and its lunar colony receive the same color
Let Gm represent the graph form of the map of the moon and Ge represent the graph form of the map of Earth. Each graph is planar as it represents a map. If we combine the graphs by merging a country vertex from the graph of Earth with it’s corresponding colony vertex from the graph of the Moon, the resulting graph, G*, is a 2-pire graph. Additionally, G* has a thickness of 2 since we have shown a decomposition of G* into two planar layers, Ge and Gm [Hut93].
It is important to note that all Earth/Moon graphs are 2-pires, but not all 2-pires are Earth/Moon graph. For example, Kg is a 2-pire, but Q(Kg) = 3.
Coloring Earth/Moon Graphs Because Earth/Moon Graphs are 2-pires, by Hea-wood’s theorem we know that they require at most 6 * 2 = 12 colors. What is not known is if any Earth/Moon graphs exist that actually require 12 colors [Hut93]. The largest known chromatic number of a thickness 2 graph was 8 until Thom Sulanke discovered an Earth/Moon Graph in 1973 that required 9 colors [Gar80].
11


Sulanke’s graph remained the sole known Earth/Moon graph with chromatic number of 9 until 2007 when Gethner and Sulanke introduced new thickness 2 graphs, including an infinite family of graphs, all with chromatic number of 9 [BGS08, GS09]. Currently the maximum number of colors needed for any thickness 2 graph lies in {9,10,11,12} [GS09],
Beyond Thickness 2 Graphs We can generalize the Earth/Moon problem to other thicknesses. Let ft be the largest chromatic number of any thickness-1 graph, the following can be said [JT78]:
{4}if t = 1,
ft e
{9,10,11,12}if t
2,
{67 — 2, 67 — 1, 67}if 7 > 2
(3-1)
Other Surfaces
So far we have discussed graphs on a surface of genus g = 0. Heawood also explored graphs for g > 0. Let x(fiO equal the minimum number of colors needed to color every graph that embeds on the surface of genus g [Hea90].
Theorem 3.4 For g > 0, x(fiO < [(1/2)(7 + ^^Sg + 1)J.
Table 3.1: Results for the first five values of 3.4
Genus 1 2 3 4 5
x(g) 7 8 9 10 11
Heawood’s formula provided an upper bound, but the question remained, is this upper bound reached? Ringel and Youngs proved the following in 1968 [RY68]:
Theorem 3.5 The genus of Kn is |~(l/12)(u — 3)(n — 4)], and consequently for g > 0, X(9)= L(1/2)(7 + v/48^+TJ.
12


Table 3.2: Results for the first five values of 3.5
Vertices 7 8 9 10 11
Genus 1 2 3 4 5
Because the complete graph, Kn contains the maximum possible edges for a given number of vertices, n, Ringel and Youngs had solved the equivalent of the Four Color Theorem for all surfaces except the sphere [Hut93].
Heawood also explored M-pire maps on surfaces besides the sphere. For an M-pire map on a surface with genus, g, let the minimum number of colors needed for all such graphs be denoted x(sO> then the following holds [Hea90]:
Theorem 3.6 For all g > 0 and M > 1, except for the case g = 0 and M = 1 xig M) <
Table 3.3: Some values for 3.6. M values run across the top and g values are on the left.
1 2 3 4 5
1 7 13 19 25 31
2 8 13 19 25 31
3 9 14 20 25 31
4 10 15 20 26 32
5 11 16 21 26 32
Rectangle Visibility Graphs
Characteristics
It was shown by Wismath [KW89] that all planar graphs have a rectangle-
visibility layout. Additionally, if we partition the edges of an RVG, R into two
sets, one set, Ry, containing all vertical visibility edges and one set, Rh, containing
all horizontal visibility edges, both sets, Ry and Rh form a BVG. Since a BVG is
13


planar, every RVG has a decomposition into two planar layers. That is, all RVG have thickness < 2 [BDHS97].
By the following, we know the edge and vertex boundaries within which a graph would qualify as an RVG candidate [HSV99]:
Theorem 3.7 A rectangle-visibility graph on n < 5 vertices has at most Cm — 20 edges.
Theorem 3.8 There is a (connected) rectangle-visiblity graph with n vertices and Cm — 20 edges for each n > 8.
Corollary 3.9 With the exception of the cases (n,m) = (6,16) and (7,22), the following holds for all n > 4:
1. for each m with 0 < m < Cm — 20, there is a rectangle-visibility graph with n vertices and m edges.
2. for each m with n — 1 < m < Cm — 20, there is a connected rectangle-visibility graph with n vertices and m edges.
Given a graph, G with Cm — 20 or fewer edges, it has been shown recognizing G as an RVG is np-complete [She96].
Topological RVG
A Rectangle Visibility Graph fails to encode information about the graph such
as multiplicities of visibilities and the direction of the visibilities. An RVG also leaves
out information about whether or not a given rectangle can see infinitely far. a
Topological Rectangle Visibility Graph (TRVG) records all of this information by
allowing for multiple edges between two rectangles and by framing the entire graph
with four new rectangles: N, S, E, and W [SW03].
A TRVG is formally defined in the following way: Let R be a set of axis-aligned
rectangles. The topological rectangle visibility graph of R consists of a pair (Dy, Dh)
14


of graphs. Here, Dy records, with multiplicities, the upwardly directed, cyclically ordered vertical visibilities of R U {S, At}; Dh records with multiplicities, the left-to-right directed, cyclically ordered horizontal visibilities of R U {W, E} [SW03].
Additionally, Strienu and Whitesides provide a quadratic time algorithm for recognizing a TRVG and a method for building a visibility layout from a TRVG [SW03].
Artificial Intelligence Algorithms
Introduction
An agent is anything that receives input from an environment and chooses an action based upon its understanding of the input. The current input value(s) passed to an agent are referred as the agent’s state. From an artificial intelligence point of view, an agent is a program, the agent’s input may come from places such as sensors or user commands, and the agent’s action could be something as simple as writing on a computer screen, or as complicated as moving a robotic arm [PR10].
The problem an agent seeks to solve has five components [PR10]:
• The initial state the agent starts in
• A description of the possible actions available to the agent. For a given state, s, a neighborhood function, N(s), returns the set of actions applicable to s
• A description of what each action does, that is, the result of applying action a to state s
• A function, g(s), which determines if s is a goal state
• A path cost function, p(si, s2), that determines the cost of moving between the states Si and s2
Graphs lend themselves well to the visualization of a search space. Different states are represented as nodes in the graph. Edges in the graph represent valid transitions
15


between states. Weights are added to edges to represent the cost of moving from one state to another.
Many combinatorial optimization problems have been proven iVP-hard. As walking away from the problem is generally not considered a reasonable response, we must attempt to find other methods that will provide an acceptable solution in an adequate amount of time. On these occasions we replace the path cost function with a heuristic function. A heuristic function is a method ”...in which additional knowledge of the problem is imparted to the search algorithm [PR10].” Since an exhaustive search of the problem space is not possible, we use heuristic functions to help us make informed decisions about which action to apply to the current state. Additionally, since we are not likely to find an optimal solution to our problem, we replace the goal function with an objective function which determines if the current state is within an acceptable range of solutions [PR10].
Traveling Salesman Problem
In the Traveling Salesman Problem (TSP), a salesman is assigned a group of cities he must visit. The salesman wishes to start from his home town, visit each city once, and then return to his hometown. The salesman knows the cost of traveling between any pair of cities and wants to find the route with the lowest cost [DS04],
The TSP search space can be modeled as a graph. Each vertex of the graph represents a city in the search space. Edges of the graph represent valid transitions between cities and edge weights signify the cost of traveling between two cities.
A successful search strategy applied to the TSP would return a list representing the order the salesman should visit the cities in and the total cost of the tour. The TSP has been shown to be iVP-complete [GJ02],
Metaheuristics
Metaheuristics have developed as a framework for applying heuristics to a broader
class of problems with similar characteristics [DS04, GP10]. Heuristic methods can
16


be categorized in one of two ways: constructive or local search. A constructive search attempts to construct a solution in an iterative fashion. A local search method attempts to modify an existing solution by making small, iterative improvements [DS04],
There exist many different heuristic methods such as Simulated Annealing, Genetic Programming, Particle Swarm Optimization and Bees Algorithm [Broil]. We focus on two methods: Ant Colony Optimization and Tabu Search.
Ant Colony Optimization
Overview First developed by Dorigo, Maniezzo and Colorini [Broil], ant algorithms seek to solve difficult optimization problems by drawing inspiration from ant behaviors [DS04],
Most everyone has seen at one time or another a group of ants parading single hie. This behavior would seem to indicate a certain degree of intelligence among ants but research has shown simple, individual actions among ants leads to more complex, coordinated behavior in the larger group [DS04, DBS06].
As an ant explores its environment, it deposits a type of chemical known as pheromone. Experiments have shown that when another ant comes upon a pheromone trail, it will, within a certain probability, follow the trail. This second ant will also deposit pheromone, increasing the pheromone intensity of the trail. Higher amounts of pheromone increase the probability that an ant will follow the trail. Altering the environment through pheromone placement is an indirect communication method known as stigmergy. Over time, as ants continue to explore and lay pheromone, the ants will converge upon a single path, resulting in our ant parade [DS04, DBS06].
Ant Colony Optimization Metaheuristic A metaheuristic is a framework for applying heuristics to a class of problems. Gendreau defines a metaheuristic as “...a general strategy for guiding and controlling inner heuristics specifically tailored to the problems at hand [GP10].”
17


Ant Colony Optimization(ACO), is a metaheuristic for ant algorithms. The ACO metaheuristic as described in [DBS06]:
Algorithm 1: ACO Metaheuristic Set parameters, initialize pheromone trails; while termination condition not met do Construct AntS olutions;
ApplyLocalSearch (optional);
UpdatePherornones; end
In the ConstructAntSolution phase, each ant iteratively constructs a solution. During an iteration an ant chooses a component to add to the solution from a set of valid components, known as the ant’s neighborhood. The component choice is guided by a probabilistic method. As with real ants, the probability of component selection is affected by the pheromone level of the component [DBS06].
The optional phase, Apply LocalS earch, attempts to apply improvement methods to a fully constructed ant solution [DBS06].
The UpdatePheromone phase makes the components of good solutions more attractive and components of bad solutions less attractive by manipulating the component pheromone levels. Members of good solutions see their pheromone levels increased, while the members of bad solutions see their levels decreased. Typically applied globally, the process of decreasing pheromone levels is referred to as evaporation. The number of solutions recognized as good solutions is application dependent [DBS06],
Common Parameters While the exact parameters of an ant algorithm can differ between implementations, there is a core group that tends to remain the same [DS04], • G, a weighted graph of edges and nodes representing ant’s search space
18


• r, amount of pheromone deposited on an edge between two nodes in G
• p, pheromone evaporation rate
• rj, heuristic value of a component selection, typically 1/edge weight (this is separate from pheromone level)
• a, the importance placed on pheromone level during ConstructAntSolutions phase
• f3, the importance of heuristic information in edge selection during ConstructAntSolutions phase
Ant System Colorini, Dorigo and Maniezzo originally created Ant System (AS) to solve the Traveling Salesman Problem [CDM91]. Since that time it has been adapted to solve other optimization problems.
When Ant System is applied to TSP, each ant iteratively builds a tour of cities. Given two towns, i and j, we define the probability that an ant chooses edge ij at time t as [CDM91]:
Pa
E”=i[n,(*)]“ - ('fa-]'3
(3.2)
With the following parameters:
• Tij(t), the pheromone level on edge ij at time t
• rjij, the cost of edge ij
• a, the importance placed on the pheromone level
• /?, the importance placed on the heuristic cost of an edge
The ratio between a and f3 creates a balance between exploration and exploitation. A ratio in favor of a places more emphasis on exploration, that is the pheromone
19


levels. A ratio in favor of [3 places more emphasis on exploitation, that is, the edge weights which represent our a priori knowledge of the problem space [DS04],
After each ant has built a tour, any edge participating in an ant’s solution has is pheromone level increased. If, for example, an edge occurs in more than one solution, it’s pheromone will be increased twice. The pheromone update formula varies depending on the type of Ant System implementation [CDM91].
Ant Colony System Ant Colony System (ACS) was introduced as an improvement to Ant System. ACS modifies the AS approach to edge selection and pheromone updating [DG97].
ACS defines a pseudo-random-proportional transition rule [DG97]. For an ant on a node, r, a city, s is chosen by the following equation:
{arg maxugJ (r){[r(r,M)] • [r]{r,u)\^}, if q < q0
(3.3)
otherwise return result of equation 3.2 With the following parameters:
• argmax, a function which returns the largest member of a set • q, a random number from (0,1)
• go, a user determined value in [0,1]
• Jk(r), a set of nodes the k-th ant can select from that are connected to node r
As in AS, the ACS transition rule strikes a balance between exploration and exploitation, but the parameter q0 determines how much we value exploitation over exploration. Larger values of qo favor the selection of the best edge, while lower values encourage a more random exploration using equation 3.2 [DG97].
In ACS, only edges participating in the globally best tour have their pheromone levels updated. The global update formula for an edge, rs, is [DG97]:
20


r(r, s) = (1 - p) â–  r(r, s) + p â–  Ar(r, s)
(3.4)
where
{Ln}, if (r, s) G global-best-tour
(3.5)
0, otherwise
with parameters:
• p, the pheromone evaporation rate • Lgb, the total length of the globally best tour
Restricting pheromone update to the globally best tour focuses the search on the area of the best tour.
ACS also adds a local pheromone updating rule that occurs immediately after an ant has selected an edge. Local update to an edge, rs, is determined by the following formula [DG97]:
r(r,s) = (1 - p) â–  r(r,s) (3.6)
The local update function decreases an edge’s pheromone level. The goal of the local update is to shuffle tours by making an edge that occurs early in one ant’s tour occur later in another ant’s tour. In this way we encourage diversity among the tours and discourage a premature solution convergence that may result in a sub-optimal solution.
Setting Parameters The chosen parameter values are important to any ACO implementation. While different papers suggest values that we can use as a starting point, the best method is to perform experiments to determine the best values for a specific implementation [DG97].
21


Applications While originally applied to the Traveling Salesman Problem, ACS
has since been adapted to a wide range of problems, including vehicle routing, graph coloring, set covering, Bayesian networks and bin packing [DS04, DBS06].
Tabu Search
Local Search Local search begins with an initial solution that has already been constructed. A user defined objective function measures the value of a solutions. A small, local modification is made to the solution by a heuristic function, resulting in an improved solution as measured by the objective function. The process continues until there are no improving modifications to be made. Because the search is not exhaustive, when a stopping point is reached a local optimum has been found [GP10].
The local search process, also known as Hill Climbing, can be described formally as [Glo89]
Algorithm 2: Hill Climbing Heuristic
1) Select an initial x E X;
2) Select some s E S(x) such that c(s(x)) < c(x);
if no such s exists then
a; is a local optimum, return
else
x := s(x), return to Step 2
end
With the following parameters:
• A,the set of all feasible solutions
• S, the set of all moves applicable to solutions in X
• c(x), an objective function measuring the cost of x E X .
Guiding Principles Introduced in 1986 by Fred Glover, Tabu Search(TS) sought
to improve heuristic methods for solving combinatorial optimization problems by
22


avoiding the local optimum issues encounterd during local search [GP10]. Like ACO, TS is a metaheuristic [Glo89].
The word ‘tabu’ is used in the Tongan language to refer to something that cannot be touched because it is sacred [GL97]. Webster’s defines it as “banned as constituting a risk.” We wish to avoid a risk during a search that will lead us down a fruitless path. In society, tabus are transmitted through social custom. Lacking a social shaming mechanism in programs, we transmit knowledge of tabu items through data structures instead. By keeping a record of tabu items, we can use past events to inform future choices [GL97].
During a search, we choose to mark certain moves, that is, the transition from one state in the search space to another, as tabu. We keep a record of tabu items in a tabu list. Items remain on the tabu list for certain length of time. As sometimes happens in real life, tabus are forgotten, or, in our case, removed from the tabu list.
Glover explains, “...tabu search is based on the premise that problem solving, in order to qualify as intelligent, must incorporate adaptive memory and responsive exploration [GL97]”. Adaptive memory is accomplished through the use of tabu lists. Responsive exploration “...derives from the supposition that a bad strategic choice can yield more information than a good random choice [GL97]”. Using tabu lists as memory for our search program we can make informed decisions about how to proceed during the search. The hope is, if a decision doesn’t turn out well, we can adapt quickly since we have insight into why the decision was made in the first place.
Simple Tabu Search Tabu Search is similar to local search with an important distinction: while local search always seeks to select a move the improves the solution, TS allows for the selection of moves that are objectively worse. By allowing nonimproving moves, TS hopes to escape the local optimum problem that hinders local search [GP10].
23


In order to avoid cycles during the search, we place information about moves that would undo a selected move in the tabu list. The tabu list can be thought of as a form of ‘recency memory’. Depending on the complexity of the problem space the information we track in the tabu list can be a collection of attributes, or it can be the specific move that is prohibited [GL97].
The length of time a move remains on the tabu list, the tabu tenure, can be a fixed length, or determined dynamically by the program. A tabu tenure of length n will have no cycles < n [GT93].
Tabu Search typically terminates when one of the following three conditions is met [GP10]:
1. After a fixed number of iterations or CPU time
2. After some number of iterations without an improvement in the objective function value
3. When the objective function reaches a pre-specihed threshold value
The Simple Tabu Search procedure is as follows [GP10]:
Given:
• S, the current solution
• S*, the best-known solution
• /*, the value of S*
• T, the tabu list
• N(S), the neighborhood of S, that is, the states that can be reached from S
• N(S), N(S) — T
24


Algorithm 3: Simple Tabu Search
Construct an initial solution, So;
S = S0;
r = f(s0y,
S* = So)
T = 0;
while termination condition not satisfied do select S in argmins,eff^[ f (S')\; if/(£) record tabu for the current move in T
end
Additional Strategies Advanced uses of Tabu Search use additional strategies to enhance the effectiveness of the search
Aspiration Criteria
There may be instances when a move on the tabu list is desirable. Aspiration criteria define cases when it is acceptable to override a move’s membership in the tabu list. For example, if a given move would result in a better objective value than the global best objective value, we could choose to override the tabu list and execute the move [GT93].
Intensification
Intensification occurs periodically throughout TS. Intensification in TS remembers good solutions or attributes of good solutions. The search space of TS is then altered to favor the good solutions or attributes [GL97].
For example, TS may choose to lock in certain members of the solution that appear frequently in good solutions [GP10], or TS may choose to pare the search space down to only include members of good solutions [Glo89].
Diversfication
25


Where Intensification seeks to localize TS to a subset of the search space identified as promising, Diversification seeks to do prevent TS from becoming too local in its search. Using knowledge of the search space so far, Diversification attempts to boldly drive the search toward new, unexplored regions. One example of this is a frequency memory which tracks how often moves or attributes of moves are uses. The search would then penalize these moves or attributes during selection [GL97].
Extended Techniques Extended techniques in TS include deeper use of knowledge, hybridization and parallelization, among others. Deeper use of knowledge includes advanced usage of elite solutions to create new solutions or remembering local optima so they can be avoided in the future. Hybridizationn uses other heuristic methods such as genetic algorithms. Parallelization is especially useful when creating neighborhoods of a solution state [GP10].
Applications Tabu Search has been successfully applied to many types of optimization problems, including: job shop scheduling, classroom scheduling, graph coloring graph partitioning, vehicle routing, traveling salesman problem, computer aided design and fault tolerant networks [GL97].
26


CHAPTER IV RESEARCH METHODS
Background
The relation between the number of vertices in a graph and the size of the graph’s largest independent set place a lower bound on the chromatic number of the graph. This relation can be used to narrow the search for thickness t graphs of at least chromatic number n.
Proposition 4.1 [M0AO8] Given a graph, G, with n vertices, x(G) > Xftj
Proof: If G is properly colored, the set of vertices assigned to a specific color define an independent set in G. The size of the largest independent set in G is signified by a. If the vertex sets belonging to each color have the same size, x(G)a = n. If the vertex sets belonging to each color do not have the same size, then we have over counted n, and x(G)a > n. Dividing through by a we reach x(G) > â– 
Given an independent set, S, of a graph, G, no edges exist in G between any two vertices in S. Since the complement of a graph contains all edges not present in the graph, the set S and its edges in Gc form a complete subgraph. Combining this knowledge and the previous proposition, we arrive at the following
Proposition 4.2 [GS09] Suppose G is a graph with n vertices. If Gc is Km-free, then x(G)> r^rl.
Proof: Coloring the vertices of a graph is equivalent to partitioning the vertices into independent sets which in turn is equivalent to partitioning the vertices of the complement into complete subgraphs.
Thus if Gc does not contain Km then at most m—1 vertices of G can be assigned the same color, in which case x(d) > ■
Procedure
We seek to generate candidate graphs of a specific thickness and chromatic number. The difficulty in this process is finding the decomposition of a candidate graph
27


into planar layers. The following approach, described in [GS09], generates planar layers first and then, through a series of transformations that preserves the planarity of the layers, attempts to transform the layers into a valid candidate graph. Generate Solution Candidate
1. Generate t triangulations representing the planar layers of a thickness t graph
2. Let G be the union of the t triangulations
3. Flip edges in the triangulations to reduce the number of Km in Gc
4. Stop when no Km remain in Gc
A note on edge flipping An edge in a planar graph participates in two faces. In a triangulation all faces are triangles. If we draw the faces an edge participates in we have fd4 less an edge. When we flip an edge, we replace it with the missing edge from Ah, preserving the planarity of the graph.
Confirm Solution
To insure uniqueness we confirm a candidate solution is critical with the following procedure
1. Confirm each layer of the candidate solution is planar
2. Remove duplicate edges (remove any edge that appears in more than one layer)
3. For each edge in the triangulations remove any edge which leaves Gc with no K
1Ym
4. Let G be the union of the planar layers
5. If any vertex of G has degree < > reject G
6. Determine the current chromatic number of G
28


7. If any vertex of G is not critical, reject G
8. Check that each edge of G is critical. If the edge is not critical, remove it from G and it’s triangulation layer. If the edge is removed, re-run Step 5
Implementation Notes In the implementation we must track which triangulation an edge belongs to. Mathematica [Woll6] allows us to use undirected edges as keys in an associative map. This gives us the ability to keep a list of deleted edges from Step 8 and delete the edges from the associative map at a later time, a nice separation of concerns that reduces the complexity of the implementation.
Confirm Solution Uniqueness
Finally, we check the solution against all other known solutions to confirm the solution is unique.
Existing Software Tools
Thom Sulanke has written a collection of utilities for generating and manipulating triangulations [Sul06b]. Among other things, the utilities can be used to;
• generate triangulations by thickness, genus and orientability
• view the adjacency matrix or adjacency list of a triangulation
• flip an edge in a triangulation
• import and export triangulations
Problems With Existing Tools
While the triangulation utilities are useful, they have some important limitations. As the utilities are written now, they can only create one triangulation at a time. This is useful if a user wants to hone in on the creation of a specific triangulation but it becomes a slow down for someone looking to use these tools to write software that uses the triangulations to generate candidate solutions as they must take the time
29


to understand the tool and build a process for generating the triangulations in their own code.
The utilities are written in the C language. Anyone looking to use the utilities must then either write their own code in C, or use a language with the capability of calling C code. While it is certainly possible to call C code from programs written in other languages, this is an additional level of complexity on top of an already complex problem. Writing code in C is also not without its own challenges. As a lower level language, it requires more code than higher level languages. Code written in C is more prone to code errors because of user pointer management, a lack of code frameworks, debugging and testing tools are less prominent and more cumbersome to use.
Building A Process
We seek a way that allows us to leverage the existing software tools while freeing us from their current restraints.
Process Definition
We define a process that can be broken into four major steps
1. Create triangulations
2. Apply a process/algorithm to the triangulations to identify potential solutions
3. Identify a potential solution as a valid solution
4. Determine if the solution is previously undiscovered
The only part of the process likely to change is the algorithm applied to identify potential solutions. By building a separate program to handle each step of the process we speed up future implementations since the code for three of the steps is reusable. By decoupling the steps into their own programs they become easier to maintain,
30


and remove language restrictions on algorithm implementations. The separate programs define a pipeline where data flows into and out of each process by way of a standardized hie format.
Input/Output Formats
We define standard input and output hie formats between the process steps. The formats are as follows:
Triangulation Generation Output/Solution Generation
• Line 1
1. the thickness of all graphs in the hie
2. the number of vertices for all graphs in the hie
3. the genus of all graphs in the hie
• lines 2 through the end
1. one triangulation in lex format
Lex format is a way of compactly encoding the information about a triangulation. In lex format, every group of of 3 letters represents a face. For example, “abc” would represent the face dehned by the edges ab, be and ca. Given the lex string of a triangulation, the number of faces in the triangulation equals the string length divided by 3.
Every thickness number of lines represents the triangulations for a thickness t graph. If, for example, thickness = 2, every 2 lines of lex strings represent the layers of one graph.
Solution Output/Coloring Input
• One graph per hie
• Line 1
31


2, 17, 0
abgabpacfacladeadfaehaghalpbcdbclbdjbegbejblpcdncficiocnodejdfidinegkehqekq abfabmaceackadjadpaepafnagjagnakmbckbcobdfbdobkqbmqcdicdocelchichldehdepdfg
Figure 4.1: Example output from the triangulation generation step
2,17,0
0,10,abcabd,bcdbde 10,0,abcabd,bcdbde
Figure 4.2: Example output from phase 2
1. n, the number of vertices
2. m, the size of the complete graph removed from the complement of the union of the triangulations
3. g, the genus of the graph • lines 2 through t
1. Number of iterations so far
2. Number of Km remaining in the complement
3. Triangulation of layer 1 in lex format
4. Triangulation of layer 2 in lex format
32


Implementation of Solution Confirmation
The solution confirmation was written with Mathematica [W0II6] as it offers a very flexible native graph type. Additionally it offers testing abilities out of the box with no additional need for configuration. The confirmation program can be run from the command line, which gives us the potential to use it as part of an automated process in the future.
Ant Colony Implementation
We used Ant Colony System to generate solution candidates. The cost function, 77, returns the inverse of the number of Km in the complement. In this way, fewer Km in the complement are made to appear more desirable. Each ant is given a copy of the starting triangulations read from the triangulation input file and then executes a sequence of edge flips. In addition to remembering the sequence of edge flips, the ant must also track which triangulation an edge belonged to and the cost of the edge flip (the number of Km in the complement). The ant must also update the state of the triangulations after each edge flip so that it chooses from a valid list of available edge flips in the next iteration.
The random nature of the edge flips means there is no guarantee the last edge flip is the best. For this reason, after an ant is finished, we determine at what point during the sequence the fewest Km in the complement was reached. From this point on we consider the ant’s sequence to go from it’s first edge flip to the edge flip that achieved the lowest score.
The following parameter values were used:
• 0=1
• p = 30
• p = 0.01
• Qo = 0.1
33


• maximum ant edge flips per iteration = n(n — 1) * 10, n = |V(G)|
• maximum iterations = 1000
34


CHAPTER V FINDINGS
Results
Ant Tuning
Ant Colony parameter values are problem specific and need to be tuned for the problem at hand. Dorigo recommends the following base values for Traveling Salesman implementations of the Ant Colony System (ACS) algorithm, where m is the number of ants and Cnn is the cost of the nearest neighbor algorithm run on the search graph [DS04],
Table 5.1: Recommended settings by Dorigo for ACS implementations.
a P P m TO
1 2 to 5 0.1 10 1 (Jnn
Because of the similarity of the Traveling Salesman problem with the edge flipping procedure, we used Dorigo’s recommended values as a starting point.
Beta In the pseudo-random-proportional transition rule of the ACS (see equation 3.3), f3 determines how much influence the heuristic measure of an edge has on the selection of the edge. Larger values of f3 increase the influence of the heuristic measure. We used a graph of thickness 9 = 2, vertices v = 17 and genus g = 0 to test the effect different values of f3 had compared with different numbers of ants. The ACS implementation was run five times for each combination of values. The results can be found in appendix something D.
From the tuning runs you can see that when the number of ants is 8, 10 or 16 the number of iterations are similar, no matter the value of /3. Interestingly, the number of iterations when f3 = 5 are greater than other values of /3. This may actually be a desirable behavior since we want to discourage the ants from converging on a solution too quickly because a quick convergence could mean the ants are not exploring enough of the search space.
35


Further Tuning It is hard to draw a deep conclusion from the tuning results
we have so far. Dorigo and Gambardella introduced the A-branching factor to help facilitate a deeper view of the effectiveness of parameter selections. The A-branching factor measures at each iteration the number of quality edges an ant has to choose from when it is on a given vertex in the search graph [DS04], This measure would give a much deeper viewer of the effects a group of parameter values have on creating a quality search space. At this time our ACS code is not able to produce information about the A-branching factor, although it would be a helpful addition in the future. Selecting Targets
We must determine the thickness, size, genus and Km to remove from the complement of a graph before we can apply the ACS search algorithm.
Lemma 5.1 The average vertex degree, D, of a graph, G, with thickness, 9 = 2, v vertices, and genus, g is:
D < 12 +
240 - 1)
(5.1)
Proof: By theorem 2.18, a planar graph, G of genus g has edges, e < 3(v — e). A planar graph of thickness, 9 = 2 has e < 2*3(u—e) edges. Simplified, e < 6v+12g —12.
The average vertex degree, D, of a graph, G, is: D = Substituting from above we have D < 2(6t,+12fl~12); and simplifying we obtain D < 12 + 24(-fl~1->. â– 
Theorem 5.2 Any graph, G, with average degree = d can be colored with at most d + 1 colors.
Proof: By way of contradiction, assume that any graph with average degree
d can not be colored with d + 1 colors. By induction, any graph, G, with d + 1 or
fewer vertices can be colored with d + 1 colors. Let G' be the graph of average vertex
degree d and one more vertex than G. Since G' has average vertex degree d, there
must exist at least one vertex of degree d — 1. Find this vertex, v and remove it from
G'. G' — v has d + 1 vertices, and by the induction hypothesis, can be colored with
36


d + 1 colors. Color G' — v with d + 1 colors. Add v back to G' — v. Since v has d — 1 neighbors, we will need at most d colors to color v and its neighbors. Thus G' can be colored with at most d + 1 colors, a contradiction. ■
Proposition 5.3 A graph, G with v vertices, chromatic number x and Km removed from the complement of G has v > (x ~ ^)(pi — 1).
Proof: By proposition 4.2, a graph, G with v vertices and Km removed from
the complement of G has chromatic number x(G) > \pf~i\i or \ppz\\ > (x — 1)-Rearranging the terms we arrive at v > (x — l)(m — 1). ■
For a given chromatic number, we can use lemma 5.1 and proposition 5.3 to help us determine which parameters we need to find a graph with a particular chromatic number.
Targets and Results
Is the chromatic number of any thickness two graph with genus g = 2
< 14?
We attempt to show that the largest chromatic number of a thickness two graph with genus g = 2 is 14 by finding a decomposition of Ku into two planar layers using our ACS implementation. First we determine the parameters:
By lemma 5.1, D < 12 + 24(q~1-> < 12 + ^. To reach x = 14, D > 13 by theorem
5.2, so 13 < 12 + ^ and 1 < By proposition 5.3, v > (14— 1 ){m— 1) > 13(m— 1). For m = 2, v > 13(2 — 1) > 13. With v = 14, 1 < || < 3.2 holds true.
Now we confirm the total edges in Ku are at most equal to the total potential edges in a graph with 9 = 2 and genus g = 2. Simplifying \E(KU)\ < 6v + 12g — 12 we reach 91 < 96 and we conclude that it is possible for K14 to have thickness 9 = 2 on genus g = 2.
Using our ACS implementation to remove K2 from the complement of the union of two triangulations, both with v = 14 on genus g = 2, we found a decomposition
37


of Ku (see Appendix C). We conclude that for thickness, 9 = 2, genus, g = 2, the largest possible chromatic number, y = 14.
Is the chromatic number of any thickness two graph with genus g = 3
< 15?
We attempt to show that the largest chromatic number of a thickness two graph with genus g = 3 is 15 by finding a decomposition of fd15 into two planar layers using our ACS implementation. First we determine the parameters:
By lemma 5.1, D < 12 + 24(y~1'1 < 12 + 44. To reach y = 15, D > 14 by theorem
5.2, so 14 < 12 + 44 anc[ 2 < 44. By proposition 5.3, v > (15 — 1 ){rri— 1) > 14(m— 1). For m = 2, v > 14(2 — 1) > 14. With v = 15, 2 < || < 3.2 holds true.
Now we confirm the total edges in K\5 are at most equal to the total potential edges in a graph with 9 = 2 and genus g = 3. Simplifying \E(K\5)\ < 6v + 12g — 12 we reach 105 <114 and we conclude that it is possible for K\5 to have thickness 9 = 2 on genus g = 3.
Using our ACS implementation to remove K2 from the complement of the union of two triangulations, both with v = 15 on genus g = 3, we found a decomposition of Ki5 (see Appendix C). We conclude that for thickness, 9 = 2, genus, g = 3, the largest possible chromatic number, y = 15.
Is the chromatic number of any thickness two graph with genus g = 4
< 16?
We attempt to show that the largest chromatic number of a thickness two graph with genus g = 4 is 16 by finding a decomposition of Kw into two planar layers using our ACS implementation. First we determine the parameters:
By lemma 5.1, D < 12 + 24(y~1'> < 12 + ^. To reach y = 16, D > 15 by theorem
5.2, so 15 < 12 + ^ and 3 < ^. By proposition 5.3, v > (16 — 1 )(m— 1) > 15(m— 1). For m = 2, v > 15(2 — 1) > 15. With v = 16, 3 < y§ < 4.5 holds true.
38


Now we confirm the total edges in K\& are at most equal to the total potential edges in a graph with 9 = 2 and genus g = 4. Simplifying \E(KW)\ < 6v + 12g — 12 we reach 120 < 132 and we conclude that it is possible for Kw to have thickness 6 = 2 on genus g = 4.
Using our ACS implementation to remove K2 from the complement of the union of two triangulations, both with v = 16 on genus g = 4, we found a decomposition of Kw (see Appendix C). We conclude that for thickness, 9 = 2, genus, g = 4, the largest possible chromatic number, y = 16.
Is the chromatic number of any thickness two graph with genus g = 5 < 17?
We attempt to show that the largest chromatic number of a thickness two graph with genus g = 5 is 17 by finding a decomposition of Ku into two planar layers using our ACS implementation. First we determine the parameters:
By lemma 5.1, D < 12 + 24(y~1') < 12 + ^. To reach y = 17, D > 16 by theorem
5.2, so 16 < 12 + ^ and 4 < ^. By proposition 5.3, v > (17— 1 )(m— 1) > 16(m— 1). For m = 2, v > 16(2 — 1) > 16. With v = 17, 4 < < 5.64 holds true.
Now we confirm the total edges in Ku are at most equal to the total potential edges in a graph with 9 = 2 and genus g = 5. Simplifying \E(Ku)\ < 6v + 12g — 12 we reach 136 < 150 and we conclude that it is possible for id17 to have thickness 9 = 2 on genus g = 5.
Using our ACS implementation to remove K2 from the complement of the union of two triangulations, both with v = 17 on genus g = 5, we found a decomposition of Ku (see Appendix C). We conclude that for thickness, 9 = 2, genus, g = 5, the largest possible chromatic number, y = 17.
Can we find additional graphs with chromatic number X = 9 having thickness 9 = 2 on genus <7 = 0?
39


By proposition 4.2, |~y] =9. Using the ACS implementation, we have produced 97 results with v = 17 vertices and K% removed from the complement. Of these, we have confirmed 2 as unique results(see Appendix C).
Does there exist a graph with chromatic number % = 10 having thickness 9 = 2 on genus g = 0?
By proposition 4.2, |~y] = [^1 = l~iyl = 10. We were unable to find any graphs with x = 10. Table 5.2 summarizes the results.
Table 5.2: Results For y = 10 Search
Vertices Kmremoved Fewest Km In Complement
19 3 5
28 4 6
29 4 55
Future Study
Our current work has been limited to graphs of relatively small size. We believe that more interesting results may be found by expanding the search to larger graph sizes. To accomplish this goal, we will need programs that make efficient use of memory and speed. We believe that an implementation of Tabu Search may be able to handle larger graphs than the current Ant Colony implementation. Implementations that are able to exploit parallel processing would also aid in exploring larger graph sizes.
Finding a way to enhance the current heuristic to evaluate more information about the search graph may also help to guide the search in a better way. To that end, creating a database of known graphs and their attributes may help to identify other good heuristic measures. Discovering as many graphs as possible, even if they do not provide us with new results, would be helpful in growing the size of the database. Big Data analysis techniques may also help once a database is generated.
40


BIBLIOGRAPHY
[ABG10]
[AH76]
[AH77]
[AHK77]
[Alal2]
[Ale98]
[BDHS97]
[BGS08]
[BLW76]
[Bre79]
[Broil]
[CDM91]
[DBS06]
[DEMHP08]
[DG97]
Michael O. Albertson, Debra L. Boutin, and Ellen Gethner. The thickness and chromatic number of r-inflated graphs. Discrete Math., 310(20):2725-2734, 2010.
K. Appel and W. Haken. Every planar map is four colorable. Bull. Arner. Math. Soc., 82(5):711-712, 09 1976.
K. Appel and W. Haken. Every planar map is four colorable, part i: Discharging. Illinois J. Math., 21(3):429-490, 09 1977.
K. Appel, W. Haken, and J. Koch. Every planar map is four colorable, part ii: Deducibility. Illinois J. Math., 21(3):491—567, 09 1977.
Roqyah R. Alalqam. Heuristic methods applied to difficult graph theory problems, 2012.
PS Alexandrov. Combinatorial topology. 1998.
Prosenjit Bose, Alice Dean, Joan Hutchinson, and Thomas Shermer. On rectangle visibility graphs, pages 25-44. Springer Berlin Heidelberg, Berlin, Heidelberg, 1997.
Debra L. Boutin, Ellen Gethner, and Thom Sulanke. Thickness-two graphs. I. New nine-critical graphs, permuted layer graphs, and Catlin’s graphs. J. Graph Theory, 57(3): 198—214, 2008.
Norman Biggs, E Keith Lloyd, and Robin J Wilson. Graph Theory, 1736-1936. Oxford University Press, 1976.
Daniel Brelaz. New methods to color the vertices of a graph. Cornmun. ACM, 22(4):251-256, April 1979.
Jason Brownlee. Clever Algorithms: Nature-Inspired Programming Recipes. Lulu.com, 1st edition, 2011.
A Colorini, M Dorigo, and V Maniezzo. Distributed optimization by ant colonies, the 1st european conf. Artificial Life, Pans, France, 1991.
Marco Dorigo, Mauro Birattari, and Thomas Stutzle. Ant colony optimization. IEEE computational intelligence magazine, 1 (4):28—39, 2006.
Alice M. Dean, Joanna A. Ellis-Monaghan, Sarah Hamilton, and Greta Pangborn. Unit rectangle visibility graphs. Electron. J. Cornbin., 15(1)Research Paper 79, 24, 2008.
M. Dorigo and L. M. Gambardella. Ant colony system: A cooperative learning approach to the traveling salesman problem. Trans. Evol. Comp, 1 (1):53—66, April 1997.
41


[Dha06]
[DHM03]
[DS04]
[Eng06]
[FM08]
[Gar80]
[GJ02]
[GL97]
[Glo89]
[Glo90]
[GP10]
[GS09]
[GT93]
[Hea90]
[HSV99]
[Hut 9 3]
Ashay Dharwadker. The vertex coloring algorithm, unpublished, 2006.
Mike Develin, Stephen Hartke, and David Petrie Moulton. A general notion of visibility graphs. Discrete Comput. Geom., 29(4):511—524, 2003.
Marco Dorigo and Thomas Stiitzle. Ant Colony Optimization. Bradford Company, Scituate, MA, USA, 2004.
Andries P Engelbrecht. Fundamentals of computational swarm intelligence. John Wiley & Sons, 2006.
Dario Floreano and Claudio Mattiussi. Bio-inspired artificial intelligence: theories, methods, and technologies. MIT press, 2008.
Martin Gardner. Mathematical games. Scientific american, 242:14-19, 1980.
Michael R Garey and David S Johnson. Computers and intractability, volume 29. wh freeman New York, 2002.
Fred Glover and Manuel Laguna. Tabu Search. Kluwer Academic Publishers, Norwell, MA, USA, 1997.
Fred Glover. Tabu searchpart i. ORSA Journal on computing, 1 (3): 190— 206, 1989.
Fred Glover. Tabu searchpart ii. ORSA Journal on computing, 2(1):4— 32, 1990.
Michel Gendreau and Jean-Yves Potvin. Tabu Search, pages 41-59. Springer US, Boston, MA, 2010.
Ellen Gethner and Thom Sulanke. Thickness-two graphs. II. More new nine-critical graphs, independence ratio, cloned planar graphs, and singly and doubly outerplanar graphs. Graphs Cornbin., 25(2): 197—217, 2009.
Fred Glover and Eric Taillard. A user’s guide to tabu search. Annals of operations research, 41 (1): 1—28, 1993.
P.J. Heawood. Map colour theorem. Quart. J. Pure Appl. Math., 24:332-338, 1890.
Joan P. Hutchinson, Thomas Shermer, and Andrew Vince. On representations of some thickness-two graphs. Comput. Geom., 13(3): 161—171, 1999.
Joan P. Hutchinson. Coloring ordinary maps, maps of empires and maps of the moon. Math. Mag., 66(4):211—226, 1993.
42


[JT78]
[JT95]
[Kem79]
[KW89]
[LR79]
[Man83]
[M0AO8]
[PR10]
[Rin59]
[RJ83]
[RY 68]
[She96]
[Sul06a]
[Sul06b]
Tommy R. Jensen and Bjarne Toft. Topological graph theory, in selected topics in graph theory, lw beineke and rj wilson, eds., 15-50, 1978.
Tommy R. Jensen and Bjarne Toft. Graph Coloring Problems. Wiley-Interscience Series in Discrete Mathematics and Optimization. John Wiley & Sons, New York, 1995.
Alfred B Kempe. On the geographical problem of the four colours. American journal of mathematics, 2(3): 193 200, 1879.
David Kirkpatrick and Stephen Wismath. Weighted visibility graphs of bars and related flow problems. Algorithms and Data Structures, pages 325-334, 1989.
Aristid Lindenmayer and Grzegorz Rozenberg. Parallel generation of maps: Developmental systems for cell layers. In Graph-grammars and their application to computer science and biology, pages 301-316. Springer, 1979.
Anthony Mansfield. Determining the thickness of graphs is np-hard. In Mathematical Proceedings of the Cambridge Philosophical Society, volume 93, pages 9-23. Cambridge Univ Press, 1983.
D. Marcus and Mathematical Association of America. Graph Theory: A Problem Oriented Approach. MAA textbooks. Mathematical Association of America, 2008.
Stuart Peter Russel. Norvig. Artificial Intelligence. A Modern Approach, 2010.
Gerhard Ringel. Fdrbungsprobleme auf Fldchen und Graphen, volume 2. VEB Deutscher Verlag der Wissenschaften, 1959.
Gerhard Ringel and Brad Jackson. Solution of heawood’s empire problem in the plane. Journal fur die reine und angewandte Mathematik, 347:146-153, 1983.
Gerhard Ringel and John WT Youngs. Solution of the heawood mapcoloring problem. Proceedings of the National Academy of Sciences, 60(2):438-445, 1968.
Thomas C Shermer. On rectangle visibility graphs, iii. external visibility and complexity. In CCCG, volume 96, pages 234-239, 1996.
Thom Sulanke. Generating irreducible triangulations of surfaces. arXiu preprint math/0606687, 2006.
Thom Sulanke. Triangulation manipulation software, 2006.
43


[SW03]
[TT86]
[WesOl]
[W0II6]
Ileana Streinu and Sue Whitesides. Rectangle visibility graphs: characterization, construction, and compaction. In STAGS 2003, volume 2607 of Lecture Notes in Comput. Set, pages 26-37. Springer, Berlin, 2003.
Roberto Tamassia and Ioannis G Tollis. A unified approach to visibility representations of planar graphs. Discrete & Computational Geometry, 1 (1) :321—341, 1986.
Douglas B. West. Introduction to graph theory, volume 2. Prentice Hall Upper Saddle River, 2001.
Wolfram Research, Inc. Mathematica, 2016.
44


APPENDIX A Triangle Generation
/*
main . c
entry point for t r i a n g u 1 a t i o n —g e n e r a t o r program
*/
#i n c1u d e #i n c1u d e #i n c1u d e #i n c1u d e
< s t d i o .h>
< s t d1i b .h>
< t r i a n g .h>
main ( int argc, char *argv [] )
{
// p° s i t i o n of command line ar g ume nt s
const int THICKNESS.ID X= 1 ;
const int NUM.VERTICES.IDX = 2;
const int GENUS.IDX = 3;
const int FILE.NAME.IDX = 4;
const int NUM.GROUPSJDX = 5 ; // optional argument
const int NUM_REQUIRED_ARGS = 5;
const int MAX.ARGS = 6 ;
// command line args , should use same type as required by sulanke functions
int thickness; // thickness of the graph, for each group generate this number of triang u 1 ations int num.vertices ; // number of vertices in the graph
int genus; // genus of the graph
int orient = 1; // 1 if the surface is orientable, 0 if not, use 1 as default char* file.name ; // name of the output file
int num.groups = 10; // how many groups of t r i a n g u 1 a t i o n s to generate , each group will have thickness number of t
// loop controls, triang, file stream args... int i , j ;
FILE * o u t f i 1 e ; struct triang t;
// seed random generation for use in create.triang srand (time( NULL ) ) ;
// check that # of arguments is correct
if (argc < NUM_REQUIRED_ARGS || argc > MAX_ARGS) {
// write error to console and exit
printf (” Too few or too many arguments . \ n%i arguments received . \nA minimum of %i is required and a maximum o f 1 return ;
}
// read command line values to variables thickness = atoi ( argv [THICKNESS.IDX] ) ; num.vertices = atoi (argv [NUM.VERTICES.IDX ] ) ;
genus = a t o i ( arg v [ GENUS.IDX ] ) ;
// if user specified optional 7th argument , set num.groups if (argc == MAX.ARGS) {
// set num.groups
num.groups = atoi (argv [NUM.GROUPSJDX] ) ;
}
45


// open file
outfile = fopen ( argv [ FILE_NAME_IDX ] , ” w” ) ;
// write first line to file
fprintf (outfile, ”%i,%i,%i,%i\n”, thickness, num.vertices , genus, num-groups);
for(i = 0; i < num_groups; i+ + ){ for(j = 0; j < thickness; j+ + ){
// generate triang u 1 ation
c r e a t e _ t r i a n g (&t , num.vertices , genus , orient );
// write triang lex to file write_triang_lex(&t, outfile); fprintf (outfile , ”\n”);
}
}
// be kind , close the file stream fclose ( outfile ) ;
}
/* include file to be used in user’s programs */
^include
^include < s t d 1 i b .h>
^include
#define MAX_V 128
#define MAX_E (MAX_V* (MAX_V-1) / 2)
#define MAX_F ( ( MAX_E / 3 ) * 2 )
#define MAX-CODE (MAX_E+MAX_E+MAX_V+4)
struct triang { /* t r i a n g u 1 a t i o n */
int nv; // # vertices
int ne ; // # edges
int nf; // # faces
int orient ; /* oriented? (not same as orientable) — 1 not yet determined */
int genus; /* genus of surface
(= number of handles or = number of crosscaps — 1 not yet determined */
i n t edge [MAX_V ] [MAX_V ]; // triangulation list [ROW] [ COL] and [COL ] [ROW] have different values, possible since any
};
void add.edge(struct triang * t , int vl, int v2);
void add_face(struct triang * t , int vl, int v2, int v3);
void canon(struct triang * t , char code [] , int mapping [ ] ) ; void canonlex(struct triang * t , char * t ex t ) ;
int can.contract(struct triang * t , int vl, int v2, int *ol, int *o2);
int check.triang(struct triang * t , char * caller );
46


void clear.triang ( struct triang * t , int v) ;
void contract.edge(struct triang * t , int vl, int v2, int ol , int o2 ) ;
void copy.triang ( struct triang *s , st ruct triang *t );
int count.triang ( struct triang * t);
int count_triang2 ( struct triang *t );
void create.triang ( struct triang * t , int v, int genus, i nt orient ) ;
void c r e a t e _t r i a n g 4 ( s t r u c t triang * t , int v, int genus, int orient ) ;
void cut.handle(struct triang * t , int v1, int v2, int v3 . ; nt v4 ) ;
void cycle.type ( struct triang * t , int v [MAX-V] , i n t n , i nt * type , int
int decode.triang (char *text , struct triang *t);
int d e c o d e _t r i a n g _ 1 e x ( c h ar *text , st ruct triang *t );
int decode_unfold_triang(char * text , struct triang * t , int border [ MAX_V ] [ MAX_V ] ) ;
void encode_planar_code(struct triang * t , char code [] ) ;
int find_flip(struct triang * t , int vl, int v2, int * v3 , int *v4);
void flip_edge(struct triang * t , int vl, int v2, int v3, int v4 ) ;
void get.complement (struct triang *t);
int near.triang ( struct triang *t);
int opposite( struct triang * t , int vl, int v2, int v3); void permute_triang(struct triang * t , int vl, int v2); void print.ascii ( struct triang *t);
void p r i n t _ n e i g h b o r s ( s t r u c t triang *t); void print.triang ( struct triang *t);
void ran_flip_triang(struct triang * t , int ntimes);
int read.triang ( struct triang *t);
int r e a d _t r i a n g _ 1 e x ( s t r u c t triang *t);
int reduce.triang (struct triang * t , int nv) ;
int reduce_triang4(struct triang * t , int nv ) ;
void remove_degree3.vertex ( struct triang * t , int v ) ;


void remove.face( struct triang * t , int vl , int v2, int v3);
void s c r a m b 1 e _t r i a n g ( s t r u c t triang *t);
void split.vertex(struct triang * t , int vl, int v2, int v3, int v4);
void testcanon.first.init.triang (struct triang * t , int givenedge [3] , int representation [], int mapping [] , int colou
void testcanon_init_triang(struct triang * t , int givenedge [3], int representation [], int mapp ing [], int colour []);
void unfold.canon ( struct triang * t , int border [MAX_V ] [ MAX_V] , int *nv_unfold , char code [] , int mapping [ ] ) ;
void unfold_testcanon_init(struct triang * t , int nv_unfold, int v.border [ MAX_V ] , int r.border [ MAX_V ] , int border.lei
void unfold_triang(struct triang * t , int border.length , int v.border [MAX_V] , int *nv_unfold , char code [] , int map pi
int write_triang_lex(struct triang * t , FILE * outfile);
static int a2i[128] = {
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
to ,27 ,28 ,29 ,30 . ,31 . ,32,33,34,35,36, 37 , 38 , 39 , 40 , 41 , 42 , 43 , 44 , 45 . ,46 , 47 . ,48 . ,49 , 50 , 51, -1,-1, -1,-1
1, 0 , 1 , 2 , 3 , 4 . , 5 co to o ,11 ,12 ,13 ,14 ,15 ,16 ,17 ,18 ,19 ,20 ,21 ,22 ,23 ,24 to Cn 1 1 1 1
static char i 2 a [52] = {
’ a ’ , ’ b ’ , ’ c ’ , ’ d ’ , ’ e ’ , ’ f ’ , ’ g ’,’h’,’i’,’j’ , ’k’ , ’ 1 ’ , ’ m’ , ’ n ’ , ’ o ’ . ■ ’ p ’ , ’ q ’ , , ’ r ’ , ’s’ , ’ t ’ . , ’ u ’ . , ’ V ’ ; , ’ w’ , ’ x ’ . . ’ y ’ s , ’ z
’A’ , ’ B ’ , ’C’,’D’, ’E’,’F’,’G ’ , ’ H’ , ’ I ’ , ’ J ’ , ’K’ , ’L’ , ’M’ , ’N’ , ’O’ . ■'P',’Q’: , ’R’ , ’S’,’T’. , ’U’ . , ’V’ . , ’W , ’X’ . , ’Y’ . , ’Z
/ * add one face to a triangu lation * /
^include
void add.face(struct triang * t , int vl, int v2, int v3)
{
#if DEBUG
if (v 1 == v 2 || v 1 == v 3 || v 2 == v 3) {
printf(” add.face: vertices ( %d , %d and %d) must be distinct. \ n”, vl ,v2 ,v3 ) ; exit ( 0 ) ;
}
if (vl < 0 || vl >= t—>nv | |
v2 < 0 || v2 >= t—>nv | |
v3 <0 || v3 >= t—>nv) {
printf (” add.face : vertex (%d , %d or %d) out of range, must be between 0 and %d . \ n ” ,
vl , v2 , v3 , t—>nv ) ; exit ( 0 ) ;
}
|end i f
if ( t —>orient == 1) {
#if DEBUG
if (t—>edge [ vl ] [ v2 ] != —1) {
printf (” add-face: can’t add face (%d,%d,%d). a face (%d,%d,%d) already exists. \ n”,
48


vl,v2,v3,vl,v2,t—>edge[vl][v2]); exit ( 0 ) ;
}
if (t—>edge[v2][v3] != —1) {
printf(”add_face: can’t add face (%d,%d,%d). a face (%d,%d,%d) already exists.\n”, vl,v2,v3,v2,v3,t—>edge[v2][v3]); exit ( 0 ) ;
}
if (t—>edge [ v3 ] [ vl ] != —1) {
printf(”add_face: can’t add face (%d,%d,%d). a face (%d,%d,%d) already exists ,\n” , vl,v2,v3,v3,vl,t—>edge[v3][vl]); exit ( 0 ) ;
}
|end i f
t—>edge[vl][v2] = v3; t—>edge[v2][v3] = vl; t—>edge[v3][vl] = v2;
}
else {
#if DEBUG
if (t —>edge [vl] [v2] != —1 && t—>edge [v2 ] [ vl ] != —1) {
printf(”add_face: can’t add face (%d,%d,%d). faces (%d,%d,%d) and (%d,%d,%d) already exist.\n
vl,v2,v3,vl,v2,t—>edge [vl][v2],v2,vl,t —>edge [v2] [vl] ) ; exit ( 0 ) ;
}
if (t —>edge [v2][v3] != —1 && t—>edge [v3][v2] != —1) {
printf(”add_face: can’t add face (%d,%d,%d). faces (%d,%d,%d) and (%d,%d,%d) already exist.\n
vl,v2,v3,v2,v3,t—>edge [v2][v3],v3,v2,t —>edge [v3] [v2] ) ; exit ( 0 ) ;
}
if (t —>edge [v3] [vl] != —1 && t—>edge [vl ] [ v3 ] != —1) {
printf(”add_face: can’t add face (%d,%d,%d). faces (%d,%d,%d) and (%d,%d,%d) already exist.\n
vl ,v2 ,v3,v3,vl ,t—>edge [v3][vl],vl,v3,t —>edge [vl] [v3] ) ; exit ( 0 ) ;
}
|end i f
if (t—>edge [ vl ] [ v2 ] == —1) t—>edge[vl][v2] = v3; else
t—>edge[v2][vl] = v3;
if ( t —>edge [ v2 ] [ v3 ] == —1) t—>edge[v2][v3] = vl; else
t—>edge[v3][v2] = vl;
if (t—>edge [ v3 ] [ vl ] == —1) t—>edge[v3][vl] = v2;
else
t—>edge[vl][v3] = v2;
}
49


( t —> n f ) + +;
}
/* remove all edges from a t r i a n g u 1 a t i o n */
^include
void clear.triang ( struct triang * t , int nv)
{
int vl ,v2 ;
if (nv <0 || nv > MAX_V) {
printf(” clear.triang : nv (%d) out of range. must be between 0 nv , MAX.V) ; exit ( 0 ) ;
}
t—>nv = 0; t—>ne = 0; t —> n f = 0 ;
for ( vl =0 ; vledge [ v 1 ] [ v2 ] = —1;
}
/* create a triang u 1 ation of a sphere with handles and/or crosscaps vertices */
^include
void create.triang(struct triang * t , int nv, int genus, int orient)
{
int vl,v2,v3,v4,v5,v6,v7; int ih ;
int handles , crosscaps , ec; int ne;
if (genus < 0) {
printf (” create.triang : The genus ( %d ) must be non— negative.\n” , genus); exit ( 0 ) ;
}
if (orient) { orient = 1;
handles = genus; crosscaps = 0; ec = 2—2*genus;
}
else {
orient = 0;
handles = (genus—1)/2; crosscaps = ((genus—1) % 2) + 1; ec = 2—genus;
}
and %d .\n”
with nv


/* test that input is in range */
ne = 3 * ( nv—ec ) ; if ( ne > MAX_E) {
printf (” create.triang : number of edges too large (%d). increase MAX_E. \ n” , ne ) ;
exit ( 0 ) ;
}
if ( ( nv * ( nv — 1) )/2 < ne) {
printf (” create.triang : The number of vertices ( %d ) is too small to create a triangulation\n\ on a surface with Euler characteristic %d.\n\
The number of edges in K%d is %d but the number of edges in a t r i a n g u 1 a t i o n s is %d ■\n” , nv , ec , nv , ( nv * ( nv — l))/2,ne); exit ( 0 ) ;
}
/*
if (nv < 4 + 3*handles + 2* crosscaps)
{
printf(” create.triang : The number of vertices (%d) is too small create a t r i a n g u 1 at i o n \ n\ on a surface with %d handles and %d c r o s s c a p s . \ n\
I only know how t o make triangulations with %d (4+3*h + 2*c) vertices . \ n ” , nv , handles , crosscaps ,4+3* handles+2*crosscaps ) ; exit ( 0 ) ;
}
*/
if (nv + 3 > MAX.V) {
printf (” create.triang : number of vertices too large (%d). increase MAX.V. \ n ” , nv ) ;
exit ( 0 ) ;
}
clear.triang (t , nv + 3 ) ;
/* create tetrahedron */
t —> orient = 1; t —> genus = 0; t—>nv = 4;
add.face(t,0,1,2); add.face(t,0,2,3); add.face(t,0,3,1); add.face(t,1,3,2);
t—>ne = 6;
/* add handles */
for ( ih =0 ; ih /* pick a random edge. add handle to connect the adjacent faces */
/*
51


sew this onto
7....7
â– \ - I / I /
â–  \ 1 / /
1 / / /â– 
â–  /1 \ - / i â– 
â–  / 1 \ 1 / 1. \ i /
â–  / / 4 / â–  1
â–  \- 1 / / â–  \
â–  \ 1 / â–  / :
â–  / / 6 . \ / :
â–  1 /1 \ - -4 :
â–  \l / i â–  / \ :
â–  3 / / / â–  \ :
â–  / 1 \ - / i â–  W
â–  1 \ 1 / / 2
â– / 2 / /â–  /1 \
â–  1 / 1 \ - i / â– 
â–  1 / \ i / â– 
â–  / / 5 /
â–  / /I \ -
â– / / 1 \
7 7
*/
t—>genus += 1;
vl = 0; v2 = 0;
while ( ( v3=t —>edge [ v2 ] [ vl ] ) = vl = rand() % (t—>nv); v2 = rand() % (t—>nv);
}
v4 = t—>edge[vl][v2]; v5 = (t—>nv) + + ; v6 = (t—>nv) + + ; v7 = (t—>nv) + + ;
remove .face (t vl ,v2 ,v4 ) ;
remove .face (t v2 ,vl ,v3 ) ;
add _fac e t , vl v7 , v2 ) ;
add _fac e t , vl v2 , v5 ) ;
add _fac e t , vl v5 , v4 ) ;
add _fac e t , v4 v5 ,v7);
add _fac e t , v4 v7 , v6 ) ;
add _fac e t , vl v6 ,v7);
add _fac e t , vl v3 , v6 ) ;
add _fac e t , v2 v4 , v6 ) ;
add _fac e t , v2 v6 , v5 ) ;
add _fac e t , v3 v5 , v6 ) ;
add _fac e t , v3 v7 , v5 ) ;
add _fac e t , v2 v7 , v3 ) ;
this
\
\ /
3-
/ \
/
-1) {
52


t—>ne += 1 5 ; reduce.triang (t , nv ) ;
}
/* add crosscaps */
if (! orient) { t —> orient = 0; t —> genus = 2 * (t —> genus);
for (ih=0;ih add crosscap in whole left by
sew this onto this
\ i /

/ \ / 1
/ \ / / â–  \
/ \ / / : \
\ / \ / \ / : \ /
3 4 | -4 : 3-
/ \ / \ / \ : / \
\ / \ \ : /
\ / \ W
1/ \ / \l 2
5---------------2---------------6 / | \
(t—>genus) + +;
vl = 0; v2 = 0;
while ( ( v3=t —>edge [ v2 ] [ vl ] ) == —1) { vl = rand() % (t—>nv); v2 = rand() % (t—>nv);
}
v4 = t —>edge [vl] [v2] ; v5 = (t—>nv) + + ; v6 = (t—>nv) + + ; remove_face(t ,vl ,v2 ,v4);
53


remove_face(t ,v2 ,vl ,v3);
add_face(t,vl,v3,v6); add.face(t,vl,v5,v4); add_face(t,v3,v5,v6); add.face(t,v4,v5,v6); add.face(t,v2,v5,v3); add_face(t,v2,v4,v6); add_face(t,vl,v5,v2); add_face(t,vl,v2,v6);
t—>ne += 9; reduce.triang (t , nv ) ;
}
/* add additional vertex , n, by placing it inside random face */
while (t—>nv < nv) {
vl = rand () % (t—>nv); v2 = rand () % (t—>nv); if ((v3=t—>edge[vl][v2]) != —1) {
v4 = (t—>nv) + +; remove-face (t ,vl ,v2 , v3 ) ; add.face(t,vl,v2,v4); add.face(t,vl,v4,v3); add.face(t,v2,v3,v4); t —> n e += 3 ;
}
}
}
/* find the other diagonal of the q u a d r a 1 a t e r a 1 created when the edge is removed */
^include
int find_flip(struct triang * t , int vl, int v2, int *ol, int * o 2 )
{
/* find the other two corners */
#if DEBUG
i f (t—>edge [v1 ] [v2] == —1 | | t —>edge [v2] [vl] == —1) {
printf(” find_flip: corrupted faces at edge (%d,%d)\n”,vl,v2); exit ( 0 ) ;
}
|end i f
* ol = t —>edge [vl] [v2] ;
* o2 = t —>edge [v2] [vl] ;
/* check for the possibility that the other two corners already form an edge */
if ( t—>edge [ * ol ] [ * o2 ] != —1)
return 0;
54


return 1;
}
/* interchange an edge for the other diagonal of the quadra1atera 1 created when the edge is removed */
^include
void flip_edge(struct triang * t , int vl , int v2, int ol , int o2)
{
/* remove the old faces */
remove-face (t , vl ,v2 , ol ) ; remove-face (t ,v2 , vl , o2 ) ;
/* replace them with new ones */
add_face(t,ol,o2,v2); add_face(t,o2,ol,vl);
}
/* randomly flip edges of a triang u 1 ation without increasing the degree of the last vertex */ ^include
void { int ran_flip_triang _e x c lude ( struct triang * t , int nt i me s )
vl , v2 , v3 , v4 ; /* vertex numbers * /
int nflips ; /* number of successful fl ip s */
int nr an ; /* number of random pairs generated */
/* pick a random edge */
nflips nr an =
= 0; 0;
while (nflips0)) {
vl = rand () % t—>nv; v2 = rand () % t—>nv; nran + + ;
/* if it is really an edge , can be flipped , and
does not increase the degree of the last vertex then flip it . */
/* if it is really an edge, ... */
if (t—>edge [ vl ] [ v2 ] != —1) {
/* ... can be flipped, ... */
if ( find_flip (t , vl ,v2,&v3,&:v4))
/* ... and does not increase the degree of the last vertex ... */
55


if (v3 != t—>nv — 1 && v4 != t—>nv — 1) { nflips+ + ;
flip.edge (t ,vl ,v2 ,v3 ,v4) ;
if (v 1 == t—>nv — 1 || v2 == t—>nv — 1) nflips = 0;
}
}
}
}
/* reduce the number of vertices in a triangulation to nv * /
/* fl ip edges until vertex has degree 3 then remove it , repeat */
/* return 1 if successful , return 0 i f can’ t red uce to nv * /
#incl ude
int / r educe.triang ( struct t r i a n g * t , i n t nv )
\ nt vl , v2 , v3 , v4 ; /* vertex numbers * /
nt degree ,prev.degree; /* degree of vertex to be removed * /
nt trys ; /* number of trys so far * /
nt nei [MAX-V] ; /* ne ig h b ors of vl */
nt i n e i ; /* ne ig hb or index */
nt X; /* Euler characteristic */
nt vmin ; /* the minimum n such that there exist a
triang u 1 ation on the surface with n vertices
/* test if theoretically possible */
if ( t —>orient == 1)
X = 2 — 2 *(t—>genus) ; else
X = 2 — t —> genus ;
/*
vmin = c e i 1 ( (7 + s qr t (49 — 24*X ) ) / 2 ) ;
*/
vmin = 4;
while ( ( vmin — 3) * ( vmin —4) < 6*(2— X) ) vmin + + ;
f ( ( t —> orient == 1 t —> genus 2)
( t —> orient == 0 && t—> genus 3)
( t —> orient == 0 t—> genus == 2))
vmin + + ;
if (nv < vmin) {
printf(”reduce_triang: can’t reduce a triangulation on a surface with genus %d and orientation %d to %d exit ( 0 ) ;
}
/* remove extra vertices if possible */
while (t—>nv > nv) { vl = t—>nv — 1;
degree = 0;
v e r t i c e
56


for (v2=0; v2 i f (t—>edge [vl][v2] != —1)
nei[degree++] = v2; t r y s = 0 ;
while (degree > 3) {
if (trys++ > 100 * t—>ne) return 0;
inei = r and () % d eg r ee ; v2 = nei [ inei ] ;
if ( find_flip (t ,vl ,v2,&v3,&:v4)) flip_edge (t ,vl ,v2 ,v3 ,v4) ; else
ran_flip_triang_exclude(t ,t —>ne);
prev_degree = degree; degree = 0;
for (v2=0; v2 if (t —>edge [vl] [v2] != —1)
nei [ degree++] = v2 ; if (degree < prev.degree) trys = 0;
v2 = ne i [0] ; v3 = t —>edge [vl] [v2] ; v4 = t —>edge [v2] [vl] ; remove_face(t ,vl ,v2 ,v3); remove_face(t ,vl ,v3 ,v4) ; remove_face(t ,vl , v4 , v2 ) ; add_face(t,v2,v3,v4);
(t—>nv) ;
t —> n e = t —> n e — 3 ;
return 1;
}
/* remove one face to a t r i a n g u 1 a t i o n */ ^include
void remove_face( struct triang * t , int vl, int v2, int v3)
{
if ( t —>orient == 1) {
#if DEBUG
if ( t —>edge [ vl ] [ v2 ] ! =
t —>edge [ v2 ] [ v3 ] ! =
t —>edge [ v3 ] [ vl ] ! =
printf(” remove.face vl ,v2 ,v3 ) ; exit ( 0 ) ;
}
#en d i f
v3 || vl | | v2) {
orientable face (%d , %d , %d ) does not exist or
is corrupted. \ n”,
57


t—>edge [vl] [v 2] t—>edge[v2][v3] t—>edge[v3][vl]
= -i; = -i; = -i;
>
else { #if DEBUG
f ((t—>edge[vl][v2] != v3 t—>edge [v2] [vl ] != v3)
(t—>edge[v2][v3] != vl && t—>edge [v3] [v2 ] != vl)
(t—>edge[v3][vl] != v2 t—>edge [vl] [v3 ] != v2 ))
print f (” remove.face : n o n o r i e n t ab 1 e face ( %d , %d , % d ) does not exist or vl ,v2 ,v3 ) ; exit ( 0 ) ;
}
#en d i f
s corrupted.\n”,
if (t —>edge [vl] [v2] == v3) t —>edge [ v 1 ] [ v2 ] = —1;
else
t —>edge [ v2 ] [ v 1 ] = —1;
if (t —>edge [v2] [v3] == vl) t—>edge [v2][v3] = —1; else
t—>edge [v3][v2] = —1;
if (t —>edge [v3] [vl] == v2) t—>edge [v3] [vl] = —1;
else
t—>edge [vl ] [v3] = —1;
( t —> n f )-;
}
/* output a t r i a n g u 1 a t i o n in lex format (not necessarily minimum (canonical)) */
^include
^include
#define LINELEN 2000
int write_triang_lex(struct triang * t , FILE *outfile)
{
char text [LINELEN] ; int ichar; int vO , v 1 ;
for (v0 = 0; v0nv —2; v0-|—|-)
for (vl=v0 + l; vlnv — 1; vl-|—|-) i f ( t —>edge [ vO ] [ vl ] != —1)
if (t—>edge[vO][vl] < t—>edge[vl][vO]) { i f (t—>edge [vO] [vl] > vl)
fprintf(outfile , ” %c%c%c ” , i 2 a [ vO ] , i 2 a [ vl ] , i 2 a [ t —>edge [ vO ] [ vl ] ] ) ; i f (t—>edge [vl ] [vO] > vl)
fprintf(outfile , ” %c%c%c ” , i 2 a [ vO ] , i 2 a [ vl ] , i 2 a [ t —>edge [ vl ] [ vO ] ] ) ;
}
else {
58


f (t—>edge[vl][vO] > vl)
fprintf(outfile , ” %c%c%c ” , i 2 a [vO] , i 2 a [ vl ] , i 2 a [ t —>edge [ vl ] [ vO ] ] ) ; f (t—>edge[vO][vl] > vl)
fprintf(outfile , ” %c%c%c ” , i 2 a [vO] , i 2 a [ vl ] , i 2 a [ t —>edge [ vO ] [ vl ] ] ) ;
59


APPENDIX B Ant Colony
/*
main . c
This is just a test file for verifying ant colony code is working
^include
^include
^include
^include
^include
^include < s t d1 i b . h>
^include
^include < s i g n a1 .h>
void sigint_handler(int);
void main(int argc, char* argv [] )
{
int v , vl , v2 , v3 , v4 , count , temp , temp2 ; int i, j; // loop controls
char line [LINE-SIZE] ; // hold line of input
int n u mb er _o f _gr o up s ; // number of t r i a n g u 1 a t i o n groups in file , there will be thickness * n u mb er _o f _gr o up s lines FILE * infile ;
FILE * o u t f i 1 e ;
signal ( SIGINT , sigint.handler ) ;
// user can pass in input file/output file , n u m _ v e r t i c e s _ i n _ c 1 i q u e s , or all arguments if (argc == COMMAND_LINE_MIN_COUNT | | argc == COMMAND_LINE_MAX_COUNT + 1 ) { initialize.log.function ();
initialize.command_line.parameters( argc , argv);
// init file streams
infile = fopen ( argv [ INPUT_FILE_POS ] , ” r ” ) ; outfile = fopen ( argv [OUTPUT_FILE_POS] a” ) ;
// check for errors opening files if ( infile == NULL) {
pr int f (” Error reading input file\n”); return ;
}
if ( outfile == NULL) {
printf(” Error opening output file\n”); return ;
}
// read line , init thickness , number of vertices and genus fgets(line , LINE-SIZE, infile);
sscanf ( line , ”%d,%d,%d,%d” , ^thickness , &vertex_count , &genus , &number_of_groups ) ;
// init tau, global variable in triang.h
60


// a nt _c o 1 o n y / i n i t i a 1 i z e _ a r r a y s resets tau during every loop of acs // allocate first level of tau
tau = (long double **) malloc ( vertex.count * s izeo f ( long double*));
// allocate second level of tau for(i = 0; i < vertex-count; i -\—|-)
tau [ i ] = (long double *) malloc ( vertex.count * s izeo f ( long double));
// init orient , should always be 1 orient = 1;
// print first line of output file
fprintf(outfile , ”%d,%d,%d,%d, alpha: %f , beta: %f , number of ants: %d \ n” , vertex.count , num.of.vertices.in.
// loop through t r i a n g u 1 a t i o n input for ( i = 0; i < number.of.groups ; iH—|-) { struct triang t, 11 , t2;
// buffers for triang inputhold triang input line char triangl [LINE-SIZE] ; char triang2 [LINE-SIZE] ;
// read triangs
fgets (triangl , LINE-SIZE , i n f i 1 e ) ; fgets(triang2 , LINE-SIZE , i n f i 1 e ) ;
// convert to triang structs decode_triang_1ex(triang1 , &tl); decode_triang_1ex ( triang2 , &t2);
// merge triangs merge_2_triang(&t , & 11 , & t 2 ) ;
// run ACS
ant_colony_system(&t , &t 1 , &t 2, outfile);
}
// close files fclose(infile); fclose (outfile ); fclose( log-file);
// free pheromone array
for(i = 0; i < vertex.count ; i H—|-)
{
free ( tau [ i ]) ;
}
free(tau);
return ;
} else {
// exit , need more arguments
61


printf(”%i arguments entered , but %i or %i arguments required . Please try again . \ n” , argc — return ;
}
void s i g i n t _ h a n d 1 e r ( i n t sig)
{
/ * do something*/
/ * printf(” Killing process %d\ n”,getpid()); printf(” Cleaning . . . \ n ” ) ; * /
fclose ( log_file); exit ( 0 ) ;
}
/*
ant.colony .h
ant colony system function signature
this file only contains one function whose purpose is to run ant colony system algorithm
*/
#ifndef ANT_COLONY_H #define ANT_COLONY_H
^include
^include < s t d 1 i b .h>
^include
^include
^include
^include
void ant_colony_system(struct triang *t, struct triang *tl, struct triang *t2, FILE * successfile
// select an edge using ant colony system formulas int a n t _ c o 1 o n y _ s y s t e m _ s e 1 e c t i o n ( Ant *MyAnt);
void a n t _ c o 1 o n y _ s y s t e m _ s a v e _ s e 1 e c t i o n ( Ant *MyAnt, int idx.to.save ) ;
// determine the heuristic cost of every possible edge flip available to an ant
void ant.colony.system.tour.construction (Ant* My Ant, struct triang *t, struct triang * 11 , struct
int a r e _t r i a n g _ e q u a 1 ( s t r u c t triang triangl , struct triang triang2);
double calculate.initial.pheromone (Ant MyAnt ) ;
// check if a solution with 0 complements exist void check.for.solution () ;
// Display the parameters used in the any colony system algorithm void display.parameters () ;
// find the best tour among a group of tours void find_best_tour (Ant MyAnt, Solution *BestSol);
// clean up pointers
, COMMAND-LINEJM1N
);
triang *t2);
62


void f r e e _ a r r a y s ( Ant * MyAnt, Solution *sol , int n u m _ ve r t i c e s ) ;
// update the pheromone matrix shared among all ants void global.pheromone.update ( Solution BestSol);
void initialize_ant_parameters(struct triang * t , struct triang * 11 , struct triang * t 2 , int num.vertices // Initialize dynamic arrays
void initialize.arrays (Ant * * My Ant, struct triang t, struct triang 11 , struct triang t2);
// Before beginning , determine what a baseline best solution is for comparison // edge_limit : max # of edges in flippable edge list
void initialize_best_solution(Solution * S o 1 , struct triang 11 , struct triang t2);
void local.pheromone.update ( int vl , int v2);
void log_ant_end(FILE * f , Solution * s , int iterations);
void log_ant_start(FILE * f , struct triang * 11 , struct triang * t 2 ) ;
void print.ant.parameters (FILE *f);
void print _tau ( long double * * t au , int length);
// Print the tour cost
void print.the.tour.cost (Ant My Ant, int idx);
// find the best subset of an ant ’ s tour void prune.tour (Ant *MyAnt);
// reset ant values
void reset.ant (Ant * MyAnt, struct triang t, struct triang 11 , struct triang t2); void reset.tau ( int num.vertices);
int Ro u le 11 e W hee 1S e 1 e c t io n ( Ant MyAnt, int dupTimes);
|end i f
/*
ant.structs .h
struct definitions for ant algorithms
*/
#ifndef ANT_STRUCTS_H #define ANT_STRUCTS_H
#define ARRAY-SIZE 100
^include
typedef struct Ant{
struct triang t , 11 , t 2 ;
//int * Tour ;
int TourCnt; // !!! gives length of tour on initial tour construction, after
int * Cost ; // Cost of each edge in ListFE, after prune.tours , Cost [TourCnt —
prune.tours ListFE[0] to 1] contains best cost of
int arg c ,
li st F E [ Tour the tour
63


int **ListFE; // edge flipped at each step , an array of 2 ints representing the edge endpoints
int *FE_Layer; // layer an edge in ListFE belongs to
// Temp Values used for building ant tour
int * * ListFE_TMP ; // a list of flippable edges for the current iteration , each member is an array
int *FECost; // cost of each flippable edge in ListFE-TMP int * ListFE.Layer ; // layer an edge in ListFE.TMP belongs to
int ListFECnt ; // number of edges in ListFE.TMP
int ListFEMax ; / / TODO: don’t believe this variable ever used, ok to delete?
long double *P; // array of probabilities for roulette wheel selection
} Ant ;
typedef struct Solution{ struct triang 11 , t 2 ;
int **ListFE; // edge flipped at each step , each edge represented as array of 2 ints representing
int *FE_Layer; // layer an edge in ListFE belongs to
int TourCnt; // length of tour
int idx; // TODO: don’t believe this variable ever used, ok to delete?
int Cost; // # of triangles in complement of tl U t2
int ListFEMax; // TODO: don’t believe ever used, ok to delete?
} Solution;
// use list of edge flips to generate triang u 1 ations void b u i 1 d _ s o 1 u t i o n _ 1 a y e r s ( S o 1 u t io n *s);
// clean up pointer in Ant void free.ant (Ant * ant ) ;
// clean up pointers in Solution void free_solution(Solution * sol ) ;
// edge_limit : maximum number of edges in flippable edge list Ant init.ant ();
|end i f
/*
constants .h
store constant values used throughout the program
*/
#ifndef CONSTANTS_H #define CONSTANTS_H
// number of command line arguments
s t a t: i c const int COMMAND-LINE JVIIN_COUNT = 4;
s t a t: i c const int COMMAND JliINEJMAX_COUNT = 11
/ / Command L i ne Positions
s t a t: i c const int INPUT_FILE_POS = 1;
s t a t: i c const int OUTPUT_FILE_POS = 2 ;
s t a t: i c const int VERTICES_IN_CLIQUES_POS = : 3
s t a t: i c const int ALPHA.POS = 4;
o f two ints , re
edge endpoints
64


s t a t i c const int BETA.POS = 5;
s t a t i c const int RHO-POS = 6 ;
s t a t i c const int QO.POS = 7;
s t a t i c const int XI.POS = 8;
s t a t i c const int EDGE_LIMIT_POS = 9;
s t a t i c const int NUM_ANTS_POS = 10;
s t a t i c const int MAX_ITERATIONS_POS =11
// Input File Positions
s t a t i c const int THICKNESS-POS = 0;
s t a t i c const int NUM_VERTICES_POS = 1;
s t a t i c const int GENUS.POS = 2;
// maximum chars to read from one line of file static const int LINE-SIZE = 1000;
#en d i f
/*
t r i a n g . h
A paired down version of the sulanke code Include only the functions that we need
*/
#ifndef TRIANG-H #define TRIANG_H
^include
^include < s t d 1 i b .h>
^include
#define MAX_V 128
#define MAX_E (MAX_V* (MAX_V-1) / 2)
#define MAX_F ( ( MAX_E / 3 ) * 2 )
#define MAX-CODE (MAX_E+MAX_E+MAX_V+4)
/***** VARIABLE DEFINITIONS *****/
FILE * log_file ;
int nAnt , vertex.count , EDGE-LIMIT, num_of_vertices_in_cliques , int genus, orient, thickness; float Q0, alpha, beta, rho, Xi; int MAXJTER;
long double **tau;
double tauO ;
struct t r i a n g { /* t r i a n g u 1 a t i o n */
int nv ;
int ne ;
int nf ;
int orient ; /* oriented? (not same as orientable) , — 1 not yet determined */
int genus; /* genus of surface
(= number of handles or = number of
— 1 not yet determined */
int edge [MAX-V] [MAX_V] ;
int nfe; // number o f flippable edges
NNSolution ;
s c ap s
65


};
static int a2i[128] = {
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
to ,27 ,28 ,29 ,30 . ,31 . ,32,33,34,35,36, 37 , 38 , 39 , 40 , 41 , 42 , 43 , 44 , 45 . ,46 , 47 . ,48 . ,49 , 50 , 51, -1,-1, -1,-1
1, 0 , 1 , 2 , 3 , 4 . , 5 co to o ,11 ,12 ,13 ,14 ,15 ,16 ,17 ,18 ,19 ,20 ,21 ,22 ,23 ,24 to Cn 1 1 1 1
static char i 2 a [52] = {
’a’,’b’,’c’,’d’,’e’,’f’,’g’,’h’,’i’
’A’,’B’,’C’,’D’,’E’,’F’,’G’,’H’,’I’
/***** FUNCTION SIGNATURES *****/
void add.edge(struct triang * t , int vl, int v2);
// add one face to a triang u 1 ation
void add.face(struct triang * t , int vl, int v2, int v3);
int check.triang ( struct triang * t , char * caller ) ;
// remove all edges from a t r i a n g u 1 a t i o n void clear.triang ( struct triang * t , int v) ;
// Generate a t r i an g u 1 a t io n
void create.triang(struct triang * t , int nv, int genus, int orient);
/* create a t r i a n g u 1 a t i o n using lex format input */ int deco d e _t riang_1ex (char *text , struct triang *t);
j ’ , ’k’ , ’ 1 ’ , ’ m’ , ’n ’ . , ’ o ’ . ■ ’ P ’ : , ’ q ’ , , ’ r ’ , ’ s ’ , ’ t ’ . , ’ u ’ . , ’ V ’ ; , ’ w’ , ’ x ’ . . ’ y ’ s , ’ z
J ’ , ’K’ , ’L’ , ’M’ , ’N’ . , ’O’ . , ’ P ’ ; , ’Q’ , , ’R’ , ’ S ’ , ’T’ . , ’U’ . , ’V’ ; , ’W , ’X’ . , ’Y’ . , ’Z
void get.int ( char prompt [] , int * integer ) ;
/* find the other diagonal of the q u a d r a 1 a t e r a 1 created when the edge is removed */
int find_flip(struct triang * t , int vl, int v2 , int *ol, int * o 2 ) ;
/* interchange an edge for the other diagonal of the quadra1atera 1 created when the edge is removed */
void flip_edge(struct triang * t , int vl, int v2, int ol , int o2);
/* randomly flip edges of a triang u 1 ation without increasing the degree of the last vertex */ void ran_flip_triang_exclude(struct triang * t , int ntimes);
/* reduce the number of vertices in a t r i a n g u 1 at i o n to nv */
/* flip edges until vertex has degree 3 then remove it , repeat */ /* return 1 if successful, return 0 if can’t reduce to nv */ int reduce.triang (struct triang * t , int nv) ;
// Remove an edge
void remove _edge( struct triang * t , int vl, int v2 );
// Remove a face
void remove.face( struct triang * t , int vl, int v2, int v3);
int dsatur.coloring (int edge [128] [128], int nv, int DEBUG) ;
66


void get_critical_graph(struct triang * t , struct triang * 11 , struct triang * t 2 , int PRINT-OUT) ; void initialize_log_function();
void initialize_command_line_parameters(int argc, char* argv [] ) ; void print.triang ( struct triang *t);
int dharwadker.coloring (struct triang t, int MODE-TEST);
// reference cH—|- function // function signature must match
int vertex-coloring ( int N, int edge [MAX_V ] [MAX_V] , int C, int PRINTOUT) ;
|end i f
/*
triang_utils .h
miscellaneous utility functions for working with graphs
*/
#ifndef TRIANG-UTILS.H #define TRIANG-UTILS.H
^include
^include
int count-cliques ( struct triang t, int num_of_vertices_in_cliques , int PRINT-OUT) ; int count_triang2 ( struct triang *t, int PRINT-TRIANGLES); void d i s p 1 a y _t r i a n g _ 1 e x ( s t r u c t triang* t);
// Flip an edge based on the given triang t and 2 endpoints vl, v2 struct triang FlipEdge(struct triang t, int vl, int v2 ) ;
void generate_random_triang(struct triang * t , struct triang * 11 , struct triang * 12 , int nv , int genus, int orient);
struct triang get _c o mp le me nt _g r ap h (struct triang *t);
// Get the flippable edges list for an Ant void g e t _ f 1 i p p a b 1 e _ e d g e s ( Ant * My Ant ) ;
// Get the ’’Nearest Neighbor” Solution
// That is to keep picking the flippable edges that yield the smallest number of triangles in the complement int getNNSolution(Ant *MyAnt, i n t EDGE-LIMIT , int num_of-vertices_in_cliques );
int load_default_triangles(char text-file [], struct triang * t , struct triang * 11 , struct triang * 12 ) ;
void merge_2_triang(struct triang * t , struct triang * 11 , struct triang * 12 ) ;
void p r i n t _n e i g h b o r s 2 ( s t r u c t triang *t);
// write triant in lex format to user specified file void print_triang_lex(FILE * filename , struct triang * t ) ;
67


void remove _edge( struct triang * t , int vl , int v2 );
#en d i f
/*
ant.colony . c
main file for running ant colony program more comments to come
*/
^include
// Accepts: struct triang * t , struct triang * 11 , struct triang * t 2 , int argc, char *argv []
// Returns nothing , best solution should be logged or written to console
void ant_colony_system(struct triang * t , struct triang * 11 , struct triang * t 2 , FILE * successfile )
{
// ant.colony parameters
// TODO: need comments for what each variable is int a, b, i, k, idx, it = 0; int num.vertices = t—>nv;
Ant *MyAnt; // array of ants
Solution BestSol; // globally best tour found among all iterations
/***** Initialization *****/ initialize_arrays( &MyAnt, * t , * 11 , * t 2 ) ;
initialize_best_solution(&BestSol, * 11 , * t 2 ) ;
/***** Write Starting Values To Console *****/
// display-parameters ();
printf(” Starting Cost: %d\ n”, count.cliques (get.complement.graph ( t ) , num.of.vertices.in.cliques , 0))i
printf (” Nearest Neighbor Solution: %d\n”, NNSolution); pr int f (” tauO : %.5f\n”, tauO);
printf(”***************************\n’’);
/***** Log Solution Start *****/ log.ant.start ( log-file , 11 , t2);
/***** Run Ant Colony Process *****/ for (it = 0; it < MAXJTER; it++)
{
// Write iteration number to console every 5 iterations so we can see progress if ( it % 5 == 0) {
printf (” Iteration #: %d \ Best Cost: %d \ n”, it, BestSol. Cost);
}
// each ant builds a tour for(k = 0; k < nAnt ; k-|—|-)
{
// clear the ant’s values for the new tour reset.ant ( &MyAnt [ k ] , *t, * 11 , *t2);
// construct the ant’s tour
68


ant_colony_system_tour_construction( &MyAnt [ k ] , t, 11 , t 2 ) ;
// store the best subset of the ant’s tour prune.tour (&MyAnt [ k ] ) ;
// compare the ant’s tour to the best solution and update if ant’s tour is better f i n d _b e s t _t o u r (MyAnt [ k ] , &BestSol);
}
// update the global pheromone global.pheromone.update ( BestSol ) ;
/***** If Solution Found, Stop Looking *****/ i f ( B est So 1 . Cost == 0)
{
break ;
}
}
/***** End of Program, Log and Free Memory *****/
// generate solution t r i a n g u 1 a t i o n s from list of edge flips build.solution.layers (&BestSol ) ;
/***** Debugging Only, Check that Solution Cost is 0 *****/ merge_2_triang(t , &(BestSol.tl) , &(BestSol.t2 ));
int c = count.cliques( get.complement.graph (t ) , num.of.vertices.in.cliques , 0);
printf(” Solution Found: \ nBestSol Cost: %d | Debug Solution Cost : %d\ nlterations : %d \ n ” , BestSol. Cost, c, it); printf(”***************************\n’’);
/***** End of Debugging *****/
// write results to log
lo g.an t _e n d ( 1 o g _ f i 1 e , &BestSol , it + 1);
// if solution cost is 0, write edge list to successfile if(c = 0) {
// track when the first comma is written so we don’t have trailing commas at the end of line int first-comma = 1; // 1 = true
// print first triang u 1 ation
for (a = 0; a < vertex-count; aH—|-) {
for(b = a + 1; b < vertex-count; bH—|-) {
// value of —1 means no edge
if( Be st So 1 . 11 . edge [ a ] [ b ] != —1) {
if (! first-comma) {
fprintf ( successfile , ”,%d,%d”, a + 1, b + 1);
} else {
fprintf ( successfile , ” %d ,%d”, a+ 1, b+ 1);
first-comma = 0;
}
}
}
}
// reset first comma, print newline first-comma = 1;
69


fprintf(successfile , ”\n”);
// print second triang u 1 ation
for (a = 0; a < vertex.count ; aH—|-) {
for(b = a + 1; b < vertex.count ; bH—|-) {
// value of —1 means no edge if( Be st So 1 . t 2 . edge [ a ] [ b ] != —1) {
i f ( ! first.comma ) {
fprintf ( successfile , ”,%d,%d”, a + 1, b + 1);
} else {
fprintf ( successfile , ”%d, % d ” , a + 1, b + 1);
first.comma = 0;
}
}
}
}
fprintf ( successfile , ”\n”);
}
// be a considerate programmer, free memory free.arrays (MyAnt, &BestSol , tl—>nv ) ;
}
/*
ant.colony.system.stages . c
implementation of functions defined in ant.colony . h
^include ^include
#define DEBUG 0
void reset.ant (Ant * MyAnt, struct triang t, struct triang tl, struct triang t2)
{
i f(DEBUG) printf(” Reset ant\n” ) ;
MyAnt—>TourCnt = 0;
MyAnt—>t = t ;
MyAnt—>t 1 = tl ;
MyAnt—>t 2 = t2 ;
}
void reset.tau ( int num.vertices )
{
int i , j ;
for(i = 0; i < num.vertices — 1; iH—|-) for(j =i + 1; j < num.vertices; j H—|-) tau[i][j] = tauO;
for(i = 0; i < num.vertices; iH—|-) tau[i][i] = 0;
}
void initialize.best.solution (Solution * S o 1 , struct triang tl, struct triang t2)


{
i f (DEBUG) printf(” initialize best solution\n” ) ; int i ;
Sol—>t1 = tl;
Sol—>t2 = t2;
Sol—>L ist F E = (int * *) malloc (EDGE-LIMIT * sizeof ( int * ) ) ;
Sol—>FE-Layer = malloc (EDGE-LIMIT * sizeof (int ));
Sol—>TourCnt = 0;
Sol —> i d x = — 1;
Sol—>Cost = NNSolution;
// init second level of pointers in ListFE for(i = 0; i < EDGE-LIMIT; i++)
Sol—>ListFE [ i ] = (int *) malloc(2 * s i z e o f ( i n t ) ) ;
}
void a n t _ c o 1 o n y _ s y s t e m _ s a v e _ s e 1 e c t i o n ( Ant *MyAnt, int idx_to_save)
{
int j = idx.to.save ;
if (j! = —1)
{
// Determine which t r i a n g u 1 a t i o n the edge flip belongs to i f (MyAnt—>L ist FE_L ay er [ j ] == 1) {
MyAnt—>t 1 = FlipEdge (MyAnt—>t 1 , MyAnt—>ListFE.TMP [ j ] [ 0 ] , MyAnt—>ListFE.TMP [ j ] [ 1 ] ) ;
}
else {
MyAnt—>t 2 = FlipEdge (MyAnt—>t 2 , MyAnt—>L ist FE.TMP [ j ] [ 0 ] , MyAnt—>L ist FE.TMP [ j ] [ 1 ] ) ;
}
MyAnt—>Cost [MyAnt—>TourCnt ] = MyAnt—>FECost [ j ] ;
MyAnt—>FE_Layer [MyAnt—>TourCnt ] = MyAnt—>ListFE_Layer [ j ] ;
// Add flipped edge
MyAnt—>ListFE [MyAnt—>TourCnt ] [ 0 ] = MyAnt—>ListFE_TMP [ j ] [ 0 ] ;
MyAnt—>ListFE [MyAnt—>TourCnt ] [ 1 ] = MyAnt—>ListFE_TMP [ j ] [ 1 ] ;
// Increment tour count last or it will mess up array indexing above MyAnt—>To ur C nt -|—|-;
}
void print.the.tour.cost (Ant MyAnt, int idx)
{
int i ;
p r i n t f (” MyAnt [%d ] . Cost — TourCnt %d : ”, idx , MyAnt. TourCnt ) ;
f o r ( i = 0; i 71


void print _tau ( long double **tau, int length)
{
int i , j ;
for ( i = 0; i printf (” tau[%d] [% d ] : %L f \ n” , i,j,tau[i][j]);
}
/*
ant.colony.system.stages . c
implementation of functions defined in ant.colony . h
*/
^include
^include
#define DEBUG 0
void local.pheromone.update ( int vl , int v2)
{
t au [vl] [v2] = (1 — Xi)*tau[vl][v2] + Xi * t auO;
}
void global.pheromone.update ( Solution BestSol)
{
int i ;
for(i = 0; i < B e s t S o 1 . Tour Cnt ; i-|—|-) // Global Pheromone Trail Update
tau[BestSol.ListFE[i][0]][BestSol.ListFE[i][l]] = (1 — rho) * tau[BestSol.ListFE[i][0]][BestSol.ListFE[i][l]] +
}
/*
ant.colony.system.stages . c
implementation of functions defined in ant.colony . h
*/
^include
^include
#define DEBUG 0
int Ro u le 11 e W hee 1S e 1 e c t io n ( Ant MyAnt, int dupTimes)
{
double r = ( double) rand () / (double )RAND_MAX; // For different range, follow http:// www. eternally confuzzled .com/ a
double *C = malloc (MyAnt. ListFECnt* sizeof ( double ) ) ; int i , j , flag ;
for ( i = 0; i {
C[i] = 0;
for ( j = 0; j <=i ; j++)
C [ i ] + =MyAnt. P [ j ] ; // Accumulate all the P [ j ] from the index 0 to index i
72


if (r {
flag =0;
for (j = 0;j if (MyAnt. ListFE_TMP [ i ] [0]= = MyAnt. ListFE [ j ] [0] && MyAnt. ListFE.TMP [ i ] [l]= = MyAnt . ListFE [ j ] [ 1] )
{
flag + + ;
if (flag >d up Times ) break ;
}
i f ( f 1 ag <=d up Times ) return i;
}
}
return —1;
}
int a r e _t r i a n g _ e q u a 1 ( s t r u c t triang triangl , struct triang triang2)
{
int i , j ;
for(i=0;i if ( triangl . edge [ i ][j ] != triang2 . edge [ i ] [ j ])
return 0;
return 1;
}
struct triang triang.sl [1000]; struct triang triang_s2 [1000]; int triang_c nt =0;
void ant.colony.system.tour.construction (Ant* MyAnt, struct triang *t, struct triang *tl, struct triang *t2)
{
i f (DEBUG) printf(” calculate edge c o s t s\n”);
// get flippable edges for the any // the calculate costs int i ,1 , idx ;
struct triang t.temp , tl.temp , t2_temp;
// calculate flippable edge list EDGE-LIMIT # of times // flippable edge list is all potential flips and their cost for ( 1 =0; KEDGE_LIMIT; 1++)
{
get_flippable_edges (MyAnt ) ;
// loop through each flippable edge and compute cost for ( i = 0; i L ist F EC nt ; i-|—|-)
{
// check which layer the edge is on i f (MyAnt—>L ist FE_L ay er [ i ] == 1)
{
73


tl.temp = FlipEdge (MyAnt—>tl , MyAnt—>ListFE_TMP [ i ] [ 0 ] , MyAnt—>ListFE_TMP [ i ] [ 1 ] ) ; t2_temp = MyAnt—>t2 ;
}
else
{
tl.temp = MyAnt—>tl;
t2_temp = FlipEdge (MyAnt—>t2 , MyAnt—>ListFE_TMP [ i ][ 0 ] , MyAnt—>ListFE_TMP [ i ][ 1 ]) ;
}
merge.2.triang (&t.temp , fetl.temp , &t2.temp ) ;
// save cost of current flip
MyAnt—>FECost [i] = count-cliques (get_complement_graph(&;t .temp), num.of.vertices.in.cliques , 0);
// if the current flip cost is zero , save and exit immediately
i f (MyAnt—>FECost [ i ] = = 0)
{
// TODO: MyAnt—>t = t.temp
ant_colony_system_save_selection( MyAnt, i ) ; return ;
}
}
// determine flippable edge with ACS probablistic selection procedure // idx is index of edge to flip in FEList
idx = an t _c o 1 o n y _s y s t e m_se 1 e c t io n (MyAnt ) ;
// update ant by flipping selected edge ant_colony_system_save_selection( MyAnt, idx);
// ACS local pheromone update procedure if ( idx != — 1)
local.pheromone.update (MyAnt—>ListFE_TMP [ idx ] [ 0 ] , MyAnt—>ListFE_TMP [ id x ] [ 1 ] ) ;
}
MyAnt—>t = t.temp ;
}
// ACS probabilistic selection procedure int a n t _ c o 1 o n y _ s y s t e m _ s e 1 e c t i o n ( Ant *MyAnt)
{
i f (DEBUG) printf(”ant colony system selection\n” );
int i , j = 0, argmax.idx ;
double sum ;
double temp , argmax ;
temp = (long d o ub le ) r an d ( ) / (long d o ub le )RANDJMAX ; // Generate a random number between 0 // if temp<= Q0: Calculate the argmax and do the edge selection // else: calculate the probabilities and do the edge selection if (temp<=Q0)
{
argmax = 0;
for ( i = 0; iListFECnt ; i-|—|-)
74


{
// Choose the maximum of t au.i "beta
temp = t au [MyAnt—>ListFE_TMP [ i ] [ 0 ] ] [ MyAnt—>ListFE_TMP [ i ] [ 1 ] ] * pow (( long double)l /MyAnt—>FECost [ i ] , bet a ) ; i f ( argmax {
argmax = temp ; argmax.idx = i ;
}
}
j = argmax.idx ;
}
else
{
/ / sum = 0;
for ( i = 0; iListFECnt ; i-|—|-)
{
// Calculate P [ i ] = tauO"alpha * cost "beta
MyAnt—>P [ i ] = pow ((long double)tau [MyAnt—>ListFE_TMP [ i ] [ 0 ] ] [ MyAnt—>L ist FE.TMP [ i ] [ 1 ] ] , alpha)* pow ((long dou sum += MyAnt—>P [ i ] ; // Accumulate for the sum
}
for ( i = 0; i L ist F EC nt ; i-|—|-)
MyAnt—>P [ i ] = MyAnt—>P [ i ] / sum; // Divide to the sum to get P [ i ] = tauO"alpha * cost "beta / sum j = Roulett e W heelSelection (* MyAnt ,10); // Do the roulette wheel selection. 10 means to allow 10 duplicates in
}
return j;
}
void prune.tour (Ant *MyAnt)
{
i f (DEBUG) printf(” prune tours\n” ); int i,final_idx=0;
// Figure out the best part of the tour for ( i =1; i TourCnt ; i-\—|-)
i f (MyAnt—>Cost [ f i n a 1 _ i d x ] >MyAnt—>Cost [ i ] ) final_idx = i;
// Save the best part to the counter of the tour MyAnt—>TourCnt = final_idx+l;
}
void find.best.tour (Ant MyAnt, Solution *BestSol)
{
i f (DEBUG) printf (” find best tour\n”);
75


int i ;
i f ( B es t Sol —>Cost > MyAnt .Cost [MyAnt . TourCnt — 1])
{
Best Sol —>Cost = MyAnt .Cost [MyAnt . TourCnt — 1 ] ;
Best Sol —>TourCnt = MyAnt . TourCnt ;
for(i = 0; i < MyAnt . TourCnt ; i-|—|-)
{
// update flippable edge list B e s t S o 1 —> ListFE [ i ] [0] = MyAnt. ListFE [ i ] [0] ; BestSo 1 —>ListFE [ i ] [1] = MyAnt. ListFE [ i ] [1] ;
// update flippable edge layers
BestSol—>FE-Layer [ i ] = MyAnt. FE_Layer [ i ] ;
}
}
}
/*
ant.structs . c
*/
^include < s t d 1 i b . h>
^include
^include
#define DEBUG 0
void b u i 1 d _ s o 1 u t i o n _ 1 a y e r s ( S o 1 u t io n *s)
{
int i ;
// update t r i a n g u 1 a t i o n s by flipping each edge in List_FE for(i = 0; i < s—>TourCnt; i-|—|-) { i f ( s—>FE_Layer [ i ] == 1) {
s—>t 1 = FlipEdge( s—>t 1 , s—>L ist FE [ i ] [ 0 ] , s—>List FE [ i ] [ 1 ] ) ;
}
else {
s—>t 2 = FlipEdge( s—>t 2 , s—>L ist FE [ i ] [ 0 ] , s—>List FE [ i ] [ 1 ] ) ;
}
}
}
void free.ant (Ant * ant )
{
int i ;
free (ant —>Cost ) ; free ( ant —>FE_Layer ) ;
// ListFE and ListFE_TMP are pointer to pointer of size = edge
// free inner pointers
for(i = 0; i < EDGE-LIMIT; i++)
{
free ( ant—>ListFE [ i ] ) ;
limit
76


free ( ant —>ListFE_TMP [ i ] ) ;
}
// free pointer to pointer free ( ant—>ListFE ) ; free ( ant —>ListFE_TMP ) ;
// free ListFE-Layer free (ant —>ListFE_Layer ) ;
// free ListFE.TMP // free FECost free ( ant—>FECost ) ;
}
void free_so1ution ( So1ution * sol )
{
int i ;
free ( sol —>FE-Layer ) ;
// free inner pointers for(i = 0; i < EDGE-LIMIT; i++)
free ( sol —>ListFE [ i ] ) ;
// free pointer to pointers free ( sol —> L i s t F E ) ;
}
Ant init.ant ()
{
int i ;
Ant myAnt ;
myAnt . TourCnt = 0;
myAnt . Cost = ma 1 lo c (EDGE-LIMIT * s i z e o f ( i n t ) ) ;
myAnt .ListFE = (int **) malloc (EDGE-LIMIT * sizeof (int *));
myAnt . FE-Layer = malloc (EDGE-LIMIT * s iz eo f ( i nt ) ) ;
myAnt . ListFE_TMP = (int **) malloc (EDGE-LIMIT * s izeof ( int myAnt .FECost = malloc( EDGE-LIMIT * sizeof (int )); myAnt .ListFE-Layer = malloc (EDGE-LIMIT * sizeof ( int )) ;
myAnt . P = m al lo c (EDGE-LIMIT * sizeof ( long double));
for(i = 0; i < EDGE-LIMIT; i++)
{
myAnt . L i s t F E [ i ] = (int * ) malloc(2 * sizeof ( int )) ; myAnt . ListFE-TMP [i] = (int *) malloc(2 * sizeof ( int )) ;
}
return myAnt;
}
^include ^include


#define DEBUG 0
double calculate.initial.pheromone (Ant MyAnt)
{
// Get the tauO based on the cost of the given NNSolution; int i,idx,l,min, temp ;
struct triang t.temp , tl.temp , t2_temp ; double tauO ;
for ( 1 = 0; 1 {
min=10000; // Reset the variable min
g e t _ f 1 i p p a b 1 e _e d g e s (&MyAnt ) ; // Get the list of flippable edges
for ( i
{
0; i i f (MyAnt. L is t F E-Layer [ i ] = = 1) // Follow the layer to flip the edge
{
tl.temp = FlipEdge (MyAnt . 11 , MyAnt. ListFE.TMP [ i ] [ 0 ] , MyAnt . ListFE.TMP [ i ] [ 1 ] ) ; t 2 _temp = MyAnt. t2;
}
else
{
tl.temp = MyAnt. 11 ;
t2_temp = FlipEdge (MyAnt . 12 , MyAnt. ListFE_TMP [ i ] [ 0 ] , MyAnt . ListFE_TMP [ i ] [ 1 ] ) ;
}
//printf(”[%d][%d][%d] ” , MyAnt . ListFE_TMP [ i ] [ 0 ] , MyAnt. ListFE_TMP [ i ] [ 1 ] , MyAnt. ListFE_Lay
//printf(”Flip [%d][%d] at the layer %d . \ n” , MyAnt. ListFE.TMP [ i ] [ 0 ] , MyAnt . ListFE.TMP [ i ] [ 1 ] //get_int (’’Next?: ” , & temp ) ;
merge.2.triang(&t.temp , &t l.temp , &t 2 _t emp ) ;
MyAnt. FECost [i] = count.cliques (get.complement_graph(&t_temp ) , num.of.vertices.in.cliques ,
i f ( min>MyAnt. FECost [ i ] )
{
min = MyAnt. FECost [ i ] ; i d x = i ;
}
}
//get-int (” \ nNext ? : ” ,&temp ) ;
// Save for the tour
ant_colony_system_save_selection( &MyAnt, i d x ) ;
// Get the best part of the tour i d x = 0;
for ( i = 0; i i f ( MyAnt. Cost [ i d x ] > MyAnt. Co st [ i ] ) // Still accept value that equals to min
i d x = i ;
78


MyAnt. TourCnt = idx + 1;
/ / printf (” NNSolution : %d\n” , MyAnt .Cost [MyAnt .TourCnt — 1]); NNSolution = MyAnt . Cost [MyAnt . TourCnt — 1] ;
else
i f (MyAnt .Cost [MyAnt .TourCnt — 1] != 0)
return l/(double)(( MyAnt. TourCnt —1)
return 0;
}#include < a nt _c o 1 o n y . h>
NNSolution ) ;
#define DEBUG 0
void d i sp 1 ay _p ar amet er s ( )
{
p r i n t f ( ” * * * ACS Starting P ar amet er s * * * \ n ” ) ;
p r i n t f (” alp ha : %.l f \ nbeta : %.lf\nrho : %. 4 f \ n C 1 i q ue : K%d\nnAnt: %d\nEDGE_LIMIT : %d\nQ0: %
}
^include
^include
#define DEBUG 0
void f r e e _ a r r a y s ( Ant * MyAnt, Solution *sol , int num.vertices)
{
int i ;
// free each ant
for(i = 0; i < nAnt ; i-|—|-)
{
free.ant (&MyAnt [ i ] ) ;
}
free (MyAnt) ; free.solution(sol);
}
^include
^include
#define DEBUG 0
void initialize_ant_parameters(struct triang * t , struct triang * 11 , struct triang * t 2 , int
{
// for loop variable declaration int i,v,genus,orient;
// allocate first level of tau
tau = (long double **) m a 1 lo c ( n u m _v er t i c e s * sizeof ( long double*));
// allocate second level of tau for(i=0; i < n u m _v er t i c e s ; i++)
tau [ i ] = (long double *) malloc(num_vertices * sizeof ( long double));
// initialize parameters to default values
.2 f\nXi : %. 2 f \ nMAX_ITER :
num.vertices , int argc ,
79


alpha
beta
num.of.vertices.in.cliques
r ho
nAnt
QO
Xi
EDGE-LIMIT
MAX-ITER
1.0; // Pheromone Exponential Weight
30.0; // Heuristic Exponential Weight
3 ;
0.01; // Evaporation Rate
1; // Number of ants
0.1; // Q0 in ACS for Tour Construction
0.1; // Parameter for Local Pheromone Update
( n u m _v er t i c e s ) * ( n u m _v er t i c e s — 1) * 10;
1000;
// if command line arguments provided , use those instead of defaults if ( argc > 4)
{
for(i = 5; i <= argc; i -\—|-)
{
switch(i)
{
case 5:
alpha = atof(argv[i—1]); break ; case 6:
beta = atof(argv[i—1]); break ; case 7:
rho = atof(argv[i—1]); break ; case 8:
num.of.vertices-in.cliques = (int) str tol ( argv [ i - 1] , NULL, 10);
break ; case 9:
nAnt = (int) s t r t o 1 ( ar g v [ i — 1 ] , NULL, 10); break ; case 10:
EDGE-LIMIT = ((int) s t r t o 1 ( argv [ i - 1] , NULL, 10)); break ; case 11:
Q0= atof(argv[i—1]); break ; case 12:
Xi = atof(argv [ i — 1] ) ; break ; case 13:
MAXJTER = (int) s t r t o 1 ( arg v [ i - 1], NULL, 10); default : break ;
}
}
}
}
^include
^include
#define DEBUG 0
void initialize.arrays (Ant * * My Ant, struct triang t, struct triang 11 , struct triang t2)
80


{
int i, j; // loop control int num.vertices = 11 . nv ;
(*MyAnt) = malloc (nAnt * s i z e o f ( Ant ) ) ;
for(i=0; i < nAnt; i-|—|-)
( * MyAnt ) [ i ] = init.ant ();
reset.ant ( & ( * MyAnt ) [ 0 ] , t , 11 , t 2 ) ;
tauO = calculate.initial.pheromone ((* MyAnt ) [ 0 ] ) ;
// initialize tau to tauO reset.tau ( num.vertices ) ;
}
/*
log.ant.end . c
write results to log file
*/
^include
^include
void log_ant_end(FILE * f , Solution * s , int iterations)
{
fprintf(f , ” FINISH , ” ) ; fprintf(f, ”%d” , s—>Cost ) ; fprintf(f , ” ,” ) ;
fprintf (f, ” %d , iterations); print.tr iang.lex (f , & ( s —> 11 ) ) ;
fprintf(f , ” ,” ) ;
print.tr iang.lex (f , & ( s —> t 2 ) ) ;
fprint f(f , ”\n” );
}
/*
log_ant_start .c
Write information about initial ant parameters Function assumes a file stream is already open
None of the functions called inside 1 o g _ a n t _ s t a r t add any extra formatting outside of what is needed to print what they’re responsible for
*/
^include
^include
void log_ant_start(FILE * f , struct triang * 11 , struct triang * t 2 )
{
fprintf (f , ’’START,” ) ; print.tr iang.lex (f , 11 ) ;
fprintf(f , ” ,” );
print.tr iang.lex (f , t 2 ) ;
81


fprintf(f , ” );
print.ant.parameters ( f ) ; fprint f(f , ”\n” );
}
/*
print.ant.parameters . c
print ant parameters to a user specified file
User is responsible for adding extra formatting such as commas before the start of the arguments or new lines after .
*/
^include
^include
void print.ant.parameters (FILE *f)
{
fprintf(f, ” % . 1 f , % . 1 f , % . 4 f ,%d ,%d ,%d , % . 2 f , % . 2 f ” , alpha, beta, rho , num.of.vertices.in.cliques , nAnt , EDGE-LIMIT, Q
}
^include
void add.edge(struct triang * t , int vl, int v2)
{
t —>edge [vl] [v2] = 1; t —>edge [v2] [vl] = 1;
}
/* add one face to a triang u 1 ation */
^include
void add.face(struct triang * t , int vl, int v2, int v3)
{
#if DEBUG
if ( v 1 == v 2 || v 1
printf (” add-face vl ,v2 ,v3 ) exit ( 0 ) ;
}
if (vl < 0 || vl >= t—>nv v2 < 0 || v2 >= t—>nv v3 <0 || v3 >= t—>nv)
printf (” add-face : vertex vl , v2 , v3 , t—>nv ) ; exit ( 0 ) ;
}
|end i f
if ( t —>orient == 1) {
#if DEBUG
if (t—>edge [ vl ] [ v2 ] != —1) {
printf (” add-face: can’t add face (%d,%d,%d). a face (%d,%d,%d) already exists. \ n”, vl,v2,v3,vl,v2,t—>edge[vl][v2]); exit ( 0 ) ;
{
(%d , %d or %d) out of range, must be between 0 and %d . \ n ” ,
== v 3 || v 2 == v 3) {
vertices (%d, %d and %d) must be distinct. \ n”,
82


}
if (t—>edge[v2][v3] != —1) {
printf(”add_face: can’t add face (%d,%d,%d). a face (%d,%d,%d) already exists. \ n”, vl,v2,v3,v2,v3,t—>edge[v2][v3]); exit ( 0 ) ;
}
if (t—>edge [ v3 ] [ vl ] != —1) {
printf(”add_face: can’t add face (%d,%d,%d). a face (%d,%d,%d) already exists ,\n” , vl,v2,v3,v3,vl,t—>edge[v3][vl]); exit ( 0 ) ;
}
|end i f
t—>edge[vl][v2] = v3; t—>edge[v2][v3] = vl; t—>edge[v3][vl] = v2;
}
else {
#if DEBUG
if (t —>edge [vl] [v2] != —1 && t—>edge [v2 ] [ vl ] != —1) {
printf(”add_face: can’t add face (%d,%d,%d). faces (%d,%d,%d) and (%d,%d,%d) already exist.\n
vl,v2,v3,vl,v2,t—>edge [vl][v2],v2,vl,t —>edge [v2] [vl] ) ; exit ( 0 ) ;
}
if (t —>edge [v2][v3] != —1 && t—>edge [v3][v2] != —1) {
printf(”add_face: can’t add face (%d,%d,%d). faces (%d,%d,%d) and (%d,%d,%d) already exist.\n
vl,v2,v3,v2,v3,t—>edge [v2][v3],v3,v2,t —>edge [v3] [v2] ) ; exit ( 0 ) ;
}
if (t —>edge [v3] [vl] != —1 && t—>edge [vl ] [ v3 ] != —1) {
printf(”add_face: can’t add face (%d,%d,%d). faces (%d,%d,%d) and (%d,%d,%d) already exist.\n
vl ,v2 ,v3,v3,vl ,t—>edge [v3][vl],vl,v3,t —>edge [vl] [v3] ) ; exit ( 0 ) ;
}
#en d i f
if (t—>edge [ vl ] [ v2 ] == —1) t—>edge[vl][v2] = v3; else
t—>edge[v2][vl] = v3;
if ( t —>edge [ v2 ] [ v3 ] == —1) t—>edge[v2][v3] = vl; else
t—>edge[v3][v2] = vl;
if (t—>edge [ v3 ] [ vl ] == —1) t—>edge[v3][vl] = v2;
else
t—>edge[vl][v3] = v2;
}
(t ~> n f) + +;
83


/* check t r i a n g u 1 a t i o n */
/* return 0 if no problems , 1 otherwise */
^include
int check.triang ( struct triang * t , char * c aller )
{
int vl , v2 , v3 ; int bad ; int ne;
int found [MAX_V] , search [MAX_V] , nsearch , nfound ; bad = 0;
// check that number of vertices in bounds if (t—>nv <4 || t—>nv > MAX_V) {
printf(”%s: nv ( %d ) out of range\n” , caller ,t —>nv ) ; bad = 1; return b ad;
}
/* check that no edge is a loop */
for ( vl =0 ; vlnv ; vl-|—|-)
if (t—>edge [ vl ] [ vl ] != —1) {
printf(”%s: loop edge at %d \ n” , caller , vl ) ; bad = 1;
}
/* check that each edge is in 0 or 2 triangles */
for ( vl =0 ; vlnv ; vl-|—|-) for ( v2 = 0; v2nv ; v2-|—|-) if (vl != v2)
if (t —>edge [vl] [v2] != —1 && t—>edge [v2 ] [v1] == — 1) { printf(”%s: (%d,%d) is on a face but (%d,%d) is not\ caller ,vl,v2,v2,vl); bad = 1;
}
/* check that orientable */ ne = 0;
for ( vl =0 ; vlnv ; vl-|—|-) for ( v2 = 0; v2nv ; v2-|—|-)
if ( t—>edge [ vl ] [ v2 ] != —1) {
ne + + ;
v3 = t—>edge[vl][v2]; if (t —>edge [v2][v3] != vl)
if ( t —> orient == 1) {
printf(”%s: (%d,%d,%d) is a face but (%d,%d,%d) is caller ,vl,v2,v3,v2,v3,vl); bad = 1;
}
not\n”,
84


else {
if (t —>edge [v3][v2] != vl) {
printf(”%s : (%d,%d,%d) is a face but (%d,%d,%d) is
caller ,vl,v2,v3,v2,v3,vl); bad = 1;
}
}
}
ne = ne / 2 ;
/* check that connected */
for ( vl =0 ; vlnv ; vl-|—|-) found [ vl ] = 0 ;
found [0] = 1;
search[0] = 0;
nsearch = 0; nfound = 1;
while (nfound < t—>nv && nsearch < nfound) { vl = search [ nsear c h+ + ]; for ( v2 = 0; v2nv ; v2-|—|-)
i f (t—>edge [vl ] [v2] != —1 && ! found [ v2]) {
found [ v2 ] = 1 ;
search [nfound + +] = v2;
}
}
if (nfound != t—>nv) {
printf(”%s: not connected\n” , caller ) ; bad = 1;
}
/* check scalars */ if ( ne != t—>ne) {
p r i n t f (” % s : calculated ne (%d) not equal to stored ne (%d)\n” caller ,ne,t —>ne); bad = 1;
}
if (ne*2/3 != t—>nf) {
p r i n t f (” % s : calculated nf (%d) not equal to stored nf (%d)\n” caller , ne * 2/ 3 , t —>nf ) ; bad = 1;
if (t—>genus != —1)
if (t—>orient == 1 && (2 — ( t —>nv—ne / 3 ) ) / 2 != t—>genus) {
p r i n t f (” % s : calculated genus (%d) not equal to stored genus caller , ( 2 —(t—>nv—ne/3))/2 ,t—>genus);
bad = 1;
if (t—>genus != —1)
if (t—>orient == 0 && (2 — ( t —>nv—ne / 3 ) ) != t—>genus) {
p r i n t f (” % s : calculated genus (%d) not equal to stored genus
not\n” ,
(%d ) \ n” ,
(%d ) \ n” ,
85


caller , ( 2 — ( t —>nv—ne / 3 ) ) ,t— >genus);
bad = 1;
}
return bad;
}
/* remove all edges from a t r i a n g u 1 a t i o n */
^include
void clear.triang ( struct triang * t , int nv)
{
int vl ,v2 ;
if (nv <0 || nv > MAX_V) {
printf(” clear.triang : nv (%d) out of range. must be between 0 nv , MAX.V) ; exit ( 0 ) ;
}
t—>nv = 0; t—>ne = 0; t —> n f = 0 ;
for ( vl =0 ; vledge [ v 1 ] [ v2 ] = —1;
}
/* create a triang u 1 ation of a sphere with handles and/or crosscaps vertices */
^include
void create.triang(struct triang * t , int nv, int genus, int orient)
{
int vl,v2,v3,v4,v5,v6,v7; int ih ;
int handles , crosscaps , ec; int ne;
if (genus < 0) {
printf (” create.triang : The genus ( %d ) must be non— negative.\n” , genus); exit ( 0 ) ;
}
if (orient) { orient = 1;
handles = genus; crosscaps = 0; ec = 2—2*genus;
}
else {
orient = 0;
and %d .\n”
with nv
handles = (genus—1)/2;


crosscaps
((genus—1) % 2) + 1;
ec = 2—genus;
}
/* test that input is in range */
ne = 3 * ( nv—ec ) ; if ( ne > MAX_E) {
printf (” create.triang : number of edges too large (%d). increase MAX_E. \ n” , ne ) ;
exit ( 0 ) ;
}
if ( ( nv * ( nv — 1) )/2 < ne) {
printf (” create.triang : The number of vertices ( %d ) is too small to create a triangulation\n\ on a surface with Euler characteristic %d.\n\
The number of edges in K%d is %d but the number of edges in a t r i a n g u 1 a t i o n s is %d ■\n” , nv , ec , nv , ( nv * ( nv — l))/2,ne); exit ( 0 ) ;
}
/*
if (nv < 4 + 3*handles + 2* crosscaps)
{
printf(” create.triang : The number of vertices (%d) is too small create a t r i a n g u 1 at i o n \ n\ on a surface with %d handles and %d c r o s s c a p s . \ n\
I only know how t o make triangulations with %d (4+3*h + 2*c) vertices . \ n ” , nv , handles , crosscaps ,4+3* handles+2*crosscaps ) ; exit ( 0 ) ;
}
*/
if (nv + 3 > MAX.V) {
printf (” create.triang : number of vertices too large (%d). increase MAX.V. \ n ” , nv ) ;
exit ( 0 ) ;
}
clear.triang (t , nv + 3 ) ;
/* create tetrahedron */
t —> orient = 1; t —> genus = 0; t—>nv = 4;
add.face(t,0,1,2); add.face(t,0,2,3); add.face(t,0,3,1); add.face(t,1,3,2);
t—>ne = 6;
/* add handles */
for ( ih =0 ; ih

/* pick a random edge.
add handle to connect the adjacent faces
/
sew this onto this
7....7
â– \ - I / I /
\ I / I /
1 / / /â– 
• /1 \ - I / I-
/ \ 1 / â–  \ 1 /
/ / 4 / â– 
\ - 1 / / \
\ 1 / â–  / \
/ / 6 . \ / \ /
/ 1 \ - -4 3-
\ / 1 â–  / \ / \
3 / / / â–  \ /
/ 1 1 / â–  \ /
\ 1 / / 2
/ 2 / /â–  /I \
/ 1 \ - / â– 
â– I / \ I / â– 
â–  / / 5 /
â–  / I /I\-â– / I / I \
7...............7
*/
t—>genus += 1;
vl = 0; v2 = 0;
while ( ( v3=t —>edge [ v2 ] [ vl ] ) == —1) { vl = rand() % (t—>nv); v2 = rand() % (t—>nv);
}
v4 = t—>edge[vl][v2]; v5 = (t—>nv) + + ; v6 = (t—>nv) + + ; v7 = (t—>nv) + + ; remove_face(t ,vl ,v2 ,v4); remove_face(t ,v2 ,vl , v3 ) ;
add.face(t,vl,v7,v2); add_face(t,vl,v2,v5); add.face(t,vl,v5,v4); add.face(t,v4,v5,v7); add.face(t, v4,v7,v6); add.face(t,vl,v6,v7); add.face(t,vl,v3,v6); add.face(t,v2,v4,v6); add.face(t,v2,v6,v5);
88


add_face(t,v3,v5,v6); add_face(t,v3, v7,v5); add_face(t,v2,v7,v3);
t—>ne += 1 5 ; reduce.triang (t , nv ) ;
}
/* add crosscaps */
if (! orient) { t —> orient = 0; t —> genus = 2 * (t —> genus);
for (ih=0;ih add crosscap in whole left by
sew this onto this
\ i /

/ \ / 1
/ \ / / â–  \
/ \ / / : \
\ / \ / \ / : \ /
3 4 | -4 : 3-
/ \ / \ / \ : / \
\ / \ \ : /
\ / \ W
1/ \ / \l
5--------------2---------------6
2
/I \
(t—>genus) + +;
vl = 0; v2 = 0;
while ( ( v3=t —>edge [ v2 ] [ vl ] ) == —1) { vl = rand() % (t—>nv); v2 = rand() % (t—>nv);
89


v4 = t—>edge [vl] [v 2] ; v5 = (t—>nv) + + ; v6 = (t—>nv) + + ; remove_face(t ,vl ,v2 ,v4); remove_face(t ,v2 ,vl ,v3);
add_face(t,vl,v3,v6); add.face(t,vl,v5,v4); add.face(t,v3,v5,v6); add.face(t,v4,v5,v6); add.face(t,v2,v5,v3); add_face(t,v2,v4,v6); add_face(t,vl,v5,v2); add_face(t,vl,v2,v6);
t—>ne += 9; reduce.triang (t , nv ) ;
}
/* add additional vertex , n, by placing it inside random face */
while (t—>nv < nv) {
vl = rand () % (t—>nv); v2 = rand () % (t—>nv); if ((v3=t—>edge[vl][v2]) != —1) {
v4 = (t—>nv) + +; remove-face (t ,vl ,v2 , v3 ) ; add.face(t,vl,v2,v4); add.face(t,vl,v4,v3); add.face(t,v2,v3,v4); t —> n e += 3 ;
}
}
}
/* create a t r i a n g u 1 a t i o n using lex format input */
/*
* lex format: string of ascii characters with no spaces
* each group of three letters represents a face
* example: abcdba => 2 faces , abca and dbad, the ending vertix is
*/
^include
^include
#define DIM 2
int decode_tr i a ng_ 1 e x (char * text , struct triang *t)
{
int itext , iface , v[(DIM+l)], nv , nf;
// determine the number of faces nf = s t r le n ( t ex t ) / (DIM+1) ;
if ( nf < 4 || nf > MAX_F) {
printf(”decode_triang_lex: bad format or nf (%d) out of range\n
omitted
%s \n” ,
90


Full Text

PAGE 1

HEURISTICSEARCHMETHODSFORDISCOVERINGTHICKNESS N GRAPHS by JEFFFLOWER B.M.,SUNY-Fredonia,2003 Athesissubmittedtothe FacultyoftheGraduateSchoolofthe UniversityofColoradoinpartialfulllment oftherequirementsforthedegreeof MasterofScience ComputerScienceProgram 2017

PAGE 2

ThisthesisfortheMasterofSciencedegreeby JeFlower hasbeenapprovedforthe ComputerScienceProgram by EllenGethner,Chair BogdanChlebus StephenHartke Date:July29,2017 ii

PAGE 3

Flower,JeM.S.,ComputerScience HeuristicSearchMethodsForDiscoveringThickness n Graphs ThesisdirectedbyAssociateProfessorDr.EllenGethner ABSTRACT AnEarth/Moon,orthickness2,graphisagraphwhoseedgescanbedistributed betweentwoplanarlayers.Morebroadly,agraphissaidtohavethickness t ifits edgescanbedistributedamong t layers.Thechromaticnumberofagraphisthe minimumnumberofcolorsneededtoproperlycoloragraph.Themaximumnumber ofcolorsneededtocolorallthickness2graphsisknowntoliein f 9 ; 10 ; 11 ; 12 g ,but theexactnumberremainsanopenquestion.AntColonyOptimizationisanarticialintelligencetechniqueforndingacceptablesolutionstodicultoptimization problems.PreviousworkhasusedatechniquedevelopedbyGethnerandSulanke withinanAntColonyalgorithmtoproducenewgraphsofvaryingthicknessandchromaticnumber.Weseektoincreasethespeedandeciencyofimplementingother AImethodsusingGethnerandSulanke'stechniquebyintroducingamodularprocess andsoftwaretools.AdditionallyweimplementourownAntColonyalgorithmand proposenewavenuesforfutureresearchanddevelopment. Theformandcontentofthisabstractareapproved.Irecommenditspublication. Approved:EllenGethner iii

PAGE 4

Formywife,Lisa,andourtwowonderfulboys. iv

PAGE 5

ACKNOWLEDGMENTS KhaMan,foryourtimeandsuggestionsregardingantalgorithms.PeterHoesley,it's raretondamanagersoconcernedforthewellbeingofhisemployees.Yoursupport andexibilityweregreatlyappreciated.Mostimportantly,Dr.EllenGethner,for thetimeyou'vededicatedandtheopportunitiesyou'veaordedme.Evenwhileon sabbaticalyouwerewillingtohelpme,andforthatI'mgrateful. v

PAGE 6

TABLEOFCONTENTS CHAPTER I.INTRODUCTION................................1 Overview....................................1 Motivation...................................1 HeuristicMethods...............................1 SectionOverview...............................2 II.DEFINITIONS.................................3 Graphs.....................................3 VisibilityGraphs...............................7 III.LITERATUREREVIEW...........................9 GraphColoringandThickness........................9 ColoringMapsandPlanarGraphs...................9 EmpireGraphs..............................9 Heawood'sTheorem.........................9 MaximumColors..........................10 Thickness n Graphs...........................11 Earth/MoonGraphs........................11 ColoringEarth/MoonGraphs...................11 BeyondThickness2Graphs....................12 OtherSurfaces..............................12 RectangleVisibilityGraphs..........................13 Characteristics..............................13 TopologicalRVG.............................14 ArticialIntelligenceAlgorithms.......................15 Introduction...............................15 TravelingSalesmanProblem.......................16 vi

PAGE 7

Metaheuristics..............................16 AntColonyOptimization........................17 Overview...............................17 AntColonyOptimizationMetaheuristic..............17 CommonParameters........................18 AntSystem.............................19 AntColonySystem.........................20 SettingParameters.........................21 Applications.............................22 TabuSearch................................22 LocalSearch.............................22 GuidingPrinciples..........................22 SimpleTabuSearch.........................23 AdditionalStrategies........................25 ExtendedTechniques........................26 Applications.............................26 IV.RESEARCHMETHODS...........................27 Background..................................27 Procedure...................................27 GenerateSolutionCandidate......................28 ConrmSolution.............................28 ConrmSolutionUniqueness......................29 ExistingSoftwareTools............................29 ProblemsWithExistingTools........................29 BuildingAProcess..............................30 ProcessDenition............................30 Input/OutputFormats..........................31 vii

PAGE 8

TriangulationGenerationOutput/SolutionGeneration......31 SolutionOutput/ColoringInput..................31 ImplementationofSolutionConrmation...............33 AntColonyImplementation.........................33 V.FINDINGS...................................35 Results.....................................35 AntTuning................................35 Beta.................................35 FurtherTuning...........................36 SelectingTargets.............................36 TargetsandResults...........................37 FutureStudy..................................40 BIBLIOGRAPHY.................................41 APPENDIX A.TriangleGeneration...............................45 B.AntColony...................................60 C.NewGraphs...................................105 Thickness=2,V=17, K m removed=3..................105 D.TuningResults.................................114 viii

PAGE 9

TABLES TABLE 2.1By2.17,theupperboundaryofedges e forgenus g ,0 g 4......7 3.1Resultsfortherstvevaluesof3.4....................12 3.2Resultsfortherstvevaluesof3.5....................13 3.3Somevaluesfor3.6. M valuesrunacrossthetopand g valuesareonthe left.......................................13 5.1RecommendedsettingsbyDorigoforACSimplementations........35 5.2ResultsFor =10Search..........................40 3.1Layer1Adjacencies, K 14 decomposition..................106 3.2Layer2Adjacencies, K 14 decomposition..................107 3.3Layer1Adjacencies, K 15 decomposition..................108 3.4Layer2Adjacencies, K 15 decomposition..................109 3.5Layer1Adjacencies, K 16 decomposition..................110 3.6Layer2Adjacencies, K 16 decomposition..................111 3.7Layer1Adjacencies, K 17 decomposition..................112 3.8Layer2Adjacencies, K 17 decomposition..................113 4.1TuningResultsfor =2...........................114 4.2TuningResultsfor =3...........................115 4.3TuningResultsfor =4...........................115 4.4TuningResultsfor =5...........................116 ix

PAGE 10

FIGURES FIGURE 2.1Agraphwith6verticesand7edges....................3 2.2Agraphanditscomplement.........................4 2.3 K 5 ,thecompletegraphon5vertices....................4 2.4Threedierentwaysofdrawing K 4 .Eitherofthelasttwodrawingsshow K 4 isplanar..................................5 2.5Agraphwith6faces.Theouterfaceofthegraphisincludedinthecount.5 2.6Agraph G highlightedinblueanditsdual G highlightedinred....6 2.7A3-coloringofagraph.Novertexisadjacenttoavertexofthesamecolor.6 2.8Surfacesofgenus=0,1and2........................7 4.1Exampleoutputfromthetriangulationgenerationstep..........32 4.2Exampleoutputfromphase2........................32 x

PAGE 11

CHAPTERIINTRODUCTION Overview Graphscanbeusedtorepresentawiderangeofthingsfromcitystreetstoairline ightstotheconnectionssharedbetweenFacebookusers.Begunin1736byEuler, graphtheoryisstillrelativelyyoungwithmanydicultquestionsstilltobeanswered. Apropercoloringofagraphassignsacolortoeachvertexsothatnoadjacent vertexreceivesthesamecolor.Thechromaticnumberofagraphistheminimum numberofcolorsneededtoperformapropercoloringofagraph[Wes01].Finding thechromaticnumberofagraphisknowntobe NP -hard[GJ02]. Thicknessisonewaytomeasurehowcloseagraphistoachievingplanarity.The thickness t ofagraph G istheminimumnumberofplanarlayers G canbedecomposedintosuchthattheirunionconstitutes G [Wes01].Thicknesshasimportant applicationstoVLSIcomputerchipdesign[BDHS97].Findingthethicknessofa graphisalsoknowntobe NP -hard[Man83]. Motivation SinceRingelintroducedtheEarth/MoonGraph,thefollowingquestionhasremainedopen: Whatisthemaximumnumberofcolorsneededtocolorallgraphsofthickness2? Currentlythelargestknownchromaticnumberofathicknesstwographisnine. Relativelyfewexamplesofthesetypesofgraphshavebeendiscovered.Moreexamplesandtechniquesforndingthicknesstwographsareneededtohelpfurtherour understandingofthem[BGS08]. HeuristicMethods Duetotheircomputationalcomplexityitisimpossibletoexhaustivelysearchfor asolutiontomanyproblems.Heuristicsearchmethodsareanarticialintelligence techniqueforleveragingdomainspecicknowledgeandhavebeensuccessfullyapplied toabroadrangeofproblemsfromjob-schedulingtonetworkrouting[PR10]. 1

PAGE 12

FirstintroducedbyDorigoandColorini,antalgorithmsareaheuristictechnique inspiredbytheobservedforagingbehaviorofants[DBS06].WeuseanimplementationofAntColonySysteminoursearchfornewthicknesstwographs. SectionOverview Insection3.1wegiveasummaryofthehistoryofgraphcoloringandthickness andhighlightsomeofthekeyresults.Insection3.2wediscussaspecictypeof thicknesstwograph,therectanglevisibilitygraph.Section3.3discussesingeneral heuristicsearchmethodsandindepthtwospecicmethods:AntColonyOptimization andTabuSearch.Chapter4discussestheresearchmethodsofourstudy,includinga discussionoftheprocedureusedinsection4.2.Insection4.5weintroduceaprocess thatwehopewillspeedfuturedevelopmentandexploration.Insection4.6wediscuss ourimplementationofAntColonySystem.Finally,inchapter5wediscussourresults andlayoutareasoffuturestudy. 2

PAGE 13

CHAPTERIIDEFINITIONS Graphs Denition2.1 [Wes01]A graph , G = f V;E g isatripleconsistingofa vertexset V G ,an edgeset , E G ,andarelationthatassociateswitheachedgetwovertices notnecessarilydistinctcalledits endpoints . Agraphisrepresentedvisuallybydrawingeachvertexasapointandedgesas curvesjoiningtheendpointsoftheedge[Wes01]. Figure2.1:Agraphwith6verticesand7edges Denition2.2 [Wes01]When u and v aretheendpointsofanedgetheyare adjacent .The degree ofvertex v isthenumberofverticesadjacentto v . Lemma2.3HandshakingLemma [Wes01]If G isagraphand d v isthedegree ofvertex v in G ,then: X v 2 V G d v =2 j E G j .1 Proof: Anedgeisdenedbytwovertices,thereforesummingthedegreesof eachvertexdoublecountstheedges. Denition2.4 [Wes01]A simplegraph isagraphhavingnoloopsormultiple edges.Wespecifyasimplegraphbyitsvertexsetandedgeset,treatingtheedgeset asasetofunorderedpairsofverticesandwriting e = uv foranedge e withendpoints u and v . 3

PAGE 14

Denition2.5 [Wes01]The complement , G C ,ofasimplegraph, G ,isthesimple graphwithvertexset V G denedby uv 2 E G C ifandonlyif uv= 2 E G . Figure2.2:Agraphanditscomplement Denition2.6 [Wes01]A clique inagraphisasetofpairwiseadjacentvertices. An independentset inagraphisasetofpairwisenonadjacentvertices. Denition2.7 [Wes01]A completegraph , K n ,isasimplegraphwith n ,vertices, allofwhicharepairwiseadjacent. Figure2.3: K 5 ,thecompletegraphon5vertices Denition2.8 [Wes01]Agraphis planar ifithasadrawingwithoutcrossings. Suchadrawingisa planarembedding of G . Denition2.9 [Wes01]A face isthesmallestpossiblecycleinagraph G suchthat theregiondenedbythecyclecontainsnoedgesorvertices. 4

PAGE 15

Figure2.4:Threedierentwaysofdrawing K 4 .Eitherofthelasttwodrawingsshow K 4 isplanar. Figure2.5:Agraphwith6faces.Theouterfaceofthegraphisincludedinthecount. Proposition2.10 [Wes01]If l F i denotesthelengthofface F i inaplanegraph G , then2 j E G j = P l F i . Proof: Eachedge e in G participatesinexactly2faces.Thereforesumming thelengthofeachfacedoublecountstheedges. Denition2.11 [Wes01]The dualgraph G ofaplanargraph G isaplanargraph whoseverticescorrespondtothefacesof G .Theedgesof G correspondtotheedges of G asfollows:if e isanedgeof G withface X ononesideandface Y ontheother side,thentheendpointsofthedualedge e 2 E G arethevertices x , y of G that representthefaces X , Y of G . Aproper graphcoloring assignsacolortoavertex, v ,ofagraph, G ,sothat noadjacentvertexof v in G receivesthesamecolor.A k -coloring of G isacoloring thatuses k colors.Inapropercoloring,eachcolorclassisanindependentset,so G is k -colorableifandonlyif V G istheunionof k independentsets[Wes01]. 5

PAGE 16

Figure2.6:Agraph G highlightedinblueanditsdual G highlightedinred Denition2.12 [Wes01]The chromaticnumber ofagraph G , G ,istheleast k suchthat G is k -colorable. Denition2.13 [Wes01]Agraph G is k -chromatic if G = k .If H < G foreverypropersubgraph, H of G ,then G is color-critical or k -critical . Figure2.7:A3-coloringofagraph.Novertexisadjacenttoavertexofthesame color. Forgraphsthatarenotplanar,wemayseektomeasurehowfarawaytheyare fromachievingplanarity.Onesuchmeasureisthickness[Wes01].Determiningthe thicknessofagraphisknowntobe NP -hard[Man83]. Denition2.14 [Wes01]The thickness ofagraph G , G ,istheminimumnumberofplanargraphsinadecompositionof G intoplanargraphs. Graphscanbeembeddedonothersurfacesbesidesthesphereortheplane.We characterizethesesurfacesinthefollowingway: 6

PAGE 17

Denition2.15 [Wes01]A handle isatubejoiningtwoholescutinasurface.The torus isthesurfaceobtainedbyaddingonehandletoasphere. Denition2.16 [Wes01]The genus ofasurfaceobtainedbyaddinghandlestoa sphereisthenumberofhandlesadded;weuse S forthesurfaceofgenus .The genus ofagraph G istheminimum suchthat G embedson S . Figure2.8:Surfacesofgenus=0,1and2 Theorem2.17Euler'sFormula [Wes01]Foragraph G with v vertices, e edges and f facesonasurfaceofgenus g : v )]TJ/F18 11.9552 Tf 11.955 0 Td [(e + f =2 )]TJ/F15 11.9552 Tf 11.955 0 Td [(2 g .2 Thequantity2 )]TJ/F15 11.9552 Tf 11.956 0 Td [(2 g isknownastheEulerCharacteristic, . Theorem2.18 [Ale98]If G isagraphwithatleastthreevertices, e edgesand v vertices,then e 3 v )]TJ/F18 11.9552 Tf 11.955 0 Td [( Proof: Everyfacehasatleast3edges.By2.10,3 f 2 e and f 2 3 e .Substitutingin2.17, v )]TJ/F18 11.9552 Tf 11.955 0 Td [(e + 2 3 e .Simplfyingwearriveat e 3 v )]TJ/F18 11.9552 Tf 11.955 0 Td [( . Table2.1:By2.17,theupperboundaryofedges e forgenus g ,0 g 4 Genus 0 1 2 3 4 e 3 v )]TJ/F15 11.9552 Tf 11.956 0 Td [(6 3 v 3 v +6 3 v +12 3 v +18 VisibilityGraphs 7

PAGE 18

Somegraphscanbevisualizedintheplanebyrepresentingtheirverticesasrectangles.Thesevisualizations,specicallyRectangleVisibilityGraphs,haveapplications toVLSIdesignforcomputerchips[BDHS97]. Denition2.19 [TT86]Agraph G isa bar-visibilitygraph orBVGifitsvertices canberepresentedbyclosedhorizontallinesegmentsintheplane,pairwisedisjoint exceptpossiblyforoverlappingendpoints,insuchawaythattwovertices u and w are adjacentifandonlyifeachofthecorrespondingsegmentsisverticallyvisiblefromthe other.Thevertices u and w arecalledverticallyvisibleifthereisanon-degenerate rectangularregion B u;w the bandofvisibilityfor u and w withtwooppositesides thataresubsetsofeachofthesesegments,and B u;w intersectsnoothersegment.A setofsegmentsrealizingaBVGiscalledalayoutoftheBVG. Denition2.20 [TT86]Consideracollection R ofrectanglesintheplane,where eachrectanglehasitssidesparalleltotheaxes,andrectanglesmayshareboundary pointsbutnotinteriorpoints.Tworectangles u and v arevisibileifthereisaband ofvisibility B u;v betweenthem.The visibilitygraph of R isthegraphofthevisibility relationontheelementsof R .Agraph G isa rectangle-visibilitygraph orRVG ifitisthevisibilitygraphofsomecollection R ofrectangles; R iscalledalayoutof G . Denition2.21 [TT86]Arectangle-visibilitylayoutis noncollinear ifnotworectangleshavecollinearsides.Arectangle-visibilitylayoutis collinear iftworectangles havecollinearsides. Denition2.22 [TT86]Agraphisa weakRVG ifitisasubgraphofsomeRVG. 8

PAGE 19

CHAPTERIIILITERATUREREVIEW GraphColoringandThickness ColoringMapsandPlanarGraphs In1852,whiletryingtocoloramapofthecountiesofEngland,FrancisGuthrie conjecturedonlyfourcolorswerenecessarytoproperlycoloranymapofconnected regions[BLW76].Toaidinndingasolution,werepresentamap, M ,asaplanar graphbycreatingavertexforeachconnectedregionin M anddrawingedgesbetween verticesiftheyshareaboundaryin M .Fromthisrelationwearealsoabletocreate amapfromaplanargraph[Hut93]. AlfredKempepublishedaproofin1879[Kem79],butin1890Heawoodpublished hisndingsofaawinKempe'sproof[Hea90].Aftermanysmallsteps,aproof wasnallydiscoveredin1976byAppelandHaken[AH76,AH77,AHK77]andthe followingwasnallyarmed: Theorem3.1FourColorTheorem Everymapdrawnintheplaneoronthe surfaceofthespherecanhaveoneoffourcolorsassignedtoeachconnectedregionso thateverypairofregionswithaborderarcincommonreceivedierentcolors[Hut93]. Becauseoftheequivalencebetweenmapsandplanargraphs,wecanalsosaythat allplanargraphscanbecoloredwithatmostfourcolors. EmpireGraphs UnabletondacorrectiontotheawhefoundinKempe'sproof,Heawood proposedaproblemhethoughthecouldsolve.Givenamapthatcontainsempires, whereanempireisagroupofcountriesunitedunderoneag,howmanycolorswould themapneedifallcountriesinanempiremustbeassignedthesamecolorandno adjacentempiresshouldreceivethesamecolor[Hea90]? Heawood'sTheorem Assumethatamapcontainsempiresmadeofnomorethan M countries.Wecallthismapan M -piremap.Letthegraph, G ,betheplanargraph 9

PAGE 20

representingthe M -piremap,witheachvertexcorrespondingtoacountryandthe edgesrepresentingadjacentcountries.Createthegraph, G ,from G bycombining thesetofverticesbelongtoanempireintoonevertexandremovingmultipleedges. G isthe M -piregraphofthe M -piremap.Tosolvetheempireproblemweseeka minimumcoloringofthe M -piregraph[Hut93]. Letthenumberofverticesin G be n andthenumberofedgesin G be e . Eachvertexin G isformedfromatmost M verticesin G ,theplanargraphhaving n verticesand e edges.Theedgesandverticesof G and G compareinthefollowing way: Mn n and e e .Using2.3,wecansaythesumofdegreesof G =2 e 2 e 6 n )]TJ/F15 11.9552 Tf 11.955 0 Td [(12 6 Mn )]TJ/F15 11.9552 Tf 11.955 0 Td [(12[Hea90]. Fromthis,weconcludetheaveragevertexdegreein G : deg 1 +deg 2 + ::: +deg n n 6 M )]TJ/F16 7.9701 Tf 13.644 4.708 Td [(12 n < 6 M ,and G mustcontainavertexofdegreeatmost6 M )]TJ/F15 11.9552 Tf 11.955 0 Td [(1[Hea90]. Heawoodusethepreviousinformationtoprovethefollowing[Hea90]: Theorem3.2Heawood'sEmpireTheorem Every M -piregraph G canbe 6 M -colored Proof: Byinductionon n .If n 6 M ,then G caneasilybe6 M -coloredby placingadierentcoloroneachvertex.Assumethetheoremistrueforevery M -pire graphwithfewerthan n vertices,andlet G bean M -piregraphwith n > 6 M vertices. Findavertex v of G ofdegreeatmost6 M )]TJ/F15 11.9552 Tf 10.392 0 Td [(1;delete v andallitsincidentedges. Theresultinggraphisstillan M -piregraphandso,byinduction,canbe6 M -colored. Since v in G isadjacenttoatmost6 M )]TJ/F15 11.9552 Tf 11.37 0 Td [(1dierentcolors,thereisacoloravailable toplaceon v .Thus G is6 M -colored[Hut93]. MaximumColors AlthoughHeawoodhadshownan M -piregraphneededno morethan6 M colors,thequestionstillremained,didany M -piregraphsexistthat required6 M colors?In1983RingelandJacksonandthequestionasfollows[RJ83]: 10

PAGE 21

Theorem3.3 M -pireTheorem Forevery M> 1 thereisan M -piregraphthat requires 6 M colors.Infact,thegraphconsistingof 6 M mutuallyadjacentverticesis an M -piregraph. Inotherwords,thecompletegraphcontaining6 M vertices, K 6 M ,isan M -pire graphandis6 M -colorable.Thisresultholdsfor M> 1becausebytheFour-Color Theorem,onlyfourcolorsareneededforagraphwith M =1. Thickness n Graphs Earth/MoonGraphs In1959,Ringelputforththefollowingtwistonempire coloring[Rin59]:Imaginethemoonhasbeencolonizedandwehavebeenaskedto coloramapoftheEarthanditscoloniesontheMoonwiththefollowingrestrictions: 1.adjacentregionsonEarthorontheMoonreceivedierentcolors,and 2.acountryonEarthanditslunarcolonyreceivethesamecolor Let G m representthegraphformofthemapofthemoonand G e representthe graphformofthemapofEarth.Eachgraphisplanarasitrepresentsamap.If wecombinethegraphsbymergingacountryvertexfromthegraphofEarthwith it'scorrespondingcolonyvertexfromthegraphoftheMoon,theresultinggraph, G ,isa2-piregraph.Additionally, G hasathicknessof2sincewehaveshowna decompositionof G intotwoplanarlayers, G e and G m [Hut93]. ItisimportanttonotethatallEarth/Moongraphsare2-pires,butnotall2-pires areEarth/Moongraph.Forexample, K 9 isa2-pire,but K 9 =3. ColoringEarth/MoonGraphs BecauseEarth/MoonGraphsare2-pires,byHeawood'stheoremweknowthattheyrequireatmost6 2=12colors.Whatisnot knownisifanyEarth/Moongraphsexistthatactuallyrequire12colors[Hut93].The largestknownchromaticnumberofathickness2graphwas8untilThomSulanke discoveredanEarth/MoonGraphin1973thatrequired9colors[Gar80]. 11

PAGE 22

Sulanke'sgraphremainedthesoleknownEarth/Moongraphwithchromatic numberof9until2007whenGethnerandSulankeintroducednewthickness2graphs, includinganinnitefamilyofgraphs,allwithchromaticnumberof9[BGS08,GS09]. Currentlythemaximumnumberofcolorsneededforanythickness2graphliesin f 9 ; 10 ; 11 ; 12 g [GS09]. BeyondThickness2Graphs WecangeneralizetheEarth/Moonproblemto otherthicknesses.Let f t bethelargestchromaticnumberofanythicknesst graph, thefollowingcanbesaid[JT78]: f t 2 8 > > > > > > < > > > > > > : f 4 g if t =1, f 9 ; 10 ; 11 ; 12 g if t =2, f 6 t )]TJ/F15 11.9552 Tf 11.955 0 Td [(2 ; 6 t )]TJ/F15 11.9552 Tf 11.955 0 Td [(1 ; 6 t g if t> 2 .1 OtherSurfaces Sofarwehavediscussedgraphsonasurfaceofgenus g =0.Heawoodalso exploredgraphsfor g> 0.Let g equaltheminimumnumberofcolorsneededto coloreverygraphthatembedsonthesurfaceofgenus g [Hea90]. Theorem3.4 For g> 0 , g b = 2+ p 48 g +1 c . Table3.1:Resultsfortherstvevaluesof3.4 Genus 1 2 3 4 5 g 7 8 9 10 11 Heawood'sformulaprovidedanupperbound,butthequestionremained,isthis upperboundreached?RingelandYoungsprovedthefollowingin1968[RY68]: Theorem3.5 Thegenusof K n is d = 12 n )]TJ/F15 11.9552 Tf 10.132 0 Td [(3 n )]TJ/F15 11.9552 Tf 10.133 0 Td [(4 e ,andconsequentlyfor g> 0 , g = b = 2+ p 48 g +1 c . 12

PAGE 23

Table3.2:Resultsfortherstvevaluesof3.5 Vertices 7 8 9 10 11 Genus 1 2 3 4 5 Becausethecompletegraph, K n containsthemaximumpossibleedgesforagiven numberofvertices, n ,RingelandYoungshadsolvedtheequivalentoftheFourColor Theoremforallsurfacesexceptthesphere[Hut93]. Heawoodalsoexplored M -piremapsonsurfacesbesidesthesphere.Foran M piremaponasurfacewithgenus, g ,lettheminimumnumberofcolorsneededforall suchgraphsbedenoted g ,thenthefollowingholds[Hea90]: Theorem3.6 Forall g 0 and M 1 ,exceptforthecase g =0 and M =1 g;M b 6 M +1+ p 48 g + M +1 2 )]TJ/F16 7.9701 Tf 6.586 0 Td [(48 2 c Table3.3:Somevaluesfor3.6. M valuesrunacrossthetopand g valuesareonthe left. 1 2 3 4 5 1 7 13 19 25 31 2 8 13 19 25 31 3 9 14 20 25 31 4 10 15 20 26 32 5 11 16 21 26 32 RectangleVisibilityGraphs Characteristics ItwasshownbyWismath[KW89]thatallplanargraphshavearectanglevisibilitylayout.Additionally,ifwepartitiontheedgesofanRVG, R intotwo sets,oneset, R V ,containingallverticalvisibilityedgesandoneset, R H ,containing allhorizontalvisibilityedges,bothsets, R V and R H formaBVG.SinceaBVGis 13

PAGE 24

planar,everyRVGhasadecompositionintotwoplanarlayers.Thatis,allRVGhave thickness 2[BDHS97]. Bythefollowing,weknowtheedgeandvertexboundarieswithinwhichagraph wouldqualifyasanRVGcandidate[HSV99]: Theorem3.7 Arectangle-visibilitygraphon n 5 verticeshasatmost 6 n )]TJ/F15 11.9552 Tf 12.855 0 Td [(20 edges. Theorem3.8 Thereisaconnectedrectangle-visiblitygraphwithnverticesand 6 n )]TJ/F15 11.9552 Tf 11.955 0 Td [(20 edgesforeach n 8 . Corollary3.9 Withtheexceptionofthecases n;m = ; 16 and ; 22 ,thefollowingholdsforall n 4 : 1.foreach m with 0 m 6 n )]TJ/F15 11.9552 Tf 12.377 0 Td [(20 ,thereisarectangle-visibilitygraphwith n verticesand m edges. 2.foreach m with n )]TJ/F15 11.9552 Tf 12.157 0 Td [(1 m 6 n )]TJ/F15 11.9552 Tf 12.157 0 Td [(20 ,thereisaconnectedrectangle-visibility graphwith n verticesand m edges. Givenagraph, G with6 n )]TJ/F15 11.9552 Tf 12.083 0 Td [(20orfeweredges,ithasbeenshownrecognizing G asanRVGis np -complete[She96]. TopologicalRVG ARectangleVisibilityGraphfailstoencodeinformationaboutthegraphsuch asmultiplicitiesofvisibilitiesandthedirectionofthevisibilities.AnRVGalsoleaves outinformationaboutwhetherornotagivenrectanglecanseeinnitelyfar.a TopologicalRectangleVisibilityGraphTRVGrecordsallofthisinformationby allowingformultipleedgesbetweentworectanglesandbyframingtheentiregraph withfournewrectangles: N , S , E ,and W [SW03]. ATRVGisformallydenedinthefollowingway:Let R beasetofaxis-aligned rectangles.Thetopologicalrectanglevisibilitygraphof R consistsofapair D V ;D H 14

PAGE 25

ofgraphs.Here, D V records,withmultiplicities,theupwardlydirected,cyclically orderedverticalvisibilitiesof R [f S;N g ; D H recordswithmultiplicities,theleft-torightdirected,cyclicallyorderedhorizontalvisibilitiesof R [f W;E g [SW03]. Additionally,StrienuandWhitesidesprovideaquadratictimealgorithmforrecognizingaTRVGandamethodforbuildingavisibilitylayoutfromaTRVG[SW03]. ArticialIntelligenceAlgorithms Introduction Anagentisanythingthatreceivesinputfromanenvironmentandchoosesan actionbaseduponitsunderstandingoftheinput.Thecurrentinputvaluespassed toanagentarereferredastheagent'sstate.Fromanarticialintelligencepointof view,anagentisaprogram,theagent'sinputmaycomefromplacessuchassensors orusercommands,andtheagent'sactioncouldbesomethingassimpleaswritingon acomputerscreen,orascomplicatedasmovingaroboticarm[PR10]. Theproblemanagentseekstosolvehasvecomponents[PR10]: Theinitialstatetheagentstartsin Adescriptionofthepossibleactionsavailabletotheagent.Foragivenstate, s ,aneighborhoodfunction, N s ,returnsthesetofactionsapplicableto s Adescriptionofwhateachactiondoes,thatis,theresultofapplyingaction a tostate s Afunction, g s ,whichdeterminesif s isagoalstate Apathcostfunction, p s 1 ;s 2 ,thatdeterminesthecostofmovingbetweenthe states s 1 and s 2 Graphslendthemselveswelltothevisualizationofasearchspace.Dierentstates arerepresentedasnodesinthegraph.Edgesinthegraphrepresentvalidtransitions 15

PAGE 26

betweenstates.Weightsareaddedtoedgestorepresentthecostofmovingfromone statetoanother. Manycombinatorialoptimizationproblemshavebeenproven NP -hard.Aswalkingawayfromtheproblemisgenerallynotconsideredareasonableresponse,wemust attempttondothermethodsthatwillprovideanacceptablesolutioninanadequate amountoftime.Ontheseoccasionswereplacethepathcostfunctionwithaheuristic function.Aheuristicfunctionisamethod"...inwhichadditionalknowledgeofthe problemisimpartedtothesearchalgorithm[PR10]."Sinceanexhaustivesearchof theproblemspaceisnotpossible,weuseheuristicfunctionstohelpusmakeinformed decisionsaboutwhichactiontoapplytothecurrentstate.Additionally,sinceweare notlikelytondanoptimalsolutiontoourproblem,wereplacethegoalfunctionwith anobjectivefunctionwhichdeterminesifthecurrentstateiswithinanacceptable rangeofsolutions[PR10]. TravelingSalesmanProblem IntheTravelingSalesmanProblemTSP,asalesmanisassignedagroupofcities hemustvisit.Thesalesmanwishestostartfromhishometown,visiteachcityonce, andthenreturntohishometown.Thesalesmanknowsthecostoftravelingbetween anypairofcitiesandwantstondtheroutewiththelowestcost[DS04]. TheTSPsearchspacecanbemodeledasagraph.Eachvertexofthegraph representsacityinthesearchspace.Edgesofthegraphrepresentvalidtransitions betweencitiesandedgeweightssignifythecostoftravelingbetweentwocities. AsuccessfulsearchstrategyappliedtotheTSPwouldreturnalistrepresenting theorderthesalesmanshouldvisitthecitiesinandthetotalcostofthetour.The TSPhasbeenshowntobe NP -complete[GJ02]. Metaheuristics Metaheuristicshavedevelopedasaframeworkforapplyingheuristicstoabroader classofproblemswithsimilarcharacteristics[DS04,GP10].Heuristicmethodscan 16

PAGE 27

becategorizedinoneoftwoways:constructiveorlocalsearch.Aconstructive searchattemptstoconstructasolutioninaniterativefashion.Alocalsearchmethod attemptstomodifyanexistingsolutionbymakingsmall,iterativeimprovements [DS04]. ThereexistmanydierentheuristicmethodssuchasSimulatedAnnealing,GeneticProgramming,ParticleSwarmOptimizationandBeesAlgorithm[Bro11].We focusontwomethods:AntColonyOptimizationandTabuSearch. AntColonyOptimization Overview FirstdevelopedbyDorigo,ManiezzoandColorini[Bro11],antalgorithmsseektosolvedicultoptimizationproblemsbydrawinginspirationfromant behaviors[DS04]. Mosteveryonehasseenatonetimeoranotheragroupofantsparadingsingle le.Thisbehaviorwouldseemtoindicateacertaindegreeofintelligenceamongants butresearchhasshownsimple,individualactionsamongantsleadstomorecomplex, coordinatedbehaviorinthelargergroup[DS04,DBS06]. Asanantexploresitsenvironment,itdepositsatypeofchemicalknownas pheromone.Experimentshaveshownthatwhenanotherantcomesuponapheromone trail,itwill,withinacertainprobability,followthetrail.Thissecondantwillalso depositpheromone,increasingthepheromoneintensityofthetrail.Higheramounts ofpheromoneincreasetheprobabilitythatanantwillfollowthetrail.Alteringthe environmentthroughpheromoneplacementisanindirectcommunicationmethod knownasstigmergy.Overtime,asantscontinuetoexploreandlaypheromone,the antswillconvergeuponasinglepath,resultinginourantparade[DS04,DBS06]. AntColonyOptimizationMetaheuristic Ametaheuristicisaframeworkforapplyingheuristicstoaclassofproblems.Gendreaudenesametaheuristicas...a generalstrategyforguidingandcontrollinginnerheuristicsspecicallytailoredto theproblemsathand[GP10]." 17

PAGE 28

AntColonyOptimizationACO,isametaheuristicforantalgorithms.TheACO metaheuristicasdescribedin[DBS06]: Algorithm1: ACOMetaheuristic Setparameters,initializepheromonetrails; while terminationconditionnotmet do ConstructAntSolutions ; ApplyLocalSearch optional; UpdatePheromones ; end Inthe ConstructAntSolution phase,eachantiterativelyconstructsasolution. Duringaniterationanantchoosesacomponenttoaddtothesolutionfromasetof validcomponents,knownastheant'sneighborhood.Thecomponentchoiceisguided byaprobabilisticmethod.Aswithrealants,theprobabilityofcomponentselection isaectedbythepheromonelevelofthecomponent[DBS06]. Theoptionalphase, ApplyLocalSearch ,attemptstoapplyimprovementmethods toafullyconstructedantsolution[DBS06]. The UpdatePheromone phasemakesthecomponentsofgoodsolutionsmoreattractiveandcomponentsofbadsolutionslessattractivebymanipulatingthecomponentpheromonelevels.Membersofgoodsolutionsseetheirpheromonelevels increased,whilethemembersofbadsolutionsseetheirlevelsdecreased.Typically appliedglobally,theprocessofdecreasingpheromonelevelsisreferredtoasevaporation.Thenumberofsolutionsrecognizedasgoodsolutionsisapplicationdependent [DBS06]. CommonParameters Whiletheexactparametersofanantalgorithmcandier betweenimplementations,thereisacoregroupthattendstoremainthesame[DS04]. G ,aweightedgraphofedgesandnodesrepresentingant'ssearchspace 18

PAGE 29

,amountofpheromonedepositedonanedgebetweentwonodesin G ,pheromoneevaporationrate ,heuristicvalueofacomponentselection,typically1/edgeweightthisis separatefrompheromonelevel ,theimportanceplacedonpheromonelevelduring ConstructAntSolutions phase ,theimportanceofheuristicinformationinedgeselectionduring ConstructAntSolutions phase AntSystem Colorini,DorigoandManiezzooriginallycreatedAntSystemAS tosolvetheTravelingSalesmanProblem[CDM91].Sincethattimeithasbeen adaptedtosolveotheroptimizationproblems. WhenAntSystemisappliedtoTSP,eachantiterativelybuildsatourofcities. Giventwotowns, i and j ,wedenetheprobabilitythatanantchoosesedge ij at time t as[CDM91]: p ij = [ ij t ] [ ij ] P n j =1 [ ij t ] [ ij ] .2 Withthefollowingparameters: ij t ,thepheromonelevelonedge ij attime t ij ,thecostofedge ij ,theimportanceplacedonthepheromonelevel ,theimportanceplacedontheheuristiccostofanedge Theratiobetween and createsabalancebetweenexplorationandexploitation.Aratioinfavorof placesmoreemphasisonexploration,thatisthepheromone 19

PAGE 30

levels.Aratioinfavorof placesmoreemphasisonexploitation,thatis,theedge weightswhichrepresentouraprioriknowledgeoftheproblemspace[DS04]. Aftereachanthasbuiltatour,anyedgeparticipatinginanant'ssolutionhas ispheromonelevelincreased.If,forexample,anedgeoccursinmorethanone solution,it'spheromonewillbeincreasedtwice.Thepheromoneupdateformula variesdependingonthetypeofAntSystemimplementation[CDM91]. AntColonySystem AntColonySystemACSwasintroducedasanimprovementtoAntSystem.ACSmodiestheASapproachtoedgeselectionandpheromone updating[DG97]. ACSdenesapseudo-random-proportionaltransitionrule[DG97].Forananton anode, r ,acity, s ischosenbythefollowingequation: s = 8 > > < > > : argmax u 2 J k r f [ r;u ] [ r;u ] g ; if q q 0 otherwisereturnresultofequation3.2 .3 Withthefollowingparameters: argmax ,afunctionwhichreturnsthelargestmemberofaset q ,arandomnumberfrom,1 q 0 ,auserdeterminedvaluein[0 ; 1] J k r ,asetofnodesthe k -thantcanselectfromthatareconnectedtonode r AsinAS,theACStransitionrulestrikesabalancebetweenexplorationand exploitation,buttheparameter q 0 determineshowmuchwevalueexploitationover exploration.Largervaluesof q 0 favortheselectionofthebestedge,whilelowervalues encourageamorerandomexplorationusingequation3.2[DG97]. InACS,onlyedgesparticipatinginthegloballybesttourhavetheirpheromone levelsupdated.Theglobalupdateformulaforanedge, rs ,is[DG97]: 20

PAGE 31

r;s = )]TJ/F18 11.9552 Tf 11.955 0 Td [( r;s + r;s .4 where r;s = 8 > > < > > : L )]TJ/F16 7.9701 Tf 6.586 0 Td [(1 gb ; if r;s 2 global-best-tour 0 ; otherwise .5 withparameters: ,thepheromoneevaporationrate L gb ,thetotallengthofthegloballybesttour Restrictingpheromoneupdatetothegloballybesttourfocusesthesearchonthe areaofthebesttour. ACSalsoaddsalocalpheromoneupdatingrulethatoccursimmediatelyafteran anthasselectedanedge.Localupdatetoanedge, rs ,isdeterminedbythefollowing formula[DG97]: r;s = )]TJ/F18 11.9552 Tf 11.956 0 Td [( r;s .6 Thelocalupdatefunctiondecreasesanedge'spheromonelevel.Thegoalofthe localupdateistoshuetoursbymakinganedgethatoccursearlyinoneant'stour occurlaterinanotherant'stour.Inthiswayweencouragediversityamongthetours anddiscourageaprematuresolutionconvergencethatmayresultinasub-optimal solution. SettingParameters ThechosenparametervaluesareimportanttoanyACO implementation.Whiledierentpaperssuggestvaluesthatwecanuseasastarting point,thebestmethodistoperformexperimentstodeterminethebestvaluesfora specicimplementation[DG97]. 21

PAGE 32

Applications WhileoriginallyappliedtotheTravelingSalesmanProblem,ACS hassincebeenadaptedtoawiderangeofproblems,includingvehiclerouting,graph coloring,setcovering,Bayesiannetworksandbinpacking[DS04,DBS06]. TabuSearch LocalSearch Localsearchbeginswithaninitialsolutionthathasalreadybeen constructed.Auserdenedobjectivefunctionmeasuresthevalueofasolutions.A small,localmodicationismadetothesolutionbyaheuristicfunction,resultingin animprovedsolutionasmeasuredbytheobjectivefunction.Theprocesscontinues untiltherearenoimprovingmodicationstobemade.Becausethesearchisnot exhaustive,whenastoppingpointisreachedalocaloptimumhasbeenfound[GP10]. Thelocalsearchprocess,alsoknownasHillClimbing,canbedescribedformally as[Glo89] Algorithm2: HillClimbingHeuristic 1Selectaninitial x 2 X ; 2Selectsome s 2 S x suchthat c s x
PAGE 33

avoidingthelocaloptimumissuesencounterdduringlocalsearch[GP10].LikeACO, TSisametaheuristic[Glo89]. Theword`tabu'isusedintheTonganlanguagetorefertosomethingthatcannot betouchedbecauseitissacred[GL97].Webster'sdenesitasbannedasconstituting arisk."Wewishtoavoidariskduringasearchthatwillleadusdownafruitlesspath. Insociety,tabusaretransmittedthroughsocialcustom.Lackingasocialshaming mechanisminprograms,wetransmitknowledgeoftabuitemsthroughdatastructures instead.Bykeepingarecordoftabuitems,wecanusepasteventstoinformfuture choices[GL97]. Duringasearch,wechoosetomarkcertainmoves,thatis,thetransitionfrom onestateinthesearchspacetoanother,astabu.Wekeeparecordoftabuitemsin atabulist.Itemsremainonthetabulistforcertainlengthoftime.Assometimes happensinreallife,tabusareforgotten,or,inourcase,removedfromthetabulist. Gloverexplains,...tabusearchisbasedonthepremisethatproblemsolving, inordertoqualifyasintelligent,mustincorporateadaptivememoryandresponsive exploration[GL97]".Adaptivememoryisaccomplishedthroughtheuseoftabulists. Responsiveexploration...derivesfromthesuppositionthatabadstrategicchoice canyieldmoreinformationthanagoodrandomchoice[GL97]".Usingtabulists asmemoryforoursearchprogramwecanmakeinformeddecisionsabouthowto proceedduringthesearch.Thehopeis,ifadecisiondoesn'tturnoutwell,wecan adaptquicklysincewehaveinsightintowhythedecisionwasmadeintherstplace. SimpleTabuSearch TabuSearchissimilartolocalsearchwithanimportant distinction:whilelocalsearchalwaysseekstoselectamovetheimprovesthesolution, TSallowsfortheselectionofmovesthatareobjectivelyworse.Byallowingnonimprovingmoves,TShopestoescapethelocaloptimumproblemthathinderslocal search[GP10]. 23

PAGE 34

Inordertoavoidcyclesduringthesearch,weplaceinformationaboutmovesthat wouldundoaselectedmoveinthetabulist.Thetabulistcanbethoughtofasa formof`recencymemory'.Dependingonthecomplexityoftheproblemspacethe informationwetrackinthetabulistcanbeacollectionofattributes,oritcanbe thespecicmovethatisprohibited[GL97]. Thelengthoftimeamoveremainsonthetabulist,thetabutenure,canbea xedlength,ordetermineddynamicallybytheprogram.Atabutenureoflength n willhavenocycles n [GT93]. TabuSearchtypicallyterminateswhenoneofthefollowingthreeconditionsis met[GP10]: 1.AfteraxednumberofiterationsorCPUtime 2.Aftersomenumberofiterationswithoutanimprovementintheobjectivefunctionvalue 3.Whentheobjectivefunctionreachesapre-speciedthresholdvalue TheSimpleTabuSearchprocedureisasfollows[GP10]: Given: S ,thecurrentsolution S ,thebest-knownsolution f ,thevalueof S T ,thetabulist N S ,theneighborhoodof S ,thatis,thestatesthatcanbereachedfrom S ~ N S , N S )]TJ/F18 11.9552 Tf 11.956 0 Td [(T 24

PAGE 35

Algorithm3: SimpleTabuSearch Constructaninitialsolution, S 0 ; S = S 0 ; f = f S 0 ; S = S 0 ; T = ; ; while terminationconditionnotsatised do select S in argmin S 0 2 ~ N S [ f S 0 ]; if f S
PAGE 36

WhereIntensicationseekstolocalizeTStoasubsetofthesearchspaceidentied aspromising,DiversicationseekstodopreventTSfrombecomingtoolocalinits search.Usingknowledgeofthesearchspacesofar,Diversicationattemptstoboldly drivethesearchtowardnew,unexploredregions.Oneexampleofthisisafrequency memorywhichtrackshowoftenmovesorattributesofmovesareuses.Thesearch wouldthenpenalizethesemovesorattributesduringselection[GL97]. ExtendedTechniques ExtendedtechniquesinTSincludedeeperuseofknowledge,hybridizationandparallelization,amongothers.Deeperuseofknowledgeincludesadvancedusageofelitesolutionstocreatenewsolutionsorrememberinglocal optimasotheycanbeavoidedinthefuture.Hybridizationnusesotherheuristic methodssuchasgeneticalgorithms.Parallelizationisespeciallyusefulwhencreating neighborhoodsofasolutionstate[GP10]. Applications TabuSearchhasbeensuccessfullyappliedtomanytypesofoptimizationproblems,including:jobshopscheduling,classroomscheduling,graph coloringgraphpartitioning,vehiclerouting,travelingsalesmanproblem,computer aideddesignandfaulttolerantnetworks[GL97]. 26

PAGE 37

CHAPTERIVRESEARCHMETHODS Background Therelationbetweenthenumberofverticesinagraphandthesizeofthegraph's largestindependentsetplacealowerboundonthechromaticnumberofthegraph. Thisrelationcanbeusedtonarrowthesearchforthickness t graphsofatleast chromaticnumber n . Proposition4.1 [MoA08] Givenagraph,G,withnvertices, G n G Proof: If G isproperlycolored,thesetofverticesassignedtoaspeciccolor deneanindependentsetin G .Thesizeofthelargestindependentsetin G issignied by .Ifthevertexsetsbelongingtoeachcolorhavethesamesize, G = n .If thevertexsetsbelongingtoeachcolordonothavethesamesize,thenwehaveover counted n ,and G n .Dividingthroughby wereach G n G . Givenanindependentset, S ,ofagraph, G ,noedgesexistin G betweenany twoverticesin S .Sincethecomplementofagraphcontainsalledgesnotpresentin thegraph,theset S anditsedgesin G c formacompletesubgraph.Combiningthis knowledgeandthepreviousproposition,wearriveatthefollowing Proposition4.2 [GS09] SupposeGisagraphwithnvertices.If G c is K m -free,then G d n m )]TJ/F16 7.9701 Tf 6.587 0 Td [(1 e . Proof: Coloringtheverticesofagraphisequivalenttopartitioningthevertices intoindependentsetswhichinturnisequivalenttopartitioningtheverticesofthe complementintocompletesubgraphs. Thusif G c doesnotcontain K m thenatmost m )]TJ/F15 11.9552 Tf 10.9 0 Td [(1verticesof G canbeassigned thesamecolor,inwhichcase g d j V G j m )]TJ/F16 7.9701 Tf 6.587 0 Td [(1 e . Procedure Weseektogeneratecandidategraphsofaspecicthicknessandchromaticnumber.Thedicultyinthisprocessisndingthedecompositionofacandidategraph 27

PAGE 38

intoplanarlayers.Thefollowingapproach,describedin[GS09],generatesplanar layersrstandthen,throughaseriesoftransformationsthatpreservestheplanarity ofthelayers,attemptstotransformthelayersintoavalidcandidategraph. GenerateSolutionCandidate 1.Generate t triangulationsrepresentingtheplanarlayersofathickness t graph 2.Let G betheunionofthe t triangulations 3.Flipedgesinthetriangulationstoreducethenumberof K m in G c 4.Stopwhenno K m remainin G c Anoteonedgeipping Anedgeinaplanargraphparticipatesintwofaces. Inatriangulationallfacesaretriangles.Ifwedrawthefacesanedgeparticipatesin wehave K 4 lessanedge.Whenweipanedge,wereplaceitwiththemissingedge from K 4 ,preservingtheplanarityofthegraph. ConrmSolution Toinsureuniquenessweconrmacandidatesolutioniscriticalwiththefollowing procedure 1.Conrmeachlayerofthecandidatesolutionisplanar 2.Removeduplicateedgesremoveanyedgethatappearsinmorethanonelayer 3.Foreachedgeinthetriangulationsremoveanyedgewhichleaves G c withno K m 4.Let G betheunionoftheplanarlayers 5.Ifanyvertexof G hasdegree < d n m )]TJ/F16 7.9701 Tf 6.587 0 Td [(1 e ,reject G 6.Determinethecurrentchromaticnumberof G 28

PAGE 39

7.Ifanyvertexof G isnotcritical,reject G 8.Checkthateachedgeof G iscritical.Iftheedgeisnotcritical,removeitfrom G andit'striangulationlayer.Iftheedgeisremoved,re-runStep 5 ImplementationNotes Intheimplementationwemusttrackwhichtriangulationanedgebelongsto. Mathematica [Wol16]allowsustouseundirectededgesas keysinanassociativemap.Thisgivesustheabilitytokeepalistofdeletededges fromStep 8 anddeletetheedgesfromtheassociativemapatalatertime,anice separationofconcernsthatreducesthecomplexityoftheimplementation. ConrmSolutionUniqueness Finally,wecheckthesolutionagainstallotherknownsolutionstoconrmthe solutionisunique. ExistingSoftwareTools ThomSulankehaswrittenacollectionofutilitiesforgeneratingandmanipulating triangulations[Sul06b].Amongotherthings,theutilitiescanbeusedto; generatetriangulationsbythickness,genusandorientability viewtheadjacencymatrixoradjacencylistofatriangulation ipanedgeinatriangulation importandexporttriangulations ProblemsWithExistingTools Whilethetriangulationutilitiesareuseful,theyhavesomeimportantlimitations. Astheutilitiesarewrittennow,theycanonlycreateonetriangulationatatime.This isusefulifauserwantstohoneinonthecreationofaspecictriangulationbutit becomesaslowdownforsomeonelookingtousethesetoolstowritesoftwarethat usesthetriangulationstogeneratecandidatesolutionsastheymusttakethetime 29

PAGE 40

tounderstandthetoolandbuildaprocessforgeneratingthetriangulationsintheir owncode. TheutilitiesarewrittenintheClanguage.Anyonelookingtousetheutilities musttheneitherwritetheirowncodeinC,orusealanguagewiththecapabilityof callingCcode.WhileitiscertainlypossibletocallCcodefromprogramswritten inotherlanguages,thisisanadditionallevelofcomplexityontopofanalready complexproblem.WritingcodeinCisalsonotwithoutitsownchallenges.Asa lowerlevellanguage,itrequiresmorecodethanhigherlevellanguages.Codewritten inCismorepronetocodeerrorsbecauseofuserpointermanagement,alackofcode frameworks,debuggingandtestingtoolsarelessprominentandmorecumbersometo use. BuildingAProcess Weseekawaythatallowsustoleveragetheexistingsoftwaretoolswhilefreeing usfromtheircurrentrestraints. ProcessDenition Wedeneaprocessthatcanbebrokenintofourmajorsteps 1.Createtriangulations 2.Applyaprocess/algorithmtothetriangulationstoidentifypotentialsolutions 3.Identifyapotentialsolutionasavalidsolution 4.Determineifthesolutionispreviouslyundiscovered Theonlypartoftheprocesslikelytochangeisthealgorithmappliedtoidentify potentialsolutions.Bybuildingaseparateprogramtohandleeachstepoftheprocess wespeedupfutureimplementationssincethecodeforthreeofthestepsisreusable. Bydecouplingthestepsintotheirownprogramstheybecomeeasiertomaintain, 30

PAGE 41

andremovelanguagerestrictionsonalgorithmimplementations.Theseparateprogramsdeneapipelinewheredataowsintoandoutofeachprocessbywayofa standardizedleformat. Input/OutputFormats Wedenestandardinputandoutputleformatsbetweentheprocesssteps.The formatsareasfollows: TriangulationGenerationOutput/SolutionGeneration Line1 1.thethicknessofallgraphsinthele 2.thenumberofverticesforallgraphsinthele 3.thegenusofallgraphsinthele lines2throughtheend 1.onetriangulationinlexformat Lexformatisawayofcompactlyencodingtheinformationaboutatriangulation. Inlexformat,everygroupofof3lettersrepresentsaface.Forexample,abc" wouldrepresentthefacedenedbytheedges ab , bc and ca .Giventhelexstring ofatriangulation,thenumberoffacesinthetriangulationequalsthestringlength dividedby3. Every thickness numberoflinesrepresentsthetriangulationsforathickness t graph.If,forexample, thickness =2,every2linesoflexstringsrepresentthelayers ofonegraph. SolutionOutput/ColoringInput Onegraphperle Line1 31

PAGE 42

2,17,0 abgabpacfacladeadfaehaghalpbcdbclbdjbegbejblpcdncficiocnodejdfidinegkehqekq abfabmaceackadjadpaepafnagjagnakmbckbcobdfbdobkqbmqcdicdocelchichldehdepdfg Figure4.1:Exampleoutputfromthetriangulationgenerationstep 2,17,0 0,10,abcabd,bcdbde 10,0,abcabd,bcdbde Figure4.2:Exampleoutputfromphase2 1. n ,thenumberofvertices 2. m ,thesizeofthecompletegraphremovedfromthecomplementofthe unionofthetriangulations 3. g ,thegenusofthegraph lines2through t 1.Numberofiterationssofar 2.Numberof K m remaininginthecomplement 3.Triangulationoflayer1inlexformat 4.Triangulationoflayer2inlexformat 32

PAGE 43

ImplementationofSolutionConrmation Thesolutionconrmationwaswrittenwith Mathematica [Wol16]asitoersa veryexiblenativegraphtype.Additionallyitoerstestingabilitiesoutofthe boxwithnoadditionalneedforconguration.Theconrmationprogramcanberun fromthecommandline,whichgivesusthepotentialtouseitaspartofanautomated processinthefuture. AntColonyImplementation WeusedAntColonySystemtogeneratesolutioncandidates.Thecostfunction, ,returnstheinverseofthenumberof K m inthecomplement.Inthisway,fewer K m inthecomplementaremadetoappearmoredesirable.Eachantisgivenacopyof thestartingtriangulationsreadfromthetriangulationinputleandthenexecutesa sequenceofedgeips.Inadditiontorememberingthesequenceofedgeips,theant mustalsotrackwhichtriangulationanedgebelongedtoandthecostoftheedgeip thenumberof K m inthecomplement.Theantmustalsoupdatethestateofthe triangulationsaftereachedgeipsothatitchoosesfromavalidlistofavailableedge ipsinthenextiteration. Therandomnatureoftheedgeipsmeansthereisnoguaranteethelastedge ipisthebest.Forthisreason,afteranantisnished,wedetermineatwhatpoint duringthesequencethefewest K m inthecomplementwasreached.Fromthispoint onweconsidertheant'ssequencetogofromit'srstedgeiptotheedgeipthat achievedthelowestscore. Thefollowingparametervalueswereused: =1 =30 =0 : 01 Q 0 =0 : 1 33

PAGE 44

maximumantedgeipsperiteration= n n )]TJ/F15 11.9552 Tf 11.955 0 Td [(1 10 ;n = j V G j maximumiterations=1000 34

PAGE 45

CHAPTERVFINDINGS Results AntTuning AntColonyparametervaluesareproblemspecicandneedtobetunedforthe problemathand.DorigorecommendsthefollowingbasevaluesforTravelingSalesmanimplementationsoftheAntColonySystemACSalgorithm,where m isthe numberofantsand C nn isthecostofthenearestneighboralgorithmrunonthe searchgraph[DS04]. Table5.1:RecommendedsettingsbyDorigoforACSimplementations. m 0 1 2to5 0.1 10 1 C nn BecauseofthesimilarityoftheTravelingSalesmanproblemwiththeedgeipping procedure,weusedDorigo'srecommendedvaluesasastartingpoint. Beta Inthepseudo-random-proportionaltransitionruleoftheACSseeequation 3.3, determineshowmuchinuencetheheuristicmeasureofanedgehasonthe selectionoftheedge.Largervaluesof increasetheinuenceoftheheuristicmeasure. Weusedagraphofthickness =2,vertices v =17andgenus g =0totestthe eectdierentvaluesof hadcomparedwithdierentnumbersofants.TheACS implementationwasrunvetimesforeachcombinationofvalues.Theresultscan befoundinappendixsomethingD. Fromthetuningrunsyoucanseethatwhenthenumberofantsis8,10or16the numberofiterationsaresimilar,nomatterthevalueof .Interestingly,thenumber ofiterationswhen =5aregreaterthanothervaluesof .Thismayactuallybea desirablebehaviorsincewewanttodiscouragetheantsfromconvergingonasolution tooquicklybecauseaquickconvergencecouldmeantheantsarenotexploringenough ofthesearchspace. 35

PAGE 46

FurtherTuning Itishardtodrawadeepconclusionfromthetuningresults wehavesofar.DorigoandGambardellaintroducedthe -branchingfactortohelp facilitateadeeperviewoftheeectivenessofparameterselections.The -branching factormeasuresateachiterationthenumberofqualityedgesananthastochoose fromwhenitisonagivenvertexinthesearchgraph[DS04].Thismeasurewould giveamuchdeepervieweroftheeectsagroupofparametervalueshaveoncreating aqualitysearchspace.AtthistimeourACScodeisnotabletoproduceinformation aboutthe -branchingfactor,althoughitwouldbeahelpfuladditioninthefuture. SelectingTargets Wemustdeterminethethickness,size,genusand K m toremovefromthecomplementofagraphbeforewecanapplytheACSsearchalgorithm. Lemma5.1 Theaveragevertexdegree, D ,ofagraph, G ,withthickness, =2 , v vertices,andgenus, g is: D 12+ 24 g )]TJ/F15 11.9552 Tf 11.955 0 Td [(1 v .1 Proof: Bytheorem2.18,aplanargraph, G ofgenus g hasedges, e 3 v )]TJ/F18 11.9552 Tf 10.396 0 Td [( .A planargraphofthickness, =2has e 2 3 v )]TJ/F18 11.9552 Tf 9.593 0 Td [( edges.Simplied, e 6 v +12 g )]TJ/F15 11.9552 Tf 9.592 0 Td [(12. Theaveragevertexdegree, D ,ofagraph, G ,is: D = 2 e v .Substitutingfromabove wehave D 2 v +12 g )]TJ/F16 7.9701 Tf 6.587 0 Td [(12 v ,andsimplifyingweobtain D 12+ 24 g )]TJ/F16 7.9701 Tf 6.586 0 Td [(1 v . Theorem5.2 Anygraph, G ,withaveragedegree = d canbecoloredwithatmost d +1 colors. Proof: Bywayofcontradiction,assumethatanygraphwithaveragedegree d cannotbecoloredwith d +1colors.Byinduction,anygraph, G ,with d +1or fewerverticescanbecoloredwith d +1colors.Let G 0 bethegraphofaveragevertex degree d andonemorevertexthan G .Since G 0 hasaveragevertexdegree d ,there mustexistatleastonevertexofdegree d )]TJ/F15 11.9552 Tf 11.364 0 Td [(1.Findthisvertex, v andremoveitfrom G 0 . G 0 )]TJ/F18 11.9552 Tf 12.162 0 Td [(v has d +1vertices,andbytheinductionhypothesis,canbecoloredwith 36

PAGE 47

d +1colors.Color G 0 )]TJ/F18 11.9552 Tf 11.607 0 Td [(v with d +1colors.Add v backto G 0 )]TJ/F18 11.9552 Tf 11.607 0 Td [(v .Since v has d )]TJ/F15 11.9552 Tf 11.607 0 Td [(1 neighbors,wewillneedatmost d colorstocolor v anditsneighbors.Thus G 0 canbe coloredwithatmost d +1colors,acontradiction. Proposition5.3 Agraph, G with v vertices,chromaticnumber and K m removed fromthecomplementof G has v> )]TJ/F15 11.9552 Tf 11.955 0 Td [(1 m )]TJ/F15 11.9552 Tf 11.955 0 Td [(1 . Proof: Byproposition4.2,agraph, G with v verticesand K m removedfrom thecomplementof G haschromaticnumber G d v m )]TJ/F16 7.9701 Tf 6.587 0 Td [(1 e ,or d v m )]TJ/F16 7.9701 Tf 6.586 0 Td [(1 e > )]TJ/F15 11.9552 Tf 12.76 0 Td [(1. Rearrangingthetermswearriveat v> )]TJ/F15 11.9552 Tf 11.956 0 Td [(1 m )]TJ/F15 11.9552 Tf 11.955 0 Td [(1. Foragivenchromaticnumber,wecanuselemma5.1andproposition5.3tohelp usdeterminewhichparametersweneedtondagraphwithaparticularchromatic number. TargetsandResults Isthechromaticnumberofanythicknesstwographwithgenus g =2 14 ? Weattempttoshowthatthelargestchromaticnumberofathicknesstwograph withgenus g =2is14byndingadecompositionof K 14 intotwoplanarlayersusing ourACSimplementation.Firstwedeterminetheparameters: Bylemma5.1, D 12+ 24 )]TJ/F16 7.9701 Tf 6.586 0 Td [(1 v 12+ 24 v .Toreach =14, D 13bytheorem 5.2,so13 12+ 24 v and1 24 v .Byproposition5.3, v> )]TJ/F15 11.9552 Tf 10.874 0 Td [(1 m )]TJ/F15 11.9552 Tf 10.874 0 Td [(1 > 13 m )]TJ/F15 11.9552 Tf 10.874 0 Td [(1. For m =2, v> 13 )]TJ/F15 11.9552 Tf 11.955 0 Td [(1 > 13.With v =14,1 24 14 3 : 2holdstrue. Nowweconrmthetotaledgesin K 14 areatmostequaltothetotalpotential edgesinagraphwith =2andgenus g =2.Simplifying j E K 14 j 6 v +12 g )]TJ/F15 11.9552 Tf 12.035 0 Td [(12 wereach91 96andweconcludethatitispossiblefor K 14 tohavethickness =2 ongenus g =2. UsingourACSimplementationtoremove K 2 fromthecomplementoftheunion oftwotriangulations,bothwith v =14ongenus g =2,wefoundadecomposition 37

PAGE 48

of K 14 seeAppendixC.Weconcludethatforthickness, =2,genus, g =2,the largestpossiblechromaticnumber, =14. Isthechromaticnumberofanythicknesstwographwithgenus g =3 15 ? Weattempttoshowthatthelargestchromaticnumberofathicknesstwograph withgenus g =3is15byndingadecompositionof K 15 intotwoplanarlayersusing ourACSimplementation.Firstwedeterminetheparameters: Bylemma5.1, D 12+ 24 )]TJ/F16 7.9701 Tf 6.586 0 Td [(1 v 12+ 48 v .Toreach =15, D 14bytheorem 5.2,so14 12+ 48 v and2 48 v .Byproposition5.3, v> )]TJ/F15 11.9552 Tf 10.874 0 Td [(1 m )]TJ/F15 11.9552 Tf 10.874 0 Td [(1 > 14 m )]TJ/F15 11.9552 Tf 10.874 0 Td [(1. For m =2, v> 14 )]TJ/F15 11.9552 Tf 11.955 0 Td [(1 > 14.With v =15,2 48 15 3 : 2holdstrue. Nowweconrmthetotaledgesin K 15 areatmostequaltothetotalpotential edgesinagraphwith =2andgenus g =3.Simplifying j E K 15 j 6 v +12 g )]TJ/F15 11.9552 Tf 12.035 0 Td [(12 wereach105 114andweconcludethatitispossiblefor K 15 tohavethickness =2ongenus g =3. UsingourACSimplementationtoremove K 2 fromthecomplementoftheunion oftwotriangulations,bothwith v =15ongenus g =3,wefoundadecomposition of K 15 seeAppendixC.Weconcludethatforthickness, =2,genus, g =3,the largestpossiblechromaticnumber, =15. Isthechromaticnumberofanythicknesstwographwithgenus g =4 16 ? Weattempttoshowthatthelargestchromaticnumberofathicknesstwograph withgenus g =4is16byndingadecompositionof K 16 intotwoplanarlayersusing ourACSimplementation.Firstwedeterminetheparameters: Bylemma5.1, D 12+ 24 )]TJ/F16 7.9701 Tf 6.586 0 Td [(1 v 12+ 72 v .Toreach =16, D 15bytheorem 5.2,so15 12+ 72 v and3 72 v .Byproposition5.3, v> )]TJ/F15 11.9552 Tf 10.874 0 Td [(1 m )]TJ/F15 11.9552 Tf 10.874 0 Td [(1 > 15 m )]TJ/F15 11.9552 Tf 10.874 0 Td [(1. For m =2, v> 15 )]TJ/F15 11.9552 Tf 11.955 0 Td [(1 > 15.With v =16,3 72 15 4 : 5holdstrue. 38

PAGE 49

Nowweconrmthetotaledgesin K 16 areatmostequaltothetotalpotential edgesinagraphwith =2andgenus g =4.Simplifying j E K 16 j 6 v +12 g )]TJ/F15 11.9552 Tf 12.035 0 Td [(12 wereach120 132andweconcludethatitispossiblefor K 16 tohavethickness =2ongenus g =4. UsingourACSimplementationtoremove K 2 fromthecomplementoftheunion oftwotriangulations,bothwith v =16ongenus g =4,wefoundadecomposition of K 16 seeAppendixC.Weconcludethatforthickness, =2,genus, g =4,the largestpossiblechromaticnumber, =16. Isthechromaticnumberofanythicknesstwographwithgenus g =5 17 ? Weattempttoshowthatthelargestchromaticnumberofathicknesstwograph withgenus g =5is17byndingadecompositionof K 17 intotwoplanarlayersusing ourACSimplementation.Firstwedeterminetheparameters: Bylemma5.1, D 12+ 24 )]TJ/F16 7.9701 Tf 6.586 0 Td [(1 v 12+ 96 v .Toreach =17, D 16bytheorem 5.2,so16 12+ 96 v and4 96 v .Byproposition5.3, v> )]TJ/F15 11.9552 Tf 10.874 0 Td [(1 m )]TJ/F15 11.9552 Tf 10.874 0 Td [(1 > 16 m )]TJ/F15 11.9552 Tf 10.874 0 Td [(1. For m =2, v> 16 )]TJ/F15 11.9552 Tf 11.955 0 Td [(1 > 16.With v =17,4 96 17 5 : 64holdstrue. Nowweconrmthetotaledgesin K 17 areatmostequaltothetotalpotential edgesinagraphwith =2andgenus g =5.Simplifying j E K 17 j 6 v +12 g )]TJ/F15 11.9552 Tf 12.035 0 Td [(12 wereach136 150andweconcludethatitispossiblefor K 17 tohavethickness =2ongenus g =5. UsingourACSimplementationtoremove K 2 fromthecomplementoftheunion oftwotriangulations,bothwith v =17ongenus g =5,wefoundadecomposition of K 17 seeAppendixC.Weconcludethatforthickness, =2,genus, g =5,the largestpossiblechromaticnumber, =17. Canwendadditionalgraphswithchromaticnumber =9 having thickness =2 ongenus g =0 ? 39

PAGE 50

Byproposition4.2, d 17 2 e =9.UsingtheACSimplementation,wehaveproduced 97resultswith v =17verticesand K 3 removedfromthecomplement.Ofthese,we haveconrmed2asuniqueresultsseeAppendixC. Doesthereexistagraphwithchromaticnumber =10 havingthickness =2 ongenus g =0 ? Byproposition4.2, d 19 2 e = d 28 3 e = d 29 3 e =10.Wewereunabletondanygraphs with =10.Table5.2summarizestheresults. Table5.2:ResultsFor =10Search Vertices K m removed Fewest K m InComplement 19 3 5 28 4 6 29 4 55 FutureStudy Ourcurrentworkhasbeenlimitedtographsofrelativelysmallsize.Webelieve thatmoreinterestingresultsmaybefoundbyexpandingthesearchtolargergraph sizes.Toaccomplishthisgoal,wewillneedprogramsthatmakeecientuseof memoryandspeed.WebelievethatanimplementationofTabuSearchmaybeableto handlelargergraphsthanthecurrentAntColonyimplementation.Implementations thatareabletoexploitparallelprocessingwouldalsoaidinexploringlargergraph sizes. Findingawaytoenhancethecurrentheuristictoevaluatemoreinformation aboutthesearchgraphmayalsohelptoguidethesearchinabetterway.Tothat end,creatingadatabaseofknowngraphsandtheirattributesmayhelptoidentify othergoodheuristicmeasures.Discoveringasmanygraphsaspossible,eveniftheydo notprovideuswithnewresults,wouldbehelpfulingrowingthesizeofthedatabase. BigDataanalysistechniquesmayalsohelponceadatabaseisgenerated. 40

PAGE 51

BIBLIOGRAPHY [ABG10]MichaelO.Albertson,DebraL.Boutin,andEllenGethner.The thicknessandchromaticnumberof r -inatedgraphs. DiscreteMath. , 310:2725{2734,2010. [AH76]K.AppelandW.Haken.Everyplanarmapisfourcolorable. Bull. Amer.Math.Soc. ,82:711{712,091976. [AH77]K.AppelandW.Haken.Everyplanarmapisfourcolorable.parti: Discharging. IllinoisJ.Math. ,21:429{490,091977. [AHK77]K.Appel,W.Haken,andJ.Koch.Everyplanarmapisfourcolorable. partii:Reducibility. IllinoisJ.Math. ,21:491{567,091977. [Ala12]RoqyahR.Alalqam.Heuristicmethodsappliedtodicultgraphtheory problems,2012. [Ale98]PSAlexandrov.Combinatorialtopology.1998. [BDHS97]ProsenjitBose,AliceDean,JoanHutchinson,andThomasShermer. Onrectanglevisibilitygraphs ,pages25{44.SpringerBerlinHeidelberg, Berlin,Heidelberg,1997. [BGS08]DebraL.Boutin,EllenGethner,andThomSulanke.Thickness-two graphs.I.Newnine-criticalgraphs,permutedlayergraphs,andCatlin's graphs. J.GraphTheory ,57:198{214,2008. [BLW76]NormanBiggs,EKeithLloyd,andRobinJWilson. GraphTheory, 1736-1936 .OxfordUniversityPress,1976. [Bre79]DanielBrelaz.Newmethodstocolortheverticesofagraph. Commun. ACM ,22:251{256,April1979. [Bro11]JasonBrownlee. CleverAlgorithms:Nature-InspiredProgramming Recipes .Lulu.com,1stedition,2011. [CDM91]AColorini,MDorigo,andVManiezzo.Distributedoptimizationby antcolonies.the1steuropeanconf. ArticialLife,Pans,France ,1991. [DBS06]MarcoDorigo,MauroBirattari,andThomasStutzle.Antcolonyoptimization. IEEEcomputationalintelligencemagazine ,1:28{39,2006. [DEMHP08]AliceM.Dean,JoannaA.Ellis-Monaghan,SarahHamilton,andGreta Pangborn.Unitrectanglevisibilitygraphs. Electron.J.Combin. , 15:ResearchPaper79,24,2008. [DG97]M.DorigoandL.M.Gambardella.Antcolonysystem:Acooperativelearningapproachtothetravelingsalesmanproblem. Trans.Evol. Comp ,1:53{66,April1997. 41

PAGE 52

[Dha06]AshayDharwadker.Thevertexcoloringalgorithm. unpublished ,2006. [DHM03]MikeDevelin,StephenHartke,andDavidPetrieMoulton.Ageneral notionofvisibilitygraphs. DiscreteComput.Geom. ,29:511{524, 2003. [DS04]MarcoDorigoandThomasStutzle. AntColonyOptimization .Bradford Company,Scituate,MA,USA,2004. [Eng06]AndriesPEngelbrecht. Fundamentalsofcomputationalswarmintelligence .JohnWiley&Sons,2006. [FM08]DarioFloreanoandClaudioMattiussi. Bio-inspiredarticialintelligence:theories,methods,andtechnologies .MITpress,2008. [Gar80]MartinGardner.Mathematicalgames. Scienticamerican ,242:14{19, 1980. [GJ02]MichaelRGareyandDavidSJohnson. Computersandintractability , volume29.whfreemanNewYork,2002. [GL97]FredGloverandManuelLaguna. TabuSearch .KluwerAcademicPublishers,Norwell,MA,USA,1997. [Glo89]FredGlover.Tabusearchparti. ORSAJournaloncomputing ,1:190{ 206,1989. [Glo90]FredGlover.Tabusearchpartii. ORSAJournaloncomputing ,2:4{ 32,1990. [GP10]MichelGendreauandJean-YvesPotvin. TabuSearch ,pages41{59. SpringerUS,Boston,MA,2010. [GS09]EllenGethnerandThomSulanke.Thickness-twographs.II.More newnine-criticalgraphs,independenceratio,clonedplanargraphs,and singlyanddoublyouterplanargraphs. GraphsCombin. ,25:197{217, 2009. [GT93]FredGloverandEricTaillard.Auser'sguidetotabusearch. Annalsof operationsresearch ,41:1{28,1993. [Hea90]P.J.Heawood.Mapcolourtheorem. Quart.J.PureAppl.Math. , 24:332{338,1890. [HSV99]JoanP.Hutchinson,ThomasShermer,andAndrewVince.Onrepresentationsofsomethickness-twographs. Comput.Geom. ,13:161{171, 1999. [Hut93]JoanP.Hutchinson.Coloringordinarymaps,mapsofempiresandmaps ofthemoon. Math.Mag. ,66:211{226,1993. 42

PAGE 53

[JT78]TommyR.JensenandBjarneToft.Topologicalgraphtheory,inselected topicsingraphtheory,lwbeinekeandrjwilson,eds.,15{50,1978. [JT95]TommyR.JensenandBjarneToft. GraphColoringProblems .WileyInterscienceSeriesinDiscreteMathematicsandOptimization.JohnWiley&Sons,NewYork,1995. [Kem79]AlfredBKempe.Onthegeographicalproblemofthefourcolours. Americanjournalofmathematics ,2:193{200,1879. [KW89]DavidKirkpatrickandStephenWismath.Weightedvisibilitygraphsof barsandrelatedowproblems. AlgorithmsandDataStructures ,pages 325{334,1989. [LR79]AristidLindenmayerandGrzegorzRozenberg.Parallelgenerationof maps:Developmentalsystemsforcelllayers.In Graph-grammars andtheirapplicationtocomputerscienceandbiology ,pages301{316. Springer,1979. [Man83]AnthonyManseld.Determiningthethicknessofgraphsisnp-hard. In MathematicalProceedingsoftheCambridgePhilosophicalSociety , volume93,pages9{23.CambridgeUnivPress,1983. [MoA08]D.MarcusandMathematicalAssociationofAmerica. GraphTheory: AProblemOrientedApproach .MAAtextbooks.MathematicalAssociationofAmerica,2008. [PR10]StuartPeterRussel.Norvig. ArticialIntelligence.AModernApproach ,2010. [Rin59]GerhardRingel. FarbungsproblemeaufFlachenundGraphen ,volume2. VEBDeutscherVerlagderWissenschaften,1959. [RJ83]GerhardRingelandBradJackson.Solutionofheawood'sempireproblemintheplane. JournalfurdiereineundangewandteMathematik , 347:146{153,1983. [RY68]GerhardRingelandJohnWTYoungs.Solutionoftheheawoodmapcoloringproblem. ProceedingsoftheNationalAcademyofSciences , 60:438{445,1968. [She96]ThomasCShermer.Onrectanglevisibilitygraphs.iii.externalvisibility andcomplexity.In CCCG ,volume96,pages234{239,1996. [Sul06a]ThomSulanke.Generatingirreducibletriangulationsofsurfaces. arXiv preprintmath/0606687 ,2006. [Sul06b]ThomSulanke.Triangulationmanipulationsoftware,2006. 43

PAGE 54

[SW03]IleanaStreinuandSueWhitesides.Rectanglevisibilitygraphs:characterization,construction,andcompaction.In STACS2003 ,volume2607 of LectureNotesinComput.Sci. ,pages26{37.Springer,Berlin,2003. [TT86]RobertoTamassiaandIoannisGTollis.Auniedapproachtovisibility representationsofplanargraphs. Discrete&ComputationalGeometry , 1:321{341,1986. [Wes01]DouglasB.West. Introductiontographtheory ,volume2.PrenticeHall UpperSaddleRiver,2001. [Wol16]WolframResearch,Inc.Mathematica,2016. 44

PAGE 55

APPENDIXATriangleGeneration / main.c entrypointfortriangulation )]TJ/F17 5.9776 Tf 5.998 0 Td [(generatorprogram / #include < stdio.h > #include < stdlib.h > #include < triang.h > #include < time.h > mainintargc,char argv[] f //positionofcommandlinearguments constintTHICKNESS IDX=1; constintNUM VERTICES IDX=2; constintGENUS IDX=3; constintFILE NAME IDX=4; constintNUM GROUPS IDX=5;//optionalargument constintNUM REQUIRED ARGS=5; constintMAX ARGS=6; //commandlineargs,shouldusesametypeasrequiredbysulankefunctions intthickness;//thicknessofthegraph,foreachgroupgeneratethisnumberoftriangulations intnum vertices;//numberofverticesinthegraph intgenus;//genusofthegraph intorient=1;//1ifthesurfaceisorientable,0ifnot,use1asdefault char file name;//nameoftheoutputfile intnum groups=10;//howmanygroupsoftriangulationstogenerate,eachgroupwillhavethicknessnumberoftriangulations //loopcontrols,triang,filestreamargs... inti,j; FILE outfile; structtriangt; //seedrandomgenerationforuseincreate triang srandtimeNULL; //checkthat#ofargumentsiscorrect ifargc < NUM REQUIRED ARGS jj argc > MAX ARGS f //writeerrortoconsoleandexit printf"Toofewortoomanyarguments. n n%iargumentsreceived. n nAminimumof%iisrequiredandamaximumof%iispermitted n n",argc,NUM REQUIRED ARGS,MAX ARGS; return; g //readcommandlinevaluestovariables thickness=atoiargv[THICKNESS IDX]; num vertices=atoiargv[NUM VERTICES IDX]; genus=atoiargv[GENUS IDX]; //ifuserspecifiedoptional7thargument,setnum groups ifargc==MAX ARGS f //setnum groups num groups=atoiargv[NUM GROUPS IDX]; g 45

PAGE 56

//openfile outfile=fopenargv[FILE NAME IDX],"w"; //writefirstlinetofile fprintfoutfile,"%i,%i,%i,%i n n",thickness,num vertices,genus,num groups; fori=0;i < num groups;i++ f forj=0;j < thickness;j++ f //generatetriangulation create triang&t,num vertices,genus,orient; //writetrianglextofile write triang lex&t,outfile; fprintfoutfile," n n"; g g //bekind,closethefilestream fcloseoutfile; g / includefiletobeusedinuser'sprograms / #include < stdio.h > #include < stdlib.h > #include < string.h > #defineMAX V128 #defineMAX EMAX V MAX V )]TJ/F17 5.9776 Tf 6.304 0 Td [(1/2 #defineMAX FMAX E/3 2 #defineMAX CODEMAX E+MAX E+MAX V+4 structtriang f / triangulation / intnv;//#vertices intne;//#edges intnf;//#faces intorient;/ oriented?notsameasorientable, )]TJ/F17 5.9776 Tf 5.596 0 Td [(1notyetdetermined / intgenus;/ genusofsurface =numberofhandlesor=numberofcrosscaps )]TJ/F17 5.9776 Tf 5.596 0 Td [(1notyetdetermined / intedge[MAX V][MAX V];//triangulationlist[ROW][COL]and[COL][ROW]havedifferentvalues,possiblesinceanyedgecanbepartofatmost2faces g ; voidadd edgestructtriang t,intv1,intv2; voidadd facestructtriang t,intv1,intv2,intv3; voidcanonstructtriang t,charcode[],intmapping[]; voidcanonlexstructtriang t,char text; intcan contractstructtriang t,intv1,intv2,int o1,int o2; intcheck triangstructtriang t,char caller; 46

PAGE 57

voidclear triangstructtriang t,intv; voidcontract edgestructtriang t,intv1,intv2,into1,into2; voidcopy triangstructtriang s,structtriang t; intcount triangstructtriang t; intcount triang2structtriang t; voidcreate triangstructtriang t,intv,intgenus,intorient; voidcreate triang4structtriang t,intv,intgenus,intorient; voidcut handlestructtriang t,intv1,intv2,intv3,intv4; voidcycle typestructtriang t,intv[MAX V],intn,int type,intgenus[2],intorient[2],intnv[2],intne[2],intnf[2]; intdecode triangchar text,structtriang t; intdecode triang lexchar text,structtriang t; intdecode unfold triangchar text,structtriang t,intborder[MAX V][MAX V]; voidencode planar codestructtriang t,charcode[]; intfind flipstructtriang t,intv1,intv2,int v3,int v4; voidflip edgestructtriang t,intv1,intv2,intv3,intv4; voidget complementstructtriang t; intnear triangstructtriang t; intoppositestructtriang t,intv1,intv2,intv3; voidpermute triangstructtriang t,intv1,intv2; voidprint asciistructtriang t; voidprint neighborsstructtriang t; voidprint triangstructtriang t; voidran flip triangstructtriang t,intntimes; intread triangstructtriang t; intread triang lexstructtriang t; intreduce triangstructtriang t,intnv; intreduce triang4structtriang t,intnv; voidremove degree3 vertexstructtriang t,intv; 47

PAGE 58

voidremove facestructtriang t,intv1,intv2,intv3; voidscramble triangstructtriang t; voidsplit vertexstructtriang t,intv1,intv2,intv3,intv4; voidtestcanon first init triangstructtriang t,intgivenedge[3],intrepresentation[],intmapping[],intcolour[]; voidtestcanon init triangstructtriang t,intgivenedge[3],intrepresentation[],intmapping[],intcolour[]; voidunfold canonstructtriang t,intborder[MAX V][MAX V],int nv unfold,charcode[],intmapping[]; voidunfold testcanon initstructtriang t,intnv unfold,intv border[MAX V],intr border[MAX V],intborder length,intdir,intiborder,intlabel[MAX V][MAX V],intborder[MAX V][MAX V],intrepresentation[],intmapping[],intcolour[]; voidunfold triangstructtriang t,intborder length,intv border[MAX V],int nv unfold,charcode[],intmapping[]; intwrite triang lexstructtriang t,FILE outfile; staticinta2i[128]= f )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.081 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.081 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.081 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.081 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.081 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.55 0 Td [(1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51, )]TJ/F17 5.9776 Tf 6.55 0 Td [(1, )]TJ/F17 5.9776 Tf 6.549 0 Td [(1, )]TJ/F17 5.9776 Tf 6.549 0 Td [(1, )]TJ/F17 5.9776 Tf 6.55 0 Td [(1, )]TJ/F17 5.9776 Tf 6.549 0 Td [(1, )]TJ/F17 5.9776 Tf 6.03 0 Td [(1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25, )]TJ/F17 5.9776 Tf 6.526 0 Td [(1, )]TJ/F17 5.9776 Tf 6.527 0 Td [(1, )]TJ/F17 5.9776 Tf 6.526 0 Td [(1, )]TJ/F17 5.9776 Tf 6.527 0 Td [(1, )]TJ/F17 5.9776 Tf 6.526 0 Td [(1 g ; staticchari2a[52]= f 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' g ; / addonefacetoatriangulation / #include < triang.h > voidadd facestructtriang t,intv1,intv2,intv3 f #ifDEBUG ifv1==v2 jj v1==v3 jj v2==v3 f printf"add face:vertices%d,%dand%dmustbedistinct. n n", v1,v2,v3; exit0; g ifv1 < 0 jj v1 > =t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv jj v2 < 0 jj v2 > =t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv jj v3 < 0 jj v3 > =t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv f printf"add face:vertex%d,%dor%doutofrange.mustbebetween0and%d. n n", v1,v2,v3,t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv; exit0; g #endif ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> orient==1 f #ifDEBUG ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f printf"add face:can'taddface%d,%d,%d.aface%d,%d,%dalreadyexists. n n", 48

PAGE 59

v1,v2,v3,v1,v2,t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]; exit0; g ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v3]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f printf"add face:can'taddface%d,%d,%d.aface%d,%d,%dalreadyexists. n n", v1,v2,v3,v2,v3,t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v3]; exit0; g ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v3][v1]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f printf"add face:can'taddface%d,%d,%d.aface%d,%d,%dalreadyexists. n n", v1,v2,v3,v3,v1,t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v3][v1]; exit0; g #endif t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v2]=v3; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v2][v3]=v1; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v3][v1]=v2; g else f #ifDEBUG ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]!= )]TJ/F17 5.9776 Tf 5.596 0 Td [(1&&t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v1]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f printf"add face:can'taddface%d,%d,%d.faces%d,%d,%dand%d,%d,%dalreadyexist. n n", v1,v2,v3,v1,v2,t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2],v2,v1,t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v2][v1]; exit0; g ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v3]!= )]TJ/F17 5.9776 Tf 5.596 0 Td [(1&&t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v3][v2]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f printf"add face:can'taddface%d,%d,%d.faces%d,%d,%dand%d,%d,%dalreadyexist. n n", v1,v2,v3,v2,v3,t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v3],v3,v2,t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v3][v2]; exit0; g ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v3][v1]!= )]TJ/F17 5.9776 Tf 5.596 0 Td [(1&&t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v3]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f printf"add face:can'taddface%d,%d,%d.faces%d,%d,%dand%d,%d,%dalreadyexist. n n", v1,v2,v3,v3,v1,t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v3][v1],v1,v3,t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v3]; exit0; g #endif ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]== )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v2]=v3; else t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v2][v1]=v3; ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v3]== )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v2][v3]=v1; else t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v3][v2]=v1; ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v3][v1]== )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v3][v1]=v2; else t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v3]=v2; g 49

PAGE 60

t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nf++; g / removealledgesfromatriangulation / #include < triang.h > voidclear triangstructtriang t,intnv f intv1,v2; ifnv < 0 jj nv > MAX V f printf"clear triang:nv%doutofrange.mustbebetween0and%d. n n", nv,MAX V; exit0; g t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv=0; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ne=0; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nf=0; forv1=0;v1 < nv;v1++ forv2=0;v2 < nv;v2++ t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]= )]TJ/F17 5.9776 Tf 6.084 0 Td [(1; g / createatriangulationofaspherewithhandlesand/orcrosscapswithnv vertices / #include < triang.h > voidcreate triangstructtriang t,intnv,intgenus,intorient f intv1,v2,v3,v4,v5,v6,v7; intih; inthandles,crosscaps,ec; intne; ifgenus < 0 f printf"create triang:Thegenus%dmustbenon )]TJ/F17 5.9776 Tf 5.999 0 Td [(negative. n n", genus; exit0; g iforient f orient=1; handles=genus; crosscaps=0; ec=2 )]TJ/F17 5.9776 Tf 5.865 0 Td [(2 genus; g else f orient=0; handles=genus )]TJ/F17 5.9776 Tf 6.414 0 Td [(1/2; crosscaps=genus )]TJ/F17 5.9776 Tf 5.972 0 Td [(1%2+1; ec=2 )]TJ/F17 5.9776 Tf 6.263 0 Td [(genus; g 50

PAGE 61

/ testthatinputisinrange / ne=3 nv )]TJ/F17 5.9776 Tf 5.816 0 Td [(ec; ifne > MAX E f printf"create triang:numberofedgestoolarge%d.increaseMAX E. n n", ne; exit0; g ifnv nv )]TJ/F17 5.9776 Tf 6.304 0 Td [(1/2 < ne f printf"create triang:Thenumberofvertices%distoosmalltocreateatriangulation n n n onasurfacewithEulercharacteristic%d. n n n ThenumberofedgesinK%dis%dbutthenumberofedgesinatriangulationsis%d. n n", nv,ec,nv,nv nv )]TJ/F17 5.9776 Tf 6.435 0 Td [(1/2,ne; exit0; g / ifnv < 4+3 handles+2 crosscaps f printf"create triang:Thenumberofvertices%distoosmallcreateatriangulation n n n onasurfacewith%dhandlesand%dcrosscaps. n n n Ionlyknowhowtomaketriangulationswith%d4+3 h+2 cvertices. n n", nv,handles,crosscaps,4+3 handles+2 crosscaps; exit0; g / ifnv+3 > MAX V f printf"create triang:numberofverticestoolarge%d.increaseMAX V. n n", nv; exit0; g clear triangt,nv+3; / createtetrahedron / t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> orient=1; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> genus=0; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv=4; add facet,0,1,2; add facet,0,2,3; add facet,0,3,1; add facet,1,3,2; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ne=6; / addhandles / forih=0;ih < handles;ih++ f / pickarandomedge.addhandletoconnecttheadjacentfaces / / 51

PAGE 62

sewthisontothis 7.../.././....7 . n j / j / j . nj / j / j .1///. ./ jn j / j . ./ jnj / j . nj / .//4/.1 . jjn j //: n . jjnj /./: n .//6. n /: n / . jj / jn )]TJ/F17 5.9776 Tf 5.596 0 Td [(4:3 )]TJ/F17 5.9776 Tf -129.055 -11.576 Td [(. njj / j ./ n :/ n .3///. n :/ ./ jn j / j . n :/ . jnj / j /2 ./2//./ jn . j / jn j /. . j / jnj /. .//5/ ./ j / jn j ./ j / jnj 7.............7 / t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> genus+=1; v1=0; v2=0; whilev3=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v1]== )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f v1=rand%t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv; v2=rand%t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv; g v4=t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v2]; v5=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv++; v6=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv++; v7=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv++; remove facet,v1,v2,v4; remove facet,v2,v1,v3; add facet,v1,v7,v2; add facet,v1,v2,v5; add facet,v1,v5,v4; add facet,v4,v5,v7; add facet,v4,v7,v6; add facet,v1,v6,v7; add facet,v1,v3,v6; add facet,v2,v4,v6; add facet,v2,v6,v5; add facet,v3,v5,v6; add facet,v3,v7,v5; add facet,v2,v7,v3; 52

PAGE 63

t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ne+=15; reduce triangt,nv; g / addcrosscaps / if!orient f t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> orient=0; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> genus=2 t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> genus; g forih=0;ih < crosscaps;ih++ f / pickarandomedge. addcrosscapinwholeleftbyremovingadjacentfaces / / sewthisontothis 6 )188()189()188()188()189()188()189()188()]TJ/F17 5.9776 Tf 42.237 0 Td [(1 )188()189()188()188()189()188()189()188()]TJ/F17 5.9776 Tf 42.237 0 Td [(5 nj / jn / n / j 1 jn / n / j /: n jn / n / j /: n jn / n / jn /: n / j 34 j)]TJ/F17 5.9776 Tf 21.752 0 Td [(4:3 )]TJ -146.772 -11.576 Td [(j / n / nj / n :/ n j / n / njn :/ j / n / njn :/ j / n / nj 2 5 )188()189()188()188()189()188()189()188()]TJ/F17 5.9776 Tf 42.237 0 Td [(2 )188()189()188()188()189()188()189()188()]TJ/F17 5.9776 Tf 42.237 0 Td [(6/ jn nj / nj / nj / nj / nj / nj / nj / nj / nj / 1 / t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> genus++; v1=0; v2=0; whilev3=t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v2][v1]== )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f v1=rand%t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv; v2=rand%t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv; g v4=t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v2]; v5=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv++; v6=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv++; remove facet,v1,v2,v4; 53

PAGE 64

remove facet,v2,v1,v3; add facet,v1,v3,v6; add facet,v1,v5,v4; add facet,v3,v5,v6; add facet,v4,v5,v6; add facet,v2,v5,v3; add facet,v2,v4,v6; add facet,v1,v5,v2; add facet,v1,v2,v6; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ne+=9; reduce triangt,nv; g / addadditionalvertex,n,byplacingitinsiderandomface / whilet )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv < nv f v1=rand%t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv; v2=rand%t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv; ifv3=t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v2]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f v4=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv++; remove facet,v1,v2,v3; add facet,v1,v2,v4; add facet,v1,v4,v3; add facet,v2,v3,v4; t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ne+=3; g g g / findtheotherdiagonalofthequadralateralcreatedwhenthe edgeisremoved / #include < triang.h > intfind flipstructtriang t,intv1,intv2,int o1,int o2 f / findtheothertwocorners / #ifDEBUG ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]== )]TJ/F17 5.9776 Tf 5.596 0 Td [(1 jj t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v2][v1]== )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f printf"find flip:corruptedfacesatedge%d,%d n n",v1,v2; exit0; g #endif o1=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]; o2=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v1]; / checkforthepossibilitythattheothertwocornersalready formanedge / ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[ o1][ o2]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 return0; 54

PAGE 65

return1; g / interchangeanedgefortheotherdiagonalofthequadralateralcreated whentheedgeisremoved / #include < triang.h > voidflip edgestructtriang t,intv1,intv2,into1,into2 f / removetheoldfaces / remove facet,v1,v2,o1; remove facet,v2,v1,o2; / replacethemwithnewones / add facet,o1,o2,v2; add facet,o2,o1,v1; g / randomlyflipedgesofatriangulationwithoutincreasingthedegreeofthelastvertex / #include < triang.h > voidran flip triang excludestructtriang t,intntimes f intv1,v2,v3,v4;/ vertexnumbers / intnflips;/ numberofsuccessfulflips / intnran;/ numberofrandompairsgenerated / / pickarandomedge / nflips=0; nran=0; whilenflips < ntimes&&nran < ntimes jj nflips > 0 f v1=rand%t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv; v2=rand%t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv; nran++; / ifitisreallyanedge,canbeflipped,and doesnotincreasethedegreeofthelastvertexthenflipit. / / ifitisreallyanedge,... / ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f / ...canbeflipped,... / iffind flipt,v1,v2,&v3,&v4 / ...anddoesnotincreasethedegreeofthelastvertex... / 55

PAGE 66

ifv3!=t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv )]TJ/F17 5.9776 Tf 10.048 0 Td [(1&&v4!=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv )]TJ/F17 5.9776 Tf 10.427 0 Td [(1 f nflips++; flip edget,v1,v2,v3,v4; ifv1==t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv )]TJ/F17 5.9776 Tf 10.048 0 Td [(1 jj v2==t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv )]TJ/F17 5.9776 Tf 10.427 0 Td [(1 nflips=0; g g g g / reducethenumberofverticesinatriangulationtonv / / flipedgesuntilvertexhasdegree3thenremoveit,repeat / / return1ifsuccessful,return0ifcan'treducetonv / #include < triang.h > intreduce triangstructtriang t,intnv f intv1,v2,v3,v4;/ vertexnumbers / intdegree,prev degree;/ degreeofvertextoberemoved / inttrys;/ numberoftryssofar / intnei[MAX V];/ neighborsofv1 / intinei;/ neighborindex / intX;/ Eulercharacteristic / intvmin;/ theminimumnsuchthatthereexista triangulationonthesurfacewithnvertices / / testiftheoreticallypossible / ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> orient==1 X=2 )]TJ/F17 5.9776 Tf 10.382 0 Td [(2 t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> genus; else X=2 )]TJ/F17 5.9776 Tf 10.184 0 Td [(t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> genus; / vmin=ceil7+sqrt49 )]TJ/F17 5.9776 Tf 6.158 0 Td [(24 X/2; / vmin=4; whilevmin )]TJ/F17 5.9776 Tf 6.245 0 Td [(3 vmin )]TJ/F17 5.9776 Tf 5.972 0 Td [(4 < 6 2 )]TJ/F17 5.9776 Tf 5.578 0 Td [(X vmin++; ift )]TJ/F20 5.9776 Tf 4.384 0 Td [(> orient==1&&t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> genus==2 jj t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> orient==0&&t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> genus==3 jj t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> orient==0&&t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> genus==2 vmin++; ifnv < vmin f printf"reduce triang:can'treduceatriangulationonasurfacewithgenus%dandorientation%dto%dvertices. n n",t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> genus,t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> orient,nv; exit0; g / removeextraverticesifpossible / whilet )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv > nv f v1=t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv )]TJ/F17 5.9776 Tf 10.686 0 Td [(1; degree=0; 56

PAGE 67

forv2=0;v2 < v1;v2++ ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]!= )]TJ/F17 5.9776 Tf 5.928 0 Td [(1 nei[degree++]=v2; trys=0; whiledegree > 3 f iftrys++ > 100 t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nereturn0; inei=rand%degree; v2=nei[inei]; iffind flipt,v1,v2,&v3,&v4 flip edget,v1,v2,v3,v4; else ran flip triang excludet,t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ne; prev degree=degree; degree=0; forv2=0;v2 < v1;v2++ ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]!= )]TJ/F17 5.9776 Tf 5.928 0 Td [(1 nei[degree++]=v2; ifdegree < prev degreetrys=0; g v2=nei[0]; v3=t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v2]; v4=t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v2][v1]; remove facet,v1,v2,v3; remove facet,v1,v3,v4; remove facet,v1,v4,v2; add facet,v2,v3,v4; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv )-50()]TJ/F17 5.9776 Tf 11.958 0 Td [(; t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ne=t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ne )]TJ/F17 5.9776 Tf 10.686 0 Td [(3; g return1; g / removeonefacetoatriangulation / #include < triang.h > voidremove facestructtriang t,intv1,intv2,intv3 f ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> orient==1 f #ifDEBUG ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]!=v3 jj t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v3]!=v1 jj t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v3][v1]!=v2 f printf"remove face:orientableface%d,%d,%ddoesnotexistoriscorrupted. n n", v1,v2,v3; exit0; g #endif 57

PAGE 68

t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v2]= )]TJ/F17 5.9776 Tf 6.083 0 Td [(1; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v2][v3]= )]TJ/F17 5.9776 Tf 6.083 0 Td [(1; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v3][v1]= )]TJ/F17 5.9776 Tf 6.083 0 Td [(1; g else f #ifDEBUG ift )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v2]!=v3&&t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v2][v1]!=v3 jj t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v2][v3]!=v1&&t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v3][v2]!=v1 jj t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v3][v1]!=v2&&t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v3]!=v2 f printf"remove face:nonorientableface%d,%d,%ddoesnotexistoriscorrupted. n n", v1,v2,v3; exit0; g #endif ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]==v3 t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]= )]TJ/F17 5.9776 Tf 6.083 0 Td [(1; else t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v1]= )]TJ/F17 5.9776 Tf 6.083 0 Td [(1; ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v3]==v1 t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v2][v3]= )]TJ/F17 5.9776 Tf 6.083 0 Td [(1; else t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v3][v2]= )]TJ/F17 5.9776 Tf 6.083 0 Td [(1; ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v3][v1]==v2 t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v3][v1]= )]TJ/F17 5.9776 Tf 6.083 0 Td [(1; else t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v3]= )]TJ/F17 5.9776 Tf 6.083 0 Td [(1; g t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nf )-50()]TJ/F17 5.9776 Tf 11.959 0 Td [(; g / outputatriangulationinlexformatnotnecessarilyminimumcanonical / #include < stdio.h > #include < triang.h > #defineLINELEN2000 intwrite triang lexstructtriang t,FILE outfile f chartext[LINELEN]; intichar; intv0,v1; forv0=0;v0 < t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv )]TJ/F17 5.9776 Tf 6.166 0 Td [(2;v0++ forv1=v0+1;v1 < t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv )]TJ/F17 5.9776 Tf 6.166 0 Td [(1;v1++ ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v0][v1]!= )]TJ/F17 5.9776 Tf 5.928 0 Td [(1 ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v0][v1] < t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v0] f ift )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v0][v1] > v1 fprintfoutfile,"%c%c%c",i2a[v0],i2a[v1],i2a[t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v0][v1]]; ift )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v0] > v1 fprintfoutfile,"%c%c%c",i2a[v0],i2a[v1],i2a[t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v0]]; g else f 58

PAGE 69

ift )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v0] > v1 fprintfoutfile,"%c%c%c",i2a[v0],i2a[v1],i2a[t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v0]]; ift )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v0][v1] > v1 fprintfoutfile,"%c%c%c",i2a[v0],i2a[v1],i2a[t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v0][v1]]; g g 59

PAGE 70

APPENDIXBAntColony / main.c Thisisjustatestfileforverifyingantcolonycodeisworking / #include < triang.h > #include < triang utils.h > #include < ant colony.h > #include < constants.h > #include < stdio.h > #include < stdlib.h > #include < unistd.h > #include < signal.h > voidsigint handlerint; voidmainintargc,char argv[] f intv,v1,v2,v3,v4,count,temp,temp2; inti,j;//loopcontrols charline[LINE SIZE];//holdlineofinput intnumber of groups;//numberoftriangulationgroupsinfile,therewillbethickness number of groupslinesoflexstrings FILE infile; FILE outfile; signalSIGINT,sigint handler; //usercanpassininputfile/outputfile,num vertices in cliques,orallarguments ifargc==COMMAND LINE MIN COUNT jj argc==COMMAND LINE MAX COUNT+1 f initialize log function; initialize command line parametersargc,argv; //initfilestreams infile=fopenargv[INPUT FILE POS],"r"; outfile=fopenargv[OUTPUT FILE POS],"a"; //checkforerrorsopeningfiles ifinfile==NULL f printf"Errorreadinginputfile n n"; return; g ifoutfile==NULL f printf"Erroropeningoutputfile n n"; return; g //readline,initthickness,numberofverticesandgenus fgetsline,LINE SIZE,infile; sscanfline,"%d,%d,%d,%d",&thickness,&vertex count,&genus,&number of groups; //inittau,globalvariableintriang.h 60

PAGE 71

//ant colony/initialize arraysresetstauduringeveryloopofacs //allocatefirstleveloftau tau=longdouble mallocvertex count sizeoflongdouble ; //allocatesecondleveloftau fori=0;i < vertex count;i++ tau[i]=longdouble mallocvertex count sizeoflongdouble; //initorient,shouldalwaysbe1 orient=1; //printfirstlineofoutputfile fprintfoutfile,"%d,%d,%d,%d,alpha:%f,beta:%f,numberofants:%d n n",vertex count,num of vertices in cliques,thickness,genus,alpha,beta,nAnt; //loopthroughtriangulationinput fori=0;i < number of groups;i++ f structtriangt,t1,t2; //buffersfortrianginputholdtrianginputline chartriang1[LINE SIZE]; chartriang2[LINE SIZE]; //readtriangs fgetstriang1,LINE SIZE,infile; fgetstriang2,LINE SIZE,infile; //converttotriangstructs decode triang lextriang1,&t1; decode triang lextriang2,&t2; //mergetriangs merge 2 triang&t,&t1,&t2; //runACS ant colony system&t,&t1,&t2,outfile; g //closefiles fcloseinfile; fcloseoutfile; fcloselog file; //freepheromonearray fori=0;i < vertex count;i++ f freetau[i]; g freetau; return; g else f //exit,needmorearguments 61

PAGE 72

printf"%iargumentsentered,but%ior%iargumentsrequired.Pleasetryagain. n n",argc )]TJ/F17 5.9776 Tf 10.435 0 Td [(1,COMMAND LINE MIN COUNT,COMMAND LINE MAX COUNT; return; g g voidsigint handlerintsig f / dosomething / / printf"Killingprocess%d n n",getpid; printf"Cleaning... n n"; / fcloselog file; exit0; g / ant colony.h antcolonysystemfunctionsignature thisfileonlycontainsonefunctionwhosepurposeistorunantcolonysystemalgorithm / #ifndefANT COLONY H #defineANT COLONY H #include < stdio.h > #include < stdlib.h > #include < string.h > #include < triang.h > #include < triang utils.h > #include < ant structs.h > voidant colony systemstructtriang t,structtriang t1,structtriang t2,FILE successfile; //selectanedgeusingantcolonysystemformulas intant colony system selectionAnt MyAnt; voidant colony system save selectionAnt MyAnt,intidx to save; //determinetheheuristiccostofeverypossibleedgeflipavailabletoanant voidant colony system tour constructionAnt MyAnt,structtriang t,structtriang t1,structtriang t2; intare triang equalstructtriangtriang1,structtriangtriang2; doublecalculate initial pheromoneAntMyAnt; //checkifasolutionwith0complementsexist voidcheck for solution; //Displaytheparametersusedintheanycolonysystemalgorithm voiddisplay parameters; //findthebesttouramongagroupoftours voidfind best tourAntMyAnt,Solution BestSol; //cleanuppointers 62

PAGE 73

voidfree arraysAnt MyAnt,Solution sol,intnum vertices; //updatethepheromonematrixsharedamongallants voidglobal pheromone updateSolutionBestSol; voidinitialize ant parametersstructtriang t,structtriang t1,structtriang t2,intnum vertices,intargc,char argv[]; //Initializedynamicarrays voidinitialize arraysAnt MyAnt,structtriangt,structtriangt1,structtriangt2; //Beforebeginning,determinewhatabaselinebestsolutionisforcomparison //edge limit:max#ofedgesinflippableedgelist voidinitialize best solutionSolution Sol,structtriangt1,structtriangt2; voidlocal pheromone updateintv1,intv2; voidlog ant endFILE f,Solution s,intiterations; voidlog ant startFILE f,structtriang t1,structtriang t2; voidprint ant parametersFILE f; voidprint taulongdouble tau,intlength; //Printthetourcost voidprint the tour costAntMyAnt,intidx; //findthebestsubsetofanant'stour voidprune tourAnt MyAnt; //resetantvalues voidreset antAnt MyAnt,structtriangt,structtriangt1,structtriangt2; voidreset tauintnum vertices; intRouletteWheelSelectionAntMyAnt,intdupTimes; #endif / ant structs.h structdefinitionsforantalgorithms / #ifndefANT STRUCTS H #defineANT STRUCTS H #defineARRAY SIZE100 #include < triang.h > typedefstructAnt f structtriangt,t1,t2; //int Tour; intTourCnt;//!!!giveslengthoftouroninitialtourconstruction,afterprune toursListFE[0]tolistFE[TourCnt )]TJ/F17 5.9776 Tf 10.686 0 Td [(1]isthesubtourofoptimalcost int Cost;//CostofeachedgeinListFE,afterprune tours,Cost[TourCnt )]TJ/F17 5.9776 Tf 10.686 0 Td [(1]containsbestcostofthetour 63

PAGE 74

int ListFE;//edgeflippedateachstep,anarrayof2intsrepresentingtheedgeendpoints int FE Layer;//layeranedgeinListFEbelongsto //TempValuesusedforbuildinganttour int ListFE TMP;//alistofflippableedgesforthecurrentiteration,eachmemberisanarrayoftwoints,representingtheendpointsoftheedge int FECost;//costofeachflippableedgeinListFE TMP int ListFE Layer;//layeranedgeinListFE TMPbelongsto intListFECnt;//numberofedgesinListFE TMP intListFEMax;//TODO:don'tbelievethisvariableeverused,oktodelete? longdouble P;//arrayofprobabilitiesforroulettewheelselection g Ant; typedefstructSolution f structtriangt1,t2; int ListFE;//edgeflippedateachstep,eachedgerepresentedasarrayof2intsrepresentingedgeendpoints int FE Layer;//layeranedgeinListFEbelongsto intTourCnt;//lengthoftour intidx;//TODO:don'tbelievethisvariableeverused,oktodelete? intCost;//#oftrianglesincomplementoft1Ut2 intListFEMax;//TODO:don'tbelieveeverused,oktodelete? g Solution; //uselistofedgeflipstogeneratetriangulations voidbuild solution layersSolution s; //cleanuppointerinAnt voidfree antAnt ant; //cleanuppointersinSolution voidfree solutionSolution sol; //edge limit:maximumnumberofedgesinflippableedgelist Antinit ant; #endif / constants.h storeconstantvaluesusedthroughouttheprogram / #ifndefCONSTANTS H #defineCONSTANTS H //numberofcommandlinearguments staticconstintCOMMAND LINE MIN COUNT=4; staticconstintCOMMAND LINE MAX COUNT=11; //CommandLinePositions staticconstintINPUT FILE POS=1; staticconstintOUTPUT FILE POS=2; staticconstintVERTICES IN CLIQUES POS=3; staticconstintALPHA POS=4; 64

PAGE 75

staticconstintBETA POS=5; staticconstintRHO POS=6; staticconstintQ0 POS=7; staticconstintXI POS=8; staticconstintEDGE LIMIT POS=9; staticconstintNUM ANTS POS=10; staticconstintMAX ITERATIONS POS=11; //InputFilePositions staticconstintTHICKNESS POS=0; staticconstintNUM VERTICES POS=1; staticconstintGENUS POS=2; //maximumcharstoreadfromonelineoffile staticconstintLINE SIZE=1000; #endif / triang.h Apaireddownversionofthesulankecode Includeonlythefunctionsthatweneed / #ifndefTRIANG H #defineTRIANG H #include < stdio.h > #include < stdlib.h > #include < string.h > #defineMAX V128 #defineMAX EMAX V MAX V )]TJ/F17 5.9776 Tf 6.304 0 Td [(1/2 #defineMAX FMAX E/3 2 #defineMAX CODEMAX E+MAX E+MAX V+4 / VARIABLEDEFINITIONS / FILE log file; intnAnt,vertex count,EDGE LIMIT,num of vertices in cliques,NNSolution; intgenus,orient,thickness; floatQ0,alpha,beta,rho,Xi; intMAX ITER; longdouble tau; doubletau0; structtriang f / triangulation / intnv; intne; intnf; intorient;/ oriented?notsameasorientable, )]TJ/F17 5.9776 Tf 5.596 0 Td [(1notyetdetermined / intgenus;/ genusofsurface =numberofhandlesor=numberofcrosscaps )]TJ/F17 5.9776 Tf 5.596 0 Td [(1notyetdetermined / intedge[MAX V][MAX V]; intnfe;//numberofflippableedges 65

PAGE 76

g ; staticinta2i[128]= f )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.081 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.081 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.081 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.081 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.081 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.082 0 Td [(1, )]TJ/F17 5.9776 Tf 6.55 0 Td [(1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51, )]TJ/F17 5.9776 Tf 6.55 0 Td [(1, )]TJ/F17 5.9776 Tf 6.549 0 Td [(1, )]TJ/F17 5.9776 Tf 6.549 0 Td [(1, )]TJ/F17 5.9776 Tf 6.55 0 Td [(1, )]TJ/F17 5.9776 Tf 6.549 0 Td [(1, )]TJ/F17 5.9776 Tf 6.03 0 Td [(1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25, )]TJ/F17 5.9776 Tf 6.526 0 Td [(1, )]TJ/F17 5.9776 Tf 6.527 0 Td [(1, )]TJ/F17 5.9776 Tf 6.526 0 Td [(1, )]TJ/F17 5.9776 Tf 6.527 0 Td [(1, )]TJ/F17 5.9776 Tf 6.526 0 Td [(1 g ; staticchari2a[52]= f 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' g ; / FUNCTIONSIGNATURES / voidadd edgestructtriang t,intv1,intv2; //addonefacetoatriangulation voidadd facestructtriang t,intv1,intv2,intv3; intcheck triangstructtriang t,char caller; //removealledgesfromatriangulation voidclear triangstructtriang t,intv; //Generateatriangulation voidcreate triangstructtriang t,intnv,intgenus,intorient; / createatriangulationusinglexformatinput / intdecode triang lexchar text,structtriang t; voidget intcharprompt[],int integer; / findtheotherdiagonalofthequadralateralcreatedwhenthe edgeisremoved / intfind flipstructtriang t,intv1,intv2,int o1,int o2; / interchangeanedgefortheotherdiagonalofthequadralateralcreated whentheedgeisremoved / voidflip edgestructtriang t,intv1,intv2,into1,into2; / randomlyflipedgesofatriangulationwithoutincreasingthedegreeofthelastvertex / voidran flip triang excludestructtriang t,intntimes; / reducethenumberofverticesinatriangulationtonv / / flipedgesuntilvertexhasdegree3thenremoveit,repeat / / return1ifsuccessful,return0ifcan'treducetonv / intreduce triangstructtriang t,intnv; //Removeanedge voidremove edgestructtriang t,intv1,intv2; //Removeaface voidremove facestructtriang t,intv1,intv2,intv3; intdsatur coloringintedge[128][128],intnv,intDEBUG; 66

PAGE 77

voidget critical graphstructtriang t,structtriang t1,structtriang t2,intPRINT OUT; voidinitialize log function; voidinitialize command line parametersintargc,char argv[]; voidprint triangstructtriang t; intdharwadker coloringstructtriangt,intMODE TEST; //referencec++function //functionsignaturemustmatch intvertex coloringintN,intedge[MAX V][MAX V],intC,intPRINTOUT; #endif / triang utils.h miscellaneousutilityfunctionsforworkingwithgraphs / #ifndefTRIANG UTILS H #defineTRIANG UTILS H #include < triang.h > #include < ant structs.h > intcount cliquesstructtriangt,intnum of vertices in cliques,intPRINT OUT; intcount triang2structtriang t,intPRINT TRIANGLES; voiddisplay triang lexstructtriang t; //Flipanedgebasedonthegiventriangtand2endpointsv1,v2 structtriangFlipEdgestructtriangt,intv1,intv2; voidgenerate random triangstructtriang t,structtriang t1,structtriang t2,intnv,intgenus,intorient; structtriangget complement graphstructtriang t; //GettheflippableedgeslistforanAnt voidget flippable edgesAnt MyAnt; //Getthe"NearestNeighbor"Solution //Thatistokeeppickingtheflippableedgesthatyieldthesmallestnumberoftrianglesinthecomplement intgetNNSolutionAnt MyAnt,intEDGE LIMIT,intnum of vertices in cliques; intload default triangleschartext file[],structtriang t,structtriang t1,structtriang t2; voidmerge 2 triangstructtriang t,structtriang t1,structtriang t2; voidprint neighbors2structtriang t; //writetriantinlexformattouserspecifiedfile voidprint triang lexFILE filename,structtriang t; 67

PAGE 78

voidremove edgestructtriang t,intv1,intv2; #endif / ant colony.c mainfileforrunningantcolonyprogram morecommentstocome / #include < ant colony.h > //Accepts:structtriang t,structtriang t1,structtriang t2,intargc,char argv[] //Returnsnothing,bestsolutionshouldbeloggedorwrittentoconsole voidant colony systemstructtriang t,structtriang t1,structtriang t2,FILE successfile f //ant colonyparameters //TODO:needcommentsforwhateachvariableis inta,b,i,k,idx,it=0; intnum vertices=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv; Ant MyAnt;//arrayofants SolutionBestSol;//globallybesttourfoundamongalliterations / Initialization / initialize arrays&MyAnt, t, t1, t2; initialize best solution&BestSol, t1, t2; / WriteStartingValuesToConsole / //display parameters; printf"StartingCost:%d n n",count cliquesget complement grapht,num of vertices in cliques,0; printf"NearestNeighborSolution:%d n n",NNSolution; printf"tau0:%.5f n n",tau0; printf" n n"; / LogSolutionStart / log ant startlog file,t1,t2; / RunAntColonyProcess / forit=0;it < MAX ITER;it++ f //Writeiterationnumbertoconsoleevery5iterationssowecanseeprogress ifit%5==0 f printf"Iteration#:%d j BestCost:%d n n",it,BestSol.Cost; g //eachantbuildsatour fork=0;k < nAnt;k++ f //cleartheant'svaluesforthenewtour reset ant&MyAnt[k], t, t1, t2; //constructtheant'stour 68

PAGE 79

ant colony system tour construction&MyAnt[k],t,t1,t2; //storethebestsubsetoftheant'stour prune tour&MyAnt[k]; //comparetheant'stourtothebestsolutionandupdateifant'stourisbetter find best tourMyAnt[k],&BestSol; g //updatetheglobalpheromone global pheromone updateBestSol; / IfSolutionFound,StopLooking / ifBestSol.Cost==0 f break; g g / EndofProgram,LogandFreeMemory / //generatesolutiontriangulationsfromlistofedgeflips build solution layers&BestSol; / DebuggingOnly,CheckthatSolutionCostis0 / merge 2 triangt,&BestSol.t1,&BestSol.t2; intc=count cliquesget complement grapht,num of vertices in cliques,0; printf"SolutionFound: n nBestSolCost:%d j DebugSolutionCost:%d n nIterations:%d n n",BestSol.Cost,c,it; printf" n n"; / EndofDebugging / //writeresultstolog log ant endlog file,&BestSol,it+1; //ifsolutioncostis0,writeedgelisttosuccessfile ifc==0 f //trackwhenthefirstcommaiswrittensowedon'thavetrailingcommasattheendofline intfirst comma=1;//1=true //printfirsttriangulation fora=0;a < vertex count;a++ f forb=a+1;b < vertex count;b++ f //valueof )]TJ/F17 5.9776 Tf 5.596 0 Td [(1meansnoedge ifBestSol.t1.edge[a][b]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f if!first comma f fprintfsuccessfile,",%d,%d",a+1,b+1; g else f fprintfsuccessfile,"%d,%d",a+1,b+1; first comma=0; g g g g //resetfirstcomma,printnewline first comma=1; 69

PAGE 80

fprintfsuccessfile," n n"; //printsecondtriangulation fora=0;a < vertex count;a++ f forb=a+1;b < vertex count;b++ f //valueof )]TJ/F17 5.9776 Tf 5.596 0 Td [(1meansnoedge ifBestSol.t2.edge[a][b]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f if!first comma f fprintfsuccessfile,",%d,%d",a+1,b+1; g else f fprintfsuccessfile,"%d,%d",a+1,b+1; first comma=0; g g g g fprintfsuccessfile," n n"; g //beaconsiderateprogrammer,freememory free arraysMyAnt,&BestSol,t1 )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv; g / ant colony system stages.c implementationoffunctionsdefinedinant colony.h / #include < ant colony.h > #include < math.h > #defineDEBUG0 voidreset antAnt MyAnt,structtriangt,structtriangt1,structtriangt2 f ifDEBUGprintf"Resetant n n"; MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> TourCnt=0; MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> t=t; MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> t1=t1; MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> t2=t2; g voidreset tauintnum vertices f inti,j; fori=0;i < num vertices )]TJ/F17 5.9776 Tf 10.685 0 Td [(1;i++ forj=i+1;j < num vertices;j++ tau[i][j]=tau0; fori=0;i < num vertices;i++ tau[i][i]=0; g voidinitialize best solutionSolution Sol,structtriangt1,structtriangt2 70

PAGE 81

f ifDEBUGprintf"initializebestsolution n n"; inti; Sol )]TJ/F20 5.9776 Tf 4.384 0 Td [(> t1=t1; Sol )]TJ/F20 5.9776 Tf 4.384 0 Td [(> t2=t2; Sol )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE=int mallocEDGE LIMIT sizeofint ; Sol )]TJ/F20 5.9776 Tf 4.384 0 Td [(> FE Layer=mallocEDGE LIMIT sizeofint; Sol )]TJ/F20 5.9776 Tf 4.384 0 Td [(> TourCnt=0; Sol )]TJ/F20 5.9776 Tf 4.384 0 Td [(> idx= )]TJ/F17 5.9776 Tf 6.083 0 Td [(1; Sol )]TJ/F20 5.9776 Tf 4.384 0 Td [(> Cost=NNSolution; //initsecondlevelofpointersinListFE fori=0;i < EDGE LIMIT;i++ Sol )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFE[i]=int malloc2 sizeofint; g voidant colony system save selectionAnt MyAnt,intidx to save f intj=idx to save; ifj!= )]TJ/F17 5.9776 Tf 6.033 0 Td [(1 f //Determinewhichtriangulationtheedgeflipbelongsto ifMyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE Layer[j]==1 f MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> t1=FlipEdgeMyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> t1,MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFE TMP[j][0],MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFE TMP[j][1]; g else f MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> t2=FlipEdgeMyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> t2,MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFE TMP[j][0],MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFE TMP[j][1]; g MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> Cost[MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> TourCnt]=MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> FECost[j]; MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> FE Layer[MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> TourCnt]=MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFE Layer[j]; //Addflippededge MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFE[MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> TourCnt][0]=MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE TMP[j][0]; MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFE[MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> TourCnt][1]=MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE TMP[j][1]; //Incrementtourcountlastoritwillmessuparrayindexingabove MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> TourCnt++; g g voidprint the tour costAntMyAnt,intidx f inti; printf"MyAnt[%d].Cost )]TJ/F17 5.9776 Tf 10.031 0 Td [(TourCnt%d:",idx,MyAnt.TourCnt; fori=0;i < MyAnt.TourCnt;i++ printf"%d",MyAnt.Cost[i]; printf" n n"; g 71

PAGE 82

voidprint taulongdouble tau,intlength f inti,j; fori=0;i < length )]TJ/F17 5.9776 Tf 6.165 0 Td [(1;i++ forj=i+1;j < length;j++ printf"tau[%d][%d]:%Lf n n",i,j,tau[i][j]; g / ant colony system stages.c implementationoffunctionsdefinedinant colony.h / #include < ant colony.h > #include < math.h > #defineDEBUG0 voidlocal pheromone updateintv1,intv2 f tau[v1][v2]=1 )]TJ/F17 5.9776 Tf 6.364 0 Td [(Xi tau[v1][v2]+Xi tau0; g voidglobal pheromone updateSolutionBestSol f inti; fori=0;i < BestSol.TourCnt;i++//GlobalPheromoneTrailUpdate tau[BestSol.ListFE[i][0]][BestSol.ListFE[i][1]]=1 )]TJ/F17 5.9776 Tf 10.327 0 Td [(rho tau[BestSol.ListFE[i][0]][BestSol.ListFE[i][1]]+longdoublerho/BestSol.Cost; g / ant colony system stages.c implementationoffunctionsdefinedinant colony.h / #include < ant colony.h > #include < math.h > #defineDEBUG0 intRouletteWheelSelectionAntMyAnt,intdupTimes f doubler=doublerand/doubleRAND MAX;//Fordifferentrange,followhttp://www.eternallyconfuzzled.com/arts/jsw art rand.aspx double C=mallocMyAnt.ListFECnt sizeofdouble; inti,j,flag; fori=0;i < MyAnt.ListFECnt;i++ f C[i]=0; forj=0;j < =i;j++ C[i]+=MyAnt.P[j];//AccumulatealltheP[j]fromtheindex0toindexi 72

PAGE 83

ifr < C[i] f flag=0; forj=0;j < MyAnt.TourCnt;j++ ifMyAnt.ListFE TMP[i][0]==MyAnt.ListFE[j][0]&&MyAnt.ListFE TMP[i][1]==MyAnt.ListFE[j][1] f flag++; ifflag > dupTimes break; g ifflag < =dupTimes returni; g g return )]TJ/F17 5.9776 Tf 6.084 0 Td [(1; g intare triang equalstructtriangtriang1,structtriangtriang2 f inti,j; fori=0;i < triang1.nv )]TJ/F17 5.9776 Tf 6.166 0 Td [(1;i++ forj=i+1;j < triang1.nv;j++ iftriang1.edge[i][j]!=triang2.edge[i][j] return0; return1; g structtriangtriang s1[1000]; structtriangtriang s2[1000]; inttriang cnt=0; voidant colony system tour constructionAnt MyAnt,structtriang t,structtriang t1,structtriang t2 f ifDEBUGprintf"calculateedgecosts n n"; //getflippableedgesfortheany //thecalculatecosts inti,l,idx; structtriangt temp,t1 temp,t2 temp; //calculateflippableedgelistEDGE LIMIT#oftimes //flippableedgelistisallpotentialflipsandtheircost forl=0;l < EDGE LIMIT;l++ f get flippable edgesMyAnt; //loopthrougheachflippableedgeandcomputecost fori=0;i < MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFECnt;i++ f //checkwhichlayertheedgeison ifMyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFE Layer[i]==1 f 73

PAGE 84

t1 temp=FlipEdgeMyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> t1,MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFE TMP[i][0],MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFE TMP[i][1]; t2 temp=MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> t2; g else f t1 temp=MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> t1; t2 temp=FlipEdgeMyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> t2,MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFE TMP[i][0],MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFE TMP[i][1]; g merge 2 triang&t temp,&t1 temp,&t2 temp; //savecostofcurrentflip MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> FECost[i]=count cliquesget complement graph&t temp,num of vertices in cliques,0; //ifthecurrentflipcostiszero,saveandexitimmediately ifMyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> FECost[i]==0 f //TODO:MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> t=t temp ant colony system save selectionMyAnt,i; return; g g //determineflippableedgewithACSprobablisticselectionprocedure //idxisindexofedgetoflipinFEList idx=ant colony system selectionMyAnt; //updateantbyflippingselectededge ant colony system save selectionMyAnt,idx; //ACSlocalpheromoneupdateprocedure ifidx!= )]TJ/F17 5.9776 Tf 6.033 0 Td [(1 local pheromone updateMyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFE TMP[idx][0],MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFE TMP[idx][1]; g MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> t=t temp; g //ACSprobabilisticselectionprocedure intant colony system selectionAnt MyAnt f ifDEBUGprintf"antcolonysystemselection n n"; inti,j=0,argmax idx; doublesum; doubletemp,argmax; temp=longdoublerand/longdoubleRAND MAX;//Generatearandomnumberbetween0 < temp < 1 //iftemp < =Q0:Calculatetheargmaxanddotheedgeselection //else:calculatetheprobabilitiesanddotheedgeselection iftemp < =Q0 f argmax=0; fori=0;i < MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFECnt;i++ 74

PAGE 85

f //Choosethemaximumoftau i^beta temp=tau[MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE TMP[i][0]][MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE TMP[i][1]] powlongdouble1/MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> FECost[i],beta; ifargmax < temp f argmax=temp; argmax idx=i; g g j=argmax idx; g else f //sum=0; fori=0;i < MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFECnt;i++ f //CalculateP[i]=tau0^alpha cost^beta MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> P[i]=powlongdoubletau[MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE TMP[i][0]][MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE TMP[i][1]],alpha powlongdouble1/MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> FECost[i],beta; sum+=MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> P[i];//Accumulateforthesum g fori=0;i < MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFECnt;i++ MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> P[i]=MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> P[i]/sum;//DividetothesumtogetP[i]=tau0^alpha cost^beta/sum j=RouletteWheelSelection MyAnt,10;//Dotheroulettewheelselection.10meanstoallow10duplicatesinthetour g returnj; g voidprune tourAnt MyAnt f ifDEBUGprintf"prunetours n n"; inti,final idx=0; //Figureoutthebestpartofthetour fori=1;i < MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> TourCnt;i++ ifMyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> Cost[final idx] > MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> Cost[i] final idx=i; //Savethebestparttothecounterofthetour MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> TourCnt=final idx+1; g voidfind best tourAntMyAnt,Solution BestSol f ifDEBUGprintf"findbesttour n n"; 75

PAGE 86

inti; ifBestSol )]TJ/F20 5.9776 Tf 4.384 0 Td [(> Cost > MyAnt.Cost[MyAnt.TourCnt )]TJ/F17 5.9776 Tf 6.385 0 Td [(1] f BestSol )]TJ/F20 5.9776 Tf 4.384 0 Td [(> Cost=MyAnt.Cost[MyAnt.TourCnt )]TJ/F17 5.9776 Tf 6.54 0 Td [(1]; BestSol )]TJ/F20 5.9776 Tf 4.384 0 Td [(> TourCnt=MyAnt.TourCnt; fori=0;i < MyAnt.TourCnt;i++ f //updateflippableedgelist BestSol )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE[i][0]=MyAnt.ListFE[i][0]; BestSol )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE[i][1]=MyAnt.ListFE[i][1]; //updateflippableedgelayers BestSol )]TJ/F20 5.9776 Tf 4.384 0 Td [(> FE Layer[i]=MyAnt.FE Layer[i]; g g g / ant structs.c / #include < stdlib.h > #include < ant structs.h > #include < triang utils.h > #defineDEBUG0 voidbuild solution layersSolution s f inti; //updatetriangulationsbyflippingeachedgeinList FE fori=0;i < s )]TJ/F20 5.9776 Tf 4.383 0 Td [(> TourCnt;i++ f ifs )]TJ/F20 5.9776 Tf 4.384 0 Td [(> FE Layer[i]==1 f s )]TJ/F20 5.9776 Tf 4.383 0 Td [(> t1=FlipEdges )]TJ/F20 5.9776 Tf 4.384 0 Td [(> t1,s )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFE[i][0],s )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE[i][1]; g else f s )]TJ/F20 5.9776 Tf 4.383 0 Td [(> t2=FlipEdges )]TJ/F20 5.9776 Tf 4.384 0 Td [(> t2,s )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFE[i][0],s )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE[i][1]; g g g voidfree antAnt ant f inti; freeant )]TJ/F20 5.9776 Tf 4.384 0 Td [(> Cost; freeant )]TJ/F20 5.9776 Tf 4.384 0 Td [(> FE Layer; //ListFEandListFE TMParepointertopointerofsize=edgelimit //freeinnerpointers fori=0;i < EDGE LIMIT;i++ f freeant )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE[i]; 76

PAGE 87

freeant )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE TMP[i]; g //freepointertopointer freeant )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE; freeant )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE TMP; //freeListFE Layer freeant )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE Layer; //freeListFE TMP //freeFECost freeant )]TJ/F20 5.9776 Tf 4.384 0 Td [(> FECost; g voidfree solutionSolution sol f inti; freesol )]TJ/F20 5.9776 Tf 4.384 0 Td [(> FE Layer; //freeinnerpointers fori=0;i < EDGE LIMIT;i++ freesol )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE[i]; //freepointertopointers freesol )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE; g Antinit ant f inti; AntmyAnt; myAnt.TourCnt=0; myAnt.Cost=mallocEDGE LIMIT sizeofint; myAnt.ListFE=int mallocEDGE LIMIT sizeofint ; myAnt.FE Layer=mallocEDGE LIMIT sizeofint; myAnt.ListFE TMP=int mallocEDGE LIMIT sizeofint ; myAnt.FECost=mallocEDGE LIMIT sizeofint; myAnt.ListFE Layer=mallocEDGE LIMIT sizeofint; myAnt.P=mallocEDGE LIMIT sizeoflongdouble; fori=0;i < EDGE LIMIT;i++ f myAnt.ListFE[i]=int malloc2 sizeofint; myAnt.ListFE TMP[i]=int malloc2 sizeofint; g returnmyAnt; g #include < ant colony.h > #include < math.h > 77

PAGE 88

#defineDEBUG0 doublecalculate initial pheromoneAntMyAnt f //Getthetau0basedonthecostofthegivenNNSolution; inti,idx,l,min,temp; structtriangt temp,t1 temp,t2 temp; doubletau0; forl=0;l < EDGE LIMIT;l++ f min=10000;//Resetthevariablemin get flippable edges&MyAnt;//Getthelistofflippableedges fori=0;i < MyAnt.ListFECnt;i++ f ifMyAnt.ListFE Layer[i]==1//Followthelayertofliptheedge f t1 temp=FlipEdgeMyAnt.t1,MyAnt.ListFE TMP[i][0],MyAnt.ListFE TMP[i][1]; t2 temp=MyAnt.t2; g else f t1 temp=MyAnt.t1; t2 temp=FlipEdgeMyAnt.t2,MyAnt.ListFE TMP[i][0],MyAnt.ListFE TMP[i][1]; g //printf"[%d][%d][%d]",MyAnt.ListFE TMP[i][0],MyAnt.ListFE TMP[i][1],MyAnt.ListFE Layer[i]; //printf"Flip[%d][%d]atthelayer%d. n n",MyAnt.ListFE TMP[i][0],MyAnt.ListFE TMP[i][1],MyAnt.ListFE Layer[i]; //get int"Next?:",&temp; merge 2 triang&t temp,&t1 temp,&t2 temp; MyAnt.FECost[i]=count cliquesget complement graph&t temp,num of vertices in cliques,0; ifmin > MyAnt.FECost[i] f min=MyAnt.FECost[i]; idx=i; g g //get int" n nNext?:",&temp; //Saveforthetour ant colony system save selection&MyAnt,idx; g //Getthebestpartofthetour idx=0; fori=0;i < MyAnt.TourCnt;i++ ifMyAnt.Cost[idx] > MyAnt.Cost[i]//Stillacceptvaluethatequalstomin idx=i; 78

PAGE 89

MyAnt.TourCnt=idx+1; //printf"NNSolution:%d n n",MyAnt.Cost[MyAnt.TourCnt )]TJ/F17 5.9776 Tf 6.66 0 Td [(1]; NNSolution=MyAnt.Cost[MyAnt.TourCnt )]TJ/F17 5.9776 Tf 6.54 0 Td [(1]; ifMyAnt.Cost[MyAnt.TourCnt )]TJ/F17 5.9776 Tf 6.166 0 Td [(1]!=0 return1/doubleMyAnt.TourCnt )]TJ/F17 5.9776 Tf 5.972 0 Td [(1 NNSolution; else return0; g #include < ant colony.h > #defineDEBUG0 voiddisplay parameters f printf" ACSStartingParameters n n"; printf"alpha:%.1f n nbeta:%.1f n nrho:%.4f n nClique:K%d n nnAnt:%d n nEDGE LIMIT:%d n nQ0:%.2f n nXi:%.2f n nMAX ITER:%d n n",alpha,beta,rho,num of vertices in cliques,nAnt,EDGE LIMIT,Q0,Xi,MAX ITER; g #include < ant colony.h > #include < math.h > #defineDEBUG0 voidfree arraysAnt MyAnt,Solution sol,intnum vertices f inti; //freeeachant fori=0;i < nAnt;i++ f free ant&MyAnt[i]; g freeMyAnt; free solutionsol; g #include < ant colony.h > #include < math.h > #defineDEBUG0 voidinitialize ant parametersstructtriang t,structtriang t1,structtriang t2,intnum vertices,intargc,char argv[] f //forloopvariabledeclaration inti,v,genus,orient; //allocatefirstleveloftau tau=longdouble mallocnum vertices sizeoflongdouble ; //allocatesecondleveloftau fori=0;i < num vertices;i++ tau[i]=longdouble mallocnum vertices sizeoflongdouble; //initializeparameterstodefaultvalues 79

PAGE 90

alpha=1.0;//PheromoneExponentialWeight beta=30.0;//HeuristicExponentialWeight num of vertices in cliques=3; rho=0.01;//EvaporationRate nAnt=1;//Numberofants Q0=0.1;//Q0inACSforTourConstruction Xi=0.1;//ParameterforLocalPheromoneUpdate EDGE LIMIT=num vertices num vertices )]TJ/F17 5.9776 Tf 10.428 0 Td [(1 10; MAX ITER=1000; //ifcommandlineargumentsprovided,usethoseinsteadofdefaults ifargc > 4 f fori=5;i < =argc;i++ f switchi f case5: alpha=atofargv[i )]TJ/F17 5.9776 Tf 6.661 0 Td [(1]; break; case6: beta=atofargv[i )]TJ/F17 5.9776 Tf 6.66 0 Td [(1]; break; case7: rho=atofargv[i )]TJ/F17 5.9776 Tf 6.66 0 Td [(1]; break; case8: num of vertices in cliques=intstrtolargv[i )]TJ/F17 5.9776 Tf 6.409 0 Td [(1],NULL,10; break; case9: nAnt=intstrtolargv[i )]TJ/F17 5.9776 Tf 6.41 0 Td [(1],NULL,10; break; case10: EDGE LIMIT=intstrtolargv[i )]TJ/F17 5.9776 Tf 6.409 0 Td [(1],NULL,10; break; case11: Q0=atofargv[i )]TJ/F17 5.9776 Tf 6.66 0 Td [(1]; break; case12: Xi=atofargv[i )]TJ/F17 5.9776 Tf 6.66 0 Td [(1]; break; case13: MAX ITER=intstrtolargv[i )]TJ/F17 5.9776 Tf 10.74 0 Td [(1],NULL,10; default: break; g g g g #include < ant colony.h > #include < math.h > #defineDEBUG0 voidinitialize arraysAnt MyAnt,structtriangt,structtriangt1,structtriangt2 80

PAGE 91

f inti,j;//loopcontrol intnum vertices=t1.nv; MyAnt=mallocnAnt sizeofAnt; fori=0;i < nAnt;i++ MyAnt[i]=init ant; reset ant& MyAnt[0],t,t1,t2; tau0=calculate initial pheromone MyAnt[0]; //initializetautotau0 reset taunum vertices; g / log ant end.c writeresultstologfile / #include < ant colony.h > #include < stdio.h > voidlog ant endFILE f,Solution s,intiterations f fprintff,"FINISH,"; fprintff,"%d",s )]TJ/F20 5.9776 Tf 4.383 0 Td [(> Cost; fprintff,","; fprintff,"%d,",iterations; print triang lexf,&s )]TJ/F20 5.9776 Tf 4.383 0 Td [(> t1; fprintff,","; print triang lexf,&s )]TJ/F20 5.9776 Tf 4.383 0 Td [(> t2; fprintff," n n"; g / log ant start.c Writeinformationaboutinitialantparameters Functionassumesafilestreamisalreadyopen Noneofthefunctionscalledinsidelog ant startaddanyextraformatting outsideofwhatisneededtoprintwhatthey'reresponsiblefor / #include < ant colony.h > #include < stdio.h > voidlog ant startFILE f,structtriang t1,structtriang t2 f fprintff,"START,"; print triang lexf,t1; fprintff,","; print triang lexf,t2; 81

PAGE 92

fprintff,","; print ant parametersf; fprintff," n n"; g / print ant parameters.c printantparameterstoauserspecifiedfile Userisresponsibleforaddingextraformattingsuchascommasbeforethe startoftheargumentsornewlinesafter. / #include < ant colony.h > #include < stdio.h > voidprint ant parametersFILE f f fprintff,"%.1f,%.1f,%.4f,%d,%d,%d,%.2f,%.2f",alpha,beta,rho,num of vertices in cliques,nAnt,EDGE LIMIT,Q0,Xi; g #include < triang.h > voidadd edgestructtriang t,intv1,intv2 f t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]=1; t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v1]=1; g / addonefacetoatriangulation / #include < triang.h > voidadd facestructtriang t,intv1,intv2,intv3 f #ifDEBUG ifv1==v2 jj v1==v3 jj v2==v3 f printf"add face:vertices%d,%dand%dmustbedistinct. n n", v1,v2,v3; exit0; g ifv1 < 0 jj v1 > =t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv jj v2 < 0 jj v2 > =t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv jj v3 < 0 jj v3 > =t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv f printf"add face:vertex%d,%dor%doutofrange.mustbebetween0and%d. n n", v1,v2,v3,t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv; exit0; g #endif ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> orient==1 f #ifDEBUG ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f printf"add face:can'taddface%d,%d,%d.aface%d,%d,%dalreadyexists. n n", v1,v2,v3,v1,v2,t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]; exit0; 82

PAGE 93

g ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v3]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f printf"add face:can'taddface%d,%d,%d.aface%d,%d,%dalreadyexists. n n", v1,v2,v3,v2,v3,t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v3]; exit0; g ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v3][v1]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f printf"add face:can'taddface%d,%d,%d.aface%d,%d,%dalreadyexists. n n", v1,v2,v3,v3,v1,t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v3][v1]; exit0; g #endif t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v2]=v3; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v2][v3]=v1; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v3][v1]=v2; g else f #ifDEBUG ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]!= )]TJ/F17 5.9776 Tf 5.596 0 Td [(1&&t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v1]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f printf"add face:can'taddface%d,%d,%d.faces%d,%d,%dand%d,%d,%dalreadyexist. n n", v1,v2,v3,v1,v2,t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2],v2,v1,t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v2][v1]; exit0; g ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v3]!= )]TJ/F17 5.9776 Tf 5.596 0 Td [(1&&t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v3][v2]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f printf"add face:can'taddface%d,%d,%d.faces%d,%d,%dand%d,%d,%dalreadyexist. n n", v1,v2,v3,v2,v3,t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v3],v3,v2,t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v3][v2]; exit0; g ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v3][v1]!= )]TJ/F17 5.9776 Tf 5.596 0 Td [(1&&t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v3]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f printf"add face:can'taddface%d,%d,%d.faces%d,%d,%dand%d,%d,%dalreadyexist. n n", v1,v2,v3,v3,v1,t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v3][v1],v1,v3,t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v3]; exit0; g #endif ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]== )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v2]=v3; else t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v2][v1]=v3; ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v3]== )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v2][v3]=v1; else t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v3][v2]=v1; ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v3][v1]== )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v3][v1]=v2; else t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v3]=v2; g t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nf++; g 83

PAGE 94

/ checktriangulation / / return0ifnoproblems,1otherwise / #include < triang.h > intcheck triangstructtriang t,char caller f intv1,v2,v3; intbad; intne; intfound[MAX V],search[MAX V],nsearch,nfound; bad=0; //checkthatnumberofverticesinbounds ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv < 4 jj t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv > MAX V f printf"%s:nv%doutofrange n n",caller,t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv; bad=1; returnbad; g / checkthatnoedgeisaloop / forv1=0;v1 < t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv;v1++ ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v1]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f printf"%s:loopedgeat%d n n",caller,v1; bad=1; g / checkthateachedgeisin0or2triangles / forv1=0;v1 < t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv;v1++ forv2=0;v2 < t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv;v2++ ifv1!=v2 ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]!= )]TJ/F17 5.9776 Tf 5.596 0 Td [(1&&t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v1]== )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f printf"%s:%d,%disonafacebut%d,%disnot n n", caller,v1,v2,v2,v1; bad=1; g / checkthatorientable / ne=0; forv1=0;v1 < t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv;v1++ forv2=0;v2 < t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv;v2++ ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f ne++; v3=t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v2]; ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v3]!=v1 ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> orient==1 f printf"%s:%d,%d,%disafacebut%d,%d,%disnot n n", caller,v1,v2,v3,v2,v3,v1; bad=1; g 84

PAGE 95

else f ift )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v3][v2]!=v1 f printf"%s:%d,%d,%disafacebut%d,%d,%disnot n n", caller,v1,v2,v3,v2,v3,v1; bad=1; g g g ne=ne/2; / checkthatconnected / forv1=0;v1 < t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv;v1++ found[v1]=0; found[0]=1; search[0]=0; nsearch=0; nfound=1; whilenfound < t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv&&nsearch < nfound f v1=search[nsearch++]; forv2=0;v2 < t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv;v2++ ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]!= )]TJ/F17 5.9776 Tf 5.596 0 Td [(1&&!found[v2] f found[v2]=1; search[nfound++]=v2; g g ifnfound!=t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv f printf"%s:notconnected n n",caller; bad=1; g / checkscalars / ifne!=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ne f printf"%s:calculatedne%dnotequaltostoredne%d n n", caller,ne,t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ne; bad=1; g ifne 2/3!=t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nf f printf"%s:calculatednf%dnotequaltostorednf%d n n", caller,ne 2/3,t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nf; bad=1; g ift )]TJ/F20 5.9776 Tf 4.384 0 Td [(> genus!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> orient==1&&2 )]TJ/F17 5.9776 Tf 6.151 0 Td [(t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv )]TJ/F17 5.9776 Tf 5.557 0 Td [(ne/3/2!=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> genus f printf"%s:calculatedgenus%dnotequaltostoredgenus%d n n", caller,2 )]TJ/F17 5.9776 Tf 6.42 0 Td [(t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv )]TJ/F17 5.9776 Tf 5.557 0 Td [(ne/3/2,t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> genus; bad=1; g ift )]TJ/F20 5.9776 Tf 4.384 0 Td [(> genus!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> orient==0&&2 )]TJ/F17 5.9776 Tf 6.151 0 Td [(t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv )]TJ/F17 5.9776 Tf 5.557 0 Td [(ne/3!=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> genus f printf"%s:calculatedgenus%dnotequaltostoredgenus%d n n", 85

PAGE 96

caller,2 )]TJ/F17 5.9776 Tf 6.42 0 Td [(t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv )]TJ/F17 5.9776 Tf 5.557 0 Td [(ne/3,t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> genus; bad=1; g returnbad; g / removealledgesfromatriangulation / #include < triang.h > voidclear triangstructtriang t,intnv f intv1,v2; ifnv < 0 jj nv > MAX V f printf"clear triang:nv%doutofrange.mustbebetween0and%d. n n", nv,MAX V; exit0; g t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv=0; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ne=0; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nf=0; forv1=0;v1 < nv;v1++ forv2=0;v2 < nv;v2++ t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]= )]TJ/F17 5.9776 Tf 6.084 0 Td [(1; g / createatriangulationofaspherewithhandlesand/orcrosscapswithnv vertices / #include < triang.h > voidcreate triangstructtriang t,intnv,intgenus,intorient f intv1,v2,v3,v4,v5,v6,v7; intih; inthandles,crosscaps,ec; intne; ifgenus < 0 f printf"create triang:Thegenus%dmustbenon )]TJ/F17 5.9776 Tf 5.999 0 Td [(negative. n n", genus; exit0; g iforient f orient=1; handles=genus; crosscaps=0; ec=2 )]TJ/F17 5.9776 Tf 5.865 0 Td [(2 genus; g else f orient=0; handles=genus )]TJ/F17 5.9776 Tf 6.414 0 Td [(1/2; 86

PAGE 97

crosscaps=genus )]TJ/F17 5.9776 Tf 5.972 0 Td [(1%2+1; ec=2 )]TJ/F17 5.9776 Tf 6.263 0 Td [(genus; g / testthatinputisinrange / ne=3 nv )]TJ/F17 5.9776 Tf 5.816 0 Td [(ec; ifne > MAX E f printf"create triang:numberofedgestoolarge%d.increaseMAX E. n n", ne; exit0; g ifnv nv )]TJ/F17 5.9776 Tf 6.304 0 Td [(1/2 < ne f printf"create triang:Thenumberofvertices%distoosmalltocreateatriangulation n n n onasurfacewithEulercharacteristic%d. n n n ThenumberofedgesinK%dis%dbutthenumberofedgesinatriangulationsis%d. n n", nv,ec,nv,nv nv )]TJ/F17 5.9776 Tf 6.435 0 Td [(1/2,ne; exit0; g / ifnv < 4+3 handles+2 crosscaps f printf"create triang:Thenumberofvertices%distoosmallcreateatriangulation n n n onasurfacewith%dhandlesand%dcrosscaps. n n n Ionlyknowhowtomaketriangulationswith%d4+3 h+2 cvertices. n n", nv,handles,crosscaps,4+3 handles+2 crosscaps; exit0; g / ifnv+3 > MAX V f printf"create triang:numberofverticestoolarge%d.increaseMAX V. n n", nv; exit0; g clear triangt,nv+3; / createtetrahedron / t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> orient=1; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> genus=0; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv=4; add facet,0,1,2; add facet,0,2,3; add facet,0,3,1; add facet,1,3,2; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ne=6; / addhandles / forih=0;ih < handles;ih++ f 87

PAGE 98

/ pickarandomedge.addhandletoconnecttheadjacentfaces / / sewthisontothis 7.../.././....7 . n j / j / j . nj / j / j .1///. ./ jn j / j . ./ jnj / j . nj / .//4/.1 . jjn j //: n . jjnj /./: n .//6. n /: n / . jj / jn )]TJ/F17 5.9776 Tf 5.596 0 Td [(4:3 )]TJ/F17 5.9776 Tf -129.055 -11.577 Td [(. njj / j ./ n :/ n .3///. n :/ ./ jn j / j . n :/ . jnj / j /2 ./2//./ jn . j / jn j /. . j / jnj /. .//5/ ./ j / jn j ./ j / jnj 7.............7 / t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> genus+=1; v1=0; v2=0; whilev3=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v1]== )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f v1=rand%t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv; v2=rand%t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv; g v4=t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v2]; v5=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv++; v6=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv++; v7=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv++; remove facet,v1,v2,v4; remove facet,v2,v1,v3; add facet,v1,v7,v2; add facet,v1,v2,v5; add facet,v1,v5,v4; add facet,v4,v5,v7; add facet,v4,v7,v6; add facet,v1,v6,v7; add facet,v1,v3,v6; add facet,v2,v4,v6; add facet,v2,v6,v5; 88

PAGE 99

add facet,v3,v5,v6; add facet,v3,v7,v5; add facet,v2,v7,v3; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ne+=15; reduce triangt,nv; g / addcrosscaps / if!orient f t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> orient=0; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> genus=2 t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> genus; g forih=0;ih < crosscaps;ih++ f / pickarandomedge. addcrosscapinwholeleftbyremovingadjacentfaces / / sewthisontothis 6 )188()189()188()188()189()188()189()188()]TJ/F17 5.9776 Tf 42.237 0 Td [(1 )188()189()188()188()189()188()189()188()]TJ/F17 5.9776 Tf 42.237 0 Td [(5 nj / jn / n / j 1 jn / n / j /: n jn / n / j /: n jn / n / jn /: n / j 34 j)]TJ/F17 5.9776 Tf 21.752 0 Td [(4:3 )]TJ -146.772 -11.577 Td [(j / n / nj / n :/ n j / n / njn :/ j / n / njn :/ j / n / nj 2 5 )188()189()188()188()189()188()189()188()]TJ/F17 5.9776 Tf 42.237 0 Td [(2 )188()189()188()188()189()188()189()188()]TJ/F17 5.9776 Tf 42.237 0 Td [(6/ jn nj / nj / nj / nj / nj / nj / nj / nj / nj / 1 / t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> genus++; v1=0; v2=0; whilev3=t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v2][v1]== )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f v1=rand%t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv; v2=rand%t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv; g 89

PAGE 100

v4=t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v2]; v5=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv++; v6=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv++; remove facet,v1,v2,v4; remove facet,v2,v1,v3; add facet,v1,v3,v6; add facet,v1,v5,v4; add facet,v3,v5,v6; add facet,v4,v5,v6; add facet,v2,v5,v3; add facet,v2,v4,v6; add facet,v1,v5,v2; add facet,v1,v2,v6; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ne+=9; reduce triangt,nv; g / addadditionalvertex,n,byplacingitinsiderandomface / whilet )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv < nv f v1=rand%t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv; v2=rand%t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv; ifv3=t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v2]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f v4=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv++; remove facet,v1,v2,v3; add facet,v1,v2,v4; add facet,v1,v4,v3; add facet,v2,v3,v4; t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ne+=3; g g g / createatriangulationusinglexformatinput / / lexformat:stringofasciicharacterswithnospaces eachgroupofthreelettersrepresentsaface example:abcdba= > 2faces,abcaanddbad,theendingvertixisomitted / #include < stdio.h > #include < triang.h > #defineDIM2 intdecode triang lexchar text,structtriang t f intitext,iface,v[DIM+1],nv,nf; //determinethenumberoffaces nf=strlentext/DIM+1; ifnf < 4 jj nf > MAX F f printf"decode triang lex:badformatornf%doutofrange n n%s n n", 90

PAGE 101

nf,text; return0; g //determinethenumberofvertices nv=0; foritext=0;itext < DIM+1 nf;itext++ ifa2i[text[itext]]== )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f printf"decode triang lex:badcharactercharacter=%c,hex%X,position%dinstring n n%s n n", text[itext],text[itext],itext,text; return0; g elseifa2i[text[itext]]+1 > nv nv=a2i[text[itext]]+1; ifnv < 4 jj nv > MAX V f printf"decode triang lex:badformatornv%doutofrange n n%s n n", nv,text; return0; g clear triangt,nv; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv=nv; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> orient=0; itext=0; foriface=0;iface < nf;iface++ f v[0]=a2i[text[itext++]]; v[1]=a2i[text[itext++]]; v[2]=a2i[text[itext++]]; add facet,v[0],v[1],v[2]; g t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ne=3 t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nf/2; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> genus=2 )]TJ/F17 5.9776 Tf 5.929 0 Td [(t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv )]TJ/F17 5.9776 Tf 10.184 0 Td [(t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ne+t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nf; check triangt,"decode triang lex"; return1; g / findtheotherdiagonalofthequadralateralcreatedwhenthe edgeisremoved / #include < triang.h > intfind flipstructtriang t,intv1,intv2,int o1,int o2 f / findtheothertwocorners / #ifDEBUG ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]== )]TJ/F17 5.9776 Tf 5.596 0 Td [(1 jj t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v2][v1]== )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f printf"find flip:corruptedfacesatedge%d,%d n n",v1,v2; exit0; g 91

PAGE 102

#endif o1=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]; o2=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v1]; / checkforthepossibilitythattheothertwocornersalready formanedge / ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[ o1][ o2]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 return0; return1; g / interchangeanedgefortheotherdiagonalofthequadralateralcreated whentheedgeisremoved / #include < triang.h > voidflip edgestructtriang t,intv1,intv2,into1,into2 f / removetheoldfaces / remove facet,v1,v2,o1; remove facet,v2,v1,o2; / replacethemwithnewones / add facet,o1,o2,v2; add facet,o2,o1,v1; g / initialize command line parameters.c readcommandlineargumentsandsetvaluesofglobal sigh variablesintriang.h / #include < constants.h > #include < triang.h > #include < stdio.h > voidinitialize command line parametersintargc,char argv[] f //functiononlycalledifatleast3args,safetoassumethisvalueexists num of vertices in cliques=intstrtolargv[VERTICES IN CLIQUES POS],NULL,10; ifargc > COMMAND LINE MIN COUNT f alpha=atofargv[ALPHA POS]; beta=atofargv[BETA POS]; rho=atofargv[RHO POS]; Q0=atofargv[Q0 POS]; Xi=atofargv[XI POS]; EDGE LIMIT=intstrtolargv[EDGE LIMIT POS],NULL,10; nAnt=intstrtolargv[NUM ANTS POS],NULL,10; MAX ITER=intstrtolargv[MAX ITERATIONS POS],NULL,10; 92

PAGE 103

g else f //setdefaultvalues alpha=1.0;//PheromoneExponentialWeight beta=30.0;//HeuristicExponentialWeight rho=0.01;//EvaporationRate nAnt=7;//Numberofants Q0=0.1;//Q0inACSforTourConstruction Xi=0.1;//ParameterforLocalPheromoneUpdate EDGE LIMIT=2720;//commonlyusenum vertices num vertices )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 10,2720=17 16 10 MAX ITER=1000; g g / randomlyflipedgesofatriangulationwithoutincreasingthedegreeofthelastvertex / #include < triang.h > #include < triang utils.h > voidran flip triang excludestructtriang t,intntimes f intv1,v2,v3,v4;/ vertexnumbers / intnflips;/ numberofsuccessfulflips / intnran;/ numberofrandompairsgenerated / / pickarandomedge / nflips=0; nran=0; whilenflips < ntimes&&nran < ntimes jj nflips > 0 f v1=rand%t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv; v2=rand%t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv; nran++; / ifitisreallyanedge,canbeflipped,and doesnotincreasethedegreeofthelastvertexthenflipit. / / ifitisreallyanedge,... / ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f / ...canbeflipped,... / iffind flipt,v1,v2,&v3,&v4 / ...anddoesnotincreasethedegreeofthelastvertex... / ifv3!=t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv )]TJ/F17 5.9776 Tf 10.048 0 Td [(1&&v4!=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv )]TJ/F17 5.9776 Tf 10.427 0 Td [(1 f nflips++; flip edget,v1,v2,v3,v4; ifv1==t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv )]TJ/F17 5.9776 Tf 10.048 0 Td [(1 jj v2==t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv )]TJ/F17 5.9776 Tf 10.427 0 Td [(1 nflips=0; g g g 93

PAGE 104

g / reducethenumberofverticesinatriangulationtonv / / flipedgesuntilvertexhasdegree3thenremoveit,repeat / / return1ifsuccessful,return0ifcan'treducetonv / #include < triang.h > intreduce triangstructtriang t,intnv f intv1,v2,v3,v4;/ vertexnumbers / intdegree,prev degree;/ degreeofvertextoberemoved / inttrys;/ numberoftryssofar / intnei[MAX V];/ neighborsofv1 / intinei;/ neighborindex / intX;/ Eulercharacteristic / intvmin;/ theminimumnsuchthatthereexista triangulationonthesurfacewithnvertices / / testiftheoreticallypossible / ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> orient==1 X=2 )]TJ/F17 5.9776 Tf 10.382 0 Td [(2 t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> genus; else X=2 )]TJ/F17 5.9776 Tf 10.184 0 Td [(t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> genus; / vmin=ceil7+sqrt49 )]TJ/F17 5.9776 Tf 6.158 0 Td [(24 X/2; / vmin=4; whilevmin )]TJ/F17 5.9776 Tf 6.245 0 Td [(3 vmin )]TJ/F17 5.9776 Tf 5.972 0 Td [(4 < 6 2 )]TJ/F17 5.9776 Tf 5.578 0 Td [(X vmin++; ift )]TJ/F20 5.9776 Tf 4.384 0 Td [(> orient==1&&t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> genus==2 jj t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> orient==0&&t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> genus==3 jj t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> orient==0&&t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> genus==2 vmin++; ifnv < vmin f printf"reduce triang:can'treduceatriangulationonasurfacewithgenus%dandorientation%dto%dvertices. n n",t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> genus,t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> orient,nv; exit0; g / removeextraverticesifpossible / whilet )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv > nv f v1=t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv )]TJ/F17 5.9776 Tf 10.686 0 Td [(1; degree=0; forv2=0;v2 < v1;v2++ ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 nei[degree++]=v2; trys=0; whiledegree > 3 f iftrys++ > 100 t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nereturn0; 94

PAGE 105

inei=rand%degree; v2=nei[inei]; iffind flipt,v1,v2,&v3,&v4 flip edget,v1,v2,v3,v4; else ran flip triang excludet,t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ne; prev degree=degree; degree=0; forv2=0;v2 < v1;v2++ ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]!= )]TJ/F17 5.9776 Tf 5.928 0 Td [(1 nei[degree++]=v2; ifdegree < prev degreetrys=0; g v2=nei[0]; v3=t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v2]; v4=t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v2][v1]; remove facet,v1,v2,v3; remove facet,v1,v3,v4; remove facet,v1,v4,v2; add facet,v2,v3,v4; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv )-50()]TJ/F17 5.9776 Tf 11.958 0 Td [(; t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ne=t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ne )]TJ/F17 5.9776 Tf 10.686 0 Td [(3; g return1; g / removeonefacetoatriangulation / #include < triang.h > voidremove facestructtriang t,intv1,intv2,intv3 f ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> orient==1 f #ifDEBUG ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]!=v3 jj t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v3]!=v1 jj t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v3][v1]!=v2 f printf"remove face:orientableface%d,%d,%ddoesnotexistoriscorrupted. n n", v1,v2,v3; exit0; g #endif t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v2]= )]TJ/F17 5.9776 Tf 6.083 0 Td [(1; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v2][v3]= )]TJ/F17 5.9776 Tf 6.083 0 Td [(1; t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v3][v1]= )]TJ/F17 5.9776 Tf 6.083 0 Td [(1; g else f #ifDEBUG ift )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v2]!=v3&&t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v2][v1]!=v3 jj t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v2][v3]!=v1&&t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v3][v2]!=v1 jj 95

PAGE 106

t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v3][v1]!=v2&&t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v3]!=v2 f printf"remove face:nonorientableface%d,%d,%ddoesnotexistoriscorrupted. n n", v1,v2,v3; exit0; g #endif ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]==v3 t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]= )]TJ/F17 5.9776 Tf 6.083 0 Td [(1; else t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v1]= )]TJ/F17 5.9776 Tf 6.083 0 Td [(1; ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v3]==v1 t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v2][v3]= )]TJ/F17 5.9776 Tf 6.083 0 Td [(1; else t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v3][v2]= )]TJ/F17 5.9776 Tf 6.083 0 Td [(1; ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v3][v1]==v2 t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v3][v1]= )]TJ/F17 5.9776 Tf 6.083 0 Td [(1; else t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v3]= )]TJ/F17 5.9776 Tf 6.083 0 Td [(1; g t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nf )-50()]TJ/F17 5.9776 Tf 11.959 0 Td [(; g #include < stdio.h > #include < triang utils.h > intcount cliquesstructtriangt,intnum of vertices in cliques,intPRINT OUT f intv1,v2,v3,v4,v5; intcount=0; switchnum of vertices in cliques f case3: forv1=0;v1 < t.nv )]TJ/F17 5.9776 Tf 6.166 0 Td [(2;v1++ forv2=v1+1;v2 < t.nv )]TJ/F17 5.9776 Tf 6.166 0 Td [(1;v2++ forv3=v2+1;v3 < t.nv;v3++ ift.edge[v1][v2]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1&&t.edge[v2][v3]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1&&t.edge[v1][v3]!= )]TJ/F17 5.9776 Tf 6.151 0 Td [(1 f count++; ifPRINT OUT printf"%d%d%d n n",v1,v2,v3; g break; case4: forv1=0;v1 < t.nv )]TJ/F17 5.9776 Tf 6.166 0 Td [(3;v1++ forv2=v1+1;v2 < t.nv )]TJ/F17 5.9776 Tf 6.166 0 Td [(2;v2++ forv3=v2+1;v3 < t.nv )]TJ/F17 5.9776 Tf 6.166 0 Td [(1;v3++ forv4=v3+1;v4 < t.nv;v4++ ift.edge[v1][v2]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1&&t.edge[v1][v3]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1&&t.edge[v1][v4]!= )]TJ/F17 5.9776 Tf 5.928 0 Td [(1&& t.edge[v2][v3]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1&&t.edge[v2][v4]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1&&t.edge[v3][v4]!= )]TJ/F17 5.9776 Tf 6.151 0 Td [(1 f 96

PAGE 107

count++; ifPRINT OUT printf"%d%d%d%d n n",v1,v2,v3,v4; g break; case5: forv1=0;v1 < t.nv )]TJ/F17 5.9776 Tf 6.166 0 Td [(4;v1++ forv2=v1+1;v2 < t.nv )]TJ/F17 5.9776 Tf 6.166 0 Td [(3;v2++ forv3=v2+1;v3 < t.nv )]TJ/F17 5.9776 Tf 6.166 0 Td [(2;v3++ forv4=v3+1;v4 < t.nv )]TJ/F17 5.9776 Tf 6.166 0 Td [(1;v4++ forv5=v4+1;v5 < t.nv;v5++ ift.edge[v1][v2]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1&&t.edge[v1][v3]!= )]TJ/F17 5.9776 Tf 5.928 0 Td [(1&&t.edge[v1][v4]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1&&t.edge[v1][v5]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1&& t.edge[v2][v3]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1&&t.edge[v2][v4]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1&&t.edge[v2][v5]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1&&t.edge[v3][v4]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1&& t.edge[v3][v5]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1&&t.edge[v4][v5]!= )]TJ/F17 5.9776 Tf 6.151 0 Td [(1 f count++; ifPRINT OUT printf"%d%d%d%d%d n n",v1,v2,v3,v4,v5; g break; default: break; g ifPRINT OUT ifcount==1 printf"Thereis%dK%dinthecomplement n n",count,num of vertices in cliques; else printf"Thereare%dK%dinthecomplement n n",count,num of vertices in cliques; returncount; g #include < stdio.h > #include < triang utils.h > intcount triang2structtriang t,intPRINT TRIANGLES f intv1,v2,v3; intcount; //printf" n n"; //printf"FindingComplement... n n"; count=0; forv1=0;v1 < t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv )]TJ/F17 5.9776 Tf 6.165 0 Td [(2;v1++ forv2=v1+1;v2 < t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv )]TJ/F17 5.9776 Tf 6.166 0 Td [(1;v2++ forv3=v2+1;v3 < t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv;v3++ ift )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v2]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1&& t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v2][v3]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1&& t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v3][v1]!= )]TJ/F17 5.9776 Tf 6.151 0 Td [(1 f ifPRINT TRIANGLES==1 printf"Triangle:%d%d%d n n",v1,v2,v3; elseifPRINT TRIANGLES==2 97

PAGE 108

printf"%d%d%d n n",v1,v2,v3; count++; g ifPRINT TRIANGLES==1 ifcount < =1 printf"Thereis%dtriangle. n n",count; else printf"Thereare%dtriangles. n n",count; //printf" n n"; returncount; g / display triang lex.c writeatrianginlexformattostdoutput / #include < triang utils.h > #include < stdio.h > #defineLINELEN2000 voiddisplay triang lexstructtriang t f intv0,v1; forv0=0;v0 < t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv )]TJ/F17 5.9776 Tf 6.166 0 Td [(2;v0++ forv1=v0+1;v1 < t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv )]TJ/F17 5.9776 Tf 6.166 0 Td [(1;v1++ ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v0][v1]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v0][v1] < t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v0] f ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v0][v1] > v1 f printf"%c%c%c",i2a[v0],i2a[v1],i2a[t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v0][v1]]; g ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v0] > v1 f printf"%c%c%c",i2a[v0],i2a[v1],i2a[t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v0]]; g g else f ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v0] > v1 f printf"%c%c%c",i2a[v0],i2a[v1],i2a[t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v0]]; g ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v0][v1] > v1 f printf"%c%c%c",i2a[v0],i2a[v1],i2a[t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v0][v1]]; g g g g #include < stdio.h > 98

PAGE 109

#include < triang utils.h > structtriangFlipEdgestructtriangt,intv1,intv2 f intv3,v4; structtriangt temp; t temp=t; ift.edge[v1][v2]== )]TJ/F17 5.9776 Tf 5.848 0 Td [(1 printf"nosuchedge n n"; else f if!find flip&t temp,v1,v2,&v3,&v4 printf"can'tfliptheedge[%d][%d] n n",v1,v2; else flip edge&t temp,v1,v2,v3,v4; g returnt temp; g #include < stdio.h > #include < triang utils.h > voidgenerate random triangstructtriang t,structtriang t1,structtriang t2,intnv,intgenus,intorient f create triangt1,nv,genus,orient; create triangt2,nv,genus,orient; merge 2 triangt,t1,t2; g #include < stdio.h > #include < triang utils.h > structtriangget complement graphstructtriang t f structtriangc; intv1,v2; clear triang&c,t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv; c.nv=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv; c.ne=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ne; c.nf=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nf; c.orient=t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> orient; c.genus=t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> genus; forv1=0;v1 < t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv;v1++ forv2=0;v2 < t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv;v2++ ifv1!=v2&&t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]== )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 add edge&c,v1,v2; returnc; g #include < stdio.h > 99

PAGE 110

#include < triang utils.h > voidget flippable edgesAnt MyAnt f inti,j,v1,v2,v3,v4; structtriangt1=MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> t1; structtriangt2=MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> t2; MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFECnt=0;//ResetthecounterofthetemporaryFElist forv1=0;v1 < MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> t.nv )]TJ/F17 5.9776 Tf 6.166 0 Td [(1;v1++ forv2=v1+1;v2 < MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> t.nv;v2++ f iffind flip&t1,v1,v2,&v3,&v4 f / MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFE TMP[MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFECnt][0]=i2a[v1] )]TJ/F17 5.9776 Tf 6.42 0 Td [(97;//Get1stendpoint MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFE TMP[MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFECnt][1]=i2a[v2] )]TJ/F17 5.9776 Tf 6.42 0 Td [(97;//Get2ndendpoint / MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE TMP[MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFECnt][0]=v1;//Get1stendpoint MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE TMP[MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFECnt][1]=v2;//Get2ndendpoint MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE Layer[MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFECnt]=1;//Thelayertofollow=1 MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFECnt++; //Incrementtheindex //printf"[%d][%d][%d][%d] )]TJ/F17 5.9776 Tf 6.022 0 Td [([%d]",i2a[v1] )]TJ/F17 5.9776 Tf 6.337 0 Td [(97,i2a[v2] )]TJ/F17 5.9776 Tf 6.338 0 Td [(97,v1,v2,MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE Layer[MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFECnt )]TJ/F17 5.9776 Tf 6.66 0 Td [(1]; //printf"[%d][%d][%d]",MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFE TMP[MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFECnt )]TJ/F17 5.9776 Tf 6.78 0 Td [(1][0],MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFE TMP[MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFECnt )]TJ/F17 5.9776 Tf 6.779 0 Td [(1][1],MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE Layer[MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFECnt )]TJ/F17 5.9776 Tf 6.66 0 Td [(1]; g iffind flip&t2,v1,v2,&v3,&v4 f / MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFE TMP[MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFECnt][0]=i2a[v1] )]TJ/F17 5.9776 Tf 6.42 0 Td [(97;//Get1stendpoint MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFE TMP[MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFECnt][1]=i2a[v2] )]TJ/F17 5.9776 Tf 6.42 0 Td [(97;//Get2ndendpoint / MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE TMP[MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFECnt][0]=v1;//Get1stendpoint MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE TMP[MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFECnt][1]=v2;//Get2ndendpoint MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE Layer[MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFECnt]=2;//Thelayertofollow=2 MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFECnt++; //Incrementtheindex //printf"[%d][%d][%d][%d] )]TJ/F17 5.9776 Tf 6.022 0 Td [([%d]",i2a[v1] )]TJ/F17 5.9776 Tf 6.337 0 Td [(97,i2a[v2] )]TJ/F17 5.9776 Tf 6.338 0 Td [(97,v1,v2,MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE Layer[MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFECnt )]TJ/F17 5.9776 Tf 6.66 0 Td [(1]; //printf"[%d][%d][%d]",MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFE TMP[MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFECnt )]TJ/F17 5.9776 Tf 6.78 0 Td [(1][0],MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFE TMP[MyAnt )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ListFECnt )]TJ/F17 5.9776 Tf 6.779 0 Td [(1][1],MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFE Layer[MyAnt )]TJ/F20 5.9776 Tf 4.384 0 Td [(> ListFECnt )]TJ/F17 5.9776 Tf 6.66 0 Td [(1]; g g g #include < stdio.h > voidget intprompt,integer charprompt[]; int integer; f / readanintegervaluefromstandardinput.orlettera=0,b=1,etc / charline[10]; charcharint; while1 f printf"Enter%s:",prompt; 100

PAGE 111

line[9]=0; iffgetsline,10,stdin ifline[9]==0 f ifsscanfline,"%d",integer==1 break; ifsscanfline,"%c",&charint==1 f integer=charint )]TJ/F17 5.9776 Tf 11.203 0 Td [('a'; break; g g //printf" n nEnterasingleintegerorcharacter. n n"; g //printf"%s=%d n n",prompt, integer; g voidget hexprompt,integer charprompt[]; int integer; f / readanHEXintegervaluefromstandardinput. / charline[10]; while1 f printf"Enter%sinHEX:",prompt; line[9]=0; iffgetsline,10,stdin ifline[9]==0 ifsscanfline,"%x",integer==1 break; printf" n nEnterasingleHEXvalue. n n"; g printf"%s=%x n n",prompt, integer; g #include < stdio.h > #include < triang utils.h > intload default triangleschartext file[],structtriang t,structtriang t1,structtriang t2 f charline[1024]; intpos=0; //FILE fp=fopen"./Data/17 0.txt","r"; charfilename[100]; sprintffilename,"./../Data/%s.txt",text file; FILE fp=fopenfilename,"r"; iffp==NULL return1; whilefgetsline,1024,fp f switchpos f case0: 101

PAGE 112

decode triang lexline,t1; break; case1: decode triang lexline,t2; break; default: break; g pos++; g merge 2 triangt,t1,t2; g #include < stdio.h > #include < triang.h > #include < time.h > voidinitialize log function f time trawtime; structtm timeinfo; charbuffer[100]; charbuffer2[100]; time&rawtime; timeinfo=localtime&rawtime; strftimebuffer,100,"%m%d%Y",timeinfo; sprintfbuffer2,"./../log/Log%s.txt",buffer; log file=fopenbuffer2,"a"; g #include < stdio.h > #include < triang utils.h > voidmerge 2 triangstructtriang t,structtriang t1,structtriang t2 f intv1,v2; forv1=0;v1 < t1 )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv )]TJ/F17 5.9776 Tf 6.166 0 Td [(1;v1++ f t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v1]= )]TJ/F17 5.9776 Tf 6.084 0 Td [(1; forv2=v1+1;v2 < t1 )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv;v2++ f ift1 )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]!= )]TJ/F17 5.9776 Tf 6.144 0 Td [(1 jj t1 )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v2][v1]!= )]TJ/F17 5.9776 Tf 6.144 0 Td [(1 jj t2 )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[v1][v2]!= )]TJ/F17 5.9776 Tf 6.143 0 Td [(1 jj t2 )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v1]!= )]TJ/F17 5.9776 Tf 6.283 0 Td [(1 f t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]=1; t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v1]=1; g else f t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]= )]TJ/F17 5.9776 Tf 6.144 0 Td [(1; t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v2][v1]= )]TJ/F17 5.9776 Tf 6.144 0 Td [(1; g g 102

PAGE 113

g t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[t1 )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv )]TJ/F17 5.9776 Tf 6.54 0 Td [(1][t1 )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv )]TJ/F17 5.9776 Tf 5.986 0 Td [(1]= )]TJ/F17 5.9776 Tf 5.986 0 Td [(1; t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv=t1 )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv; g #include < stdio.h > #include < triang utils.h > voidprint neighbors2structtriang t f inti,j; fori=0;i < t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv;i++ f printf"%d:",i; forj=0;j < t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv;j++ f ift )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[i][j]!= )]TJ/F17 5.9776 Tf 6.143 0 Td [(1 jj t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> edge[j][i]!= )]TJ/F17 5.9776 Tf 6.283 0 Td [(1 printf"%d",j; g printf" n n"; g g / printatriangulationofasurface / #include < triang.h > voidprint triangstructtriang t f intv1,v2; ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv < 4 jj t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv > MAX V f printf"print triang:numberofverticesmustbeatleast4andlessthan%dbutis%d. n n",MAX V,t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv; return; g printf"vertices:%d,edges:%d,faces:%d,orientable:%d,genus%d n n", t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv,t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> ne,t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nf,t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> orient,t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> genus; printf" n n"; forv2=0;v2 < t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv;v2++ printf"%3d",v2; printf" n n"; forv1=0;v1 < t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv;v1++ f printf" n n%2d",v1; forv2=0;v2 < t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv;v2++ ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]== )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 printf""; else printf"%3d",t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v2]; g printf" n n n n"; 103

PAGE 114

g / print triang lex.c Writeatriangulationinlexformattoauserspecifiedfile / #include < triang.h > #include < stdio.h > #defineLINELEN2000 voidprint triang lexFILE filename,structtriang t f intv0,v1; forv0=0;v0 < t )]TJ/F20 5.9776 Tf 4.384 0 Td [(> nv )]TJ/F17 5.9776 Tf 6.166 0 Td [(2;v0++ forv1=v0+1;v1 < t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> nv )]TJ/F17 5.9776 Tf 6.166 0 Td [(1;v1++ ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v0][v1]!= )]TJ/F17 5.9776 Tf 5.929 0 Td [(1 f ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v0][v1] < t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v0] f ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v0][v1] > v1 f fprintffilename,"%c%c%c",i2a[v0],i2a[v1],i2a[t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v0][v1]]; g ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v0] > v1 f fprintffilename,"%c%c%c",i2a[v0],i2a[v1],i2a[t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v0]]; g g else f ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v0] > v1 f fprintffilename,"%c%c%c",i2a[v0],i2a[v1],i2a[t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v1][v0]]; g ift )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v0][v1] > v1 f fprintffilename,"%c%c%c",i2a[v0],i2a[v1],i2a[t )]TJ/F20 5.9776 Tf 4.383 0 Td [(> edge[v0][v1]]; g g g g 104

PAGE 115

APPENDIXCNewGraphs Thickness =2 ,V =17 , K m removed =3 105

PAGE 116

Table3.1:Layer1Adjacencies, K 14 decomposition Vertex Adjacencies 1 4,6,7,12,13,14 2 4,5,7,8,9,10 3 4,5,6,11,13 4 1,2,3,5,6,7,9,10,13,14 5 2,3,4,6,7,9,10,11,12,14 6 1,3,4,5,9,11,12 7 1,2,4,5,8,11,13,14 8 2,7,9,14 9 2,4,5,6,8,11,14 10 2,4,5,11,14 11 3,5,6,7,9,10,13,14 12 1,5,6,14 13 1,3,4,7,11,14 14 1,4,5,7,8,9,10,11,12,13 106

PAGE 117

Table3.2:Layer2Adjacencies, K 14 decomposition Vertex Adjacencies 1 235891011 2 13611121314 3 12789101214 4 81112 5 1813 6 278101314 7 3691012 8 1345610111213 9 137101213 10 1367891213 11 124812 12 234789101113 13 256891012 14 236 107

PAGE 118

Table3.3:Layer1Adjacencies, K 15 decomposition Vertex Adjacencies 1 35789101112131415 2 368 3 12567891011121314 4 81214 5 13101214 6 2378121314 7 136121415 8 1234611121314 9 1311121314 10 1351114 11 138910121315 12 1345678911131415 13 1368911121415 14 1345678910121315 15 1711121314 108

PAGE 119

Table3.4:Layer2Adjacencies, K 15 decomposition Vertex Adjacencies 1 246 2 14579101112131415 3 415 4 123567910111315 5 246789111315 6 1459101115 7 24589101113 8 5791015 9 2456781015 10 246789121315 11 2456714 12 210 13 245710 14 211 15 234568910 109

PAGE 120

Table3.5:Layer1Adjacencies, K 16 decomposition Vertex Adjacencies 1 245810111213141516 2 1345691112131516 3 2567810111316 4 1289101112131416 5 12368101112 6 235101113141516 7 31116 8 1345101113 9 2411121415 10 134568131416 11 12345678912131416 12 1245911 13 1234681011 14 1469101115 15 12691416 16 123467101115 110

PAGE 121

Table3.6:Layer2Adjacencies, K 16 decomposition Vertex Adjacencies 1 3679 2 781014 3 149121415 4 356715 5 47913141516 6 1478912 7 12456891012131415 8 267912141516 9 135678101316 10 279111215 11 1015 12 36781013141516 13 57912141516 14 23578121316 15 3457810111213 16 589121314 111

PAGE 122

Table3.7:Layer1Adjacencies, K 17 decomposition Vertex Adjacencies 1 67111415 2 34578910151617 3 2478910111314151617 4 2378910121314 5 271114151617 6 1791116 7 123456811121314151617 8 234710121517 9 23461116 10 2348111213141517 11 13567910131415 12 47810141516 13 34710111415 14 13457101112131516 15 123578101112131416 16 23567912141517 17 235781016 112

PAGE 123

Table3.8:Layer2Adjacencies, K 17 decomposition Vertex Adjacencies 1 2345891012131617 2 1611121314 3 15612 4 15611151617 5 134689101213 6 23458101213141517 7 910 8 156911131416 9 1578101213141517 10 1567916 11 248121617 12 123569111317 13 125689121617 14 268917 15 46917 16 148101113 17 14691112131415 113

PAGE 124

APPENDIXDTuningResults Table4.1:TuningResultsfor =2 NumberofAnts AverageIterations Average K m Remaining 1 516 1 2 506 1 4 34 0 8 7 0 10 4 0 16 4 0 32 2 0 64 3 0 128 1 0 114

PAGE 125

Table4.2:TuningResultsfor =3 NumberofAnts AverageIterations Average K m Remaining 1 491 0 2 506 1 4 6 0 8 20 0 10 6 0 16 3 0 32 2 0 64 1 0 128 1 0 Table4.3:TuningResultsfor =4 NumberofAnts AverageIterations Average K m Remaining 1 516 1 2 506 1 4 34 0 8 7 0 10 4 0 16 4 0 32 2 0 64 3 0 128 1 0 115

PAGE 126

Table4.4:TuningResultsfor =5 NumberofAnts AverageIterations Average K m Remaining 1 503 1 2 405 0 4 48 0 8 13 0 10 15 0 16 11 0 32 1 0 64 1 0 128 1 0 116