Table Of Content2
1
0
2
n
a
J
8
2
]
S
D
.
s
c
[
Implementation of
1
v
5 exponential and
8
9
5 parametrized algorithms in
.
1
0
2 the AGAPE project
1
:
v
i
X
r P. Berthomé, J.-F. Lalande, V. Levorato
a
LIFO, Université d’Orléans - ENSI de Bourges
Report no RR-2012-01
Version 1
CONTENTS P.Berthomé,J.-F.Lalande,V.Levorato
Contents
Presentation 3
1 Installationnotes 3
2 Packagescontent 3
2.1 Packageagape.algos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1.1 ClassColoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1.2 ClassMinDFVS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.1.3 ClassMIS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.1.4 ClassMVC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.1.5 ClassSeparators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2 Packageagape.applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2.1 Graphicaleditor: theGraphEditorclass . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2.2 Agapecommandlineapplication: theAgapeCLclass . . . . . . . . . . . . . . . . . . . . 6
2.3 Packageagape.generators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3.1 Randomgraphgenerators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3.2 Structuredgraphgenerators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.4 Packageagape.io . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.5 Packageagape.tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.6 Packageagape.visualization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3 Tutorials 9
3.1 Tutorialsforbasics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.1.1 CreatingJunggraphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.1.2 Input/Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.1.3 Usingfactories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.1.4 Usinggenerators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.2 Tutorialsforalgorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.2.1 UsingColoringalgorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.2.2 UsingMinDFVSalgorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2.3 UsingMISalgorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.2.4 UsingMVCalgorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.2.5 UsingSeparatorsalgorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
References 21
2
P.Berthomé,J.-F.Lalande,V.Levorato
Presentation
Thistechnicalreportdescribestheimplementationofexactandparametrizedexponentialalgorithms,developed
during the French ANR Agape during 2010-2012. The developed algorithms are distributed under the CeCILL
licenseandhavebeenwritteninJavausingtheJunggraphlibrary.
1 Installation notes
The source code is available at http://traclifo.univ-orleans.fr/Agape/. Several dependencies
arenecessaryinordertousetheAgapelibrary. Theyareincludedinthelib/directoryoftheSVNtrunk:
• Junglibrary2.0.1,BSDlicense(jung*.jar).
• Apachecommonsforcollections,ApacheLicense2.0(collections-generic-4.01.jar)1.
• Guavai.e. Google’scollections,ApacheLicense2.0,(guava-r09.jar).
• Mascoptoptimizationlibrary,LGPL,(mascoptLib.jar).
TheprojectcanbedownloadedasanEclipseprojectfromtheSVNtrunkrepository(seeinstructionsonthe
website). Itisparticularlyusefulforstudyingthesourcecodeoftheprovidedalgorithms. Tousethislibraryasa
dependencyinanotherproject,onlytheagape.jarfileandthedependencies(dependencies.zip)areneeded.
2 Packages content
Inthissection,webrieflydescribetheimplementedalgorithms. Section3describeshowtousethesealgorithms
throughsimpletutorials.
2.1 Packageagape.algos
This package contains the different implemented exponential or parametrized algorithms. The abstract class
Algorithms groups the different factories for graph/vertices/arcs creation. The graphs are based on generic
classes of the Jung library. Indeed, some algorithms require to instantiate vertices or arcs. The instanciation of
such objects depends of the nature of the generic token, e.g. a vertex can be an Integer. Thus, as the type
ofverticesarenotknowninadvance,thealgorithmsthatrequiretocreategraphsshouldobtainafactoryforthe
providedgraph.
The different classes and their hierarchy are represented in Figure 1. Table 1 sums-up the different imple-
mented algorithms, their complexity in time and the references to the papers that provided the algorithms. The
last column recalls the acronym used for the Agape Command Line tool (c.f. Section 2.2.2). In the following
subsections,eachimplementedalgorithmisbrieflydescribed.
2.1.1 ClassColoring
Thegoalofthisclassistocomputetheminimumnumberofcolorstoproperlycoloranundirectedgraph.
intchromaticNumber(Graph<V,E>G): Computes the chromatic number of a graph G. This method is based
ontheAnexactalgorithmforgraphcoloringwithpolynomialmemorybyBodlaenderandKratsch[4]. The
algorithmsolvestheprobleminPSPACEandintimeO(5.283n).
Set<Set<V>>graphColoring(Graph<V,E>G): Computes a solution having the minimum chromatic number
usingthesamealgorithmasbefore. Itreturnsthepartitionoftheverticesintocolorclasses.
Set<Set<V>>greedyGraphColoring(Graph<V,E>G): agreedyalgorithmthatcomputesiterativelythemaxi-
mumindependetsetofGandremovesit.
1Thisisanew(veryoldi.e.2006)versionofthepopularJakartaCommons-Collectionsproject.ItfeaturessupportforJava1.5Generics.
Genericsintroduceawholenewlevelofusabilityandtype-safetytotheCommons-Collectionsclasses.
3
2.1 Packageagape.algos P.Berthomé,J.-F.Lalande,V.Levorato
Acronym Algorithm Timecomplexity References AgapeCL
CN ChromaticNumber
Bodlaender,Kratsch O(5.283n) [4] CN
DFVS DirectedFeedbackVertexSet
Razgon,Thomassé O(1.9977n) [14,16] DFVS
MIS MaximumIndependentSet
Brute-Force O(n2.2n) MISBF
Moon,Moser O(1.4423n) [12] MISMM
Fomin,Grandoni,Kratsch O(1.2201n) [9] MISFGK
MVC MinimumVertexCover
Brute-Force O((cid:0)n(cid:1)) MVCBF
k
Niedermeier O(1.47k) [13] MVCDBS
Niedermeier O(1.33k) [13] MVCN
Buss,Goldsmith – [13,5] MVCBG
SEP Minimalab-Separators
Berry,Bordat,Cogis O(n3) [3] SEP
Table1: Algorithmssummary
2.1.2 ClassMinDFVS
Thisclassisdedicatedtotheminimumdirectedfeedbackvertexset.Thisproblemconsistsinfindingtheminimum
numberofverticestodeleteinordertogetadirectedacyclicgraphfromadirectedgraph.
Set<V>minimumDirectedAcyclicSubset(Graph<V,E>G): Computes the Minimum Directed Acyclic Subset
asthecomplementoftheMaximumDirectedFeedbackVertexSet(seebelow).
Set<V>maximumDirectedAcyclicSubset(Graph<V,E>G): The implemented method solves the problem in
timeO(1.9977n)usingtheRazgonworkComputingMinimumDirectedFeedbackVertexSetinO∗(1.9977n)[14]).
ItuseskernelizationtechniquespresentedinA4k2kernelforfeedbackvertexsetbyThomassé[16].
Set<V>greedyMinFVS(Graph<V,E>G): ComputesanapproximationoftheFVSproblemusingthebigdegree
heuristic,writtenbyLevorato.Startingfromtheinitialgraph,thealgorithmremovesthevertexwithhighest
degreeuntilthegraphisacyclic.
Thisclassalsoprovidesamethodthatenumeratesallthecycles. Thiscanbeusefulltofindallthecyclesthat
areimpactedbyagivenvertexoftheminimumfeedbackvertexset.
Set<ArrayList<V>>enumAllCircuitsTarjan(Graph<V,E>G) Enumeratesallcircuitsofagraph(Tarjan,Enu-
merationoftheelementarycircuitsofadirectedgraph[15]).
Algorithms
DFVS Coloring MIS MVC Separators
MarkMap
Figure1: Theagape.algospackagehierarchy
4
2.1 Packageagape.algos P.Berthomé,J.-F.Lalande,V.Levorato
2.1.3 ClassMIS
This class computes the maximum independ set of a graph (directed or undirected). This problem consists in
findingthemaximumsetofverticessuchthattwoverticesofthecomputedsetarenotneighborsintheoriginal
graph. Severalalgorithmshavebeenimplemented.
Set<V>maximalIndependentSetGreedy(Graph<V,E>g): implementsapolynomialgreedyheuristicinO(n+
m). Thealgorithmchoosesverticesofminimumdegreeandremovestheneighborsiteratively.
Set<V>maximumIndependentSetBruteForce(Graph<V,E>g): this algorithm examines every vertex subset
andcheckswhetheritisanindependentsetusingtheisIndependentSetmethod.Thetimecomplexity
isO(n2.2n).
Set<V>maximumIndependentSetMaximumDegree(Graph<V,E>g): thisalgorithmcomputesanexactsolu-
tionbybranchingonthemaximumdegreevertexthatiseitherinoroutofthefinalsolutionandcomputes
theresultrecursively. ThisalgorithmhasbeenproposedbyI.TodincaandM.Liedloffbuthasnoproved
upperbound.
Set<V>maximumIndependentSetMoonMoser(Graph<V,E>g): thealgorithmsolvestheproblemintimeO(1.4423n).
ItisbasedonOncliquesingraphs[12].
Set<V>maximumIndependentSetMoonMoserNonRecursive(Graph<V,E>g): thisisthenonrecurvisvever-
sionofthepreviousalgorithm. Experimentalbenchmarksshowthatthisversionisslower.
Set<V>maximuRmIndependentSetFominGrandoniKratsch(Graph<V,E>g): thismethodisbasedonAMea-
sure & Conquer Approach forthe Analysis of Exact Algorithms [9]. The algorithm solves the problem in
timeO(1.2201n).
Twomethodshelptodetectifasetisanindependentsetforagivengraph:
booleanisIndependentSet(Graph<V,E>g,Set<V>S): verifiesthatSisanindependentsetofG.
booleanisMaximalIndependentSet(Graph<V,E>g,Set<V>S): verifiesthatSisamaximalindependentsetof
G(cannotbecompleted).
2.1.4 ClassMVC
ThisclassimplementsalgorithmsforsolvingtheMinimumVertexCoverproblem.Theproblemconsistsinfinding
theminimumsetofverticessuchthatanyvertexisatdistanceatmost1ofthecomputedset.Thisclassonlyworks
onundirectedgraphs.
Set<V>twoApproximationCover(Graph<V,E>g): 2-approximation of the Minimum Vertex Cover problem.
Thealgorithmreturnsacoverthatisatmostofdoublesizeofaminimalcover,O(|E|)time.
Set<V>greedyCoverMaxDegree(Graph<V,E>g): this greedy heuristic computes a result by selecting itera-
tivelythevertexhavingthemaximumdegree.
booleankVertexCoverBruteForce(Graph<V,E>g,intk): thismethodselectsallthesetsofsizekamongnand
checksifthissetcoversthegraph. TheresultingcomplexityisO((cid:0)n(cid:1)). Thealgorithmtriestopotentially
k
selecttheverticesthatarenotcoveredfirstwhichimprovestheexecutiontime.
booleankVertexCoverDegreeBranchingStrategy(Graph<V,E>g,intk): thismethodusesDegree-Branching-
Strategy (DBS) and has a time complexity of O(1.47k). This algorithm is extracted from Invitation to
Fixed-ParameterAlgorithms[13]pp. 90.
booleankVertexCoverNiedermeier(Graph<V,E>g,intk): this method is an implementation of Niedermeier
algorithmofInvitationtoFixedParameterAlgorithms[13]pp.99-101,whichtimecomplexityisO(1.33k).
booleankVertexCoverBussGoldsmith(Graph<V,E>g,intk): this method is an implementation of Buss and
GoldsmithreductionalgorithmofNondeterminismwithinP[5],presentedbyNiedermeierin[13]pp. 54.
5
2.2 Packageagape.applications P.Berthomé,J.-F.Lalande,V.Levorato
Figure2: Screencaptureofthegrapheditor
2.1.5 ClassSeparators
Thisclassimplementsalgorithmsforsolvingtheminimalseparatorproblem. TheAB-separatorproblemconsists
infindingtheminimumsetofverticessuchthatremovingthissetofverticesdisconnectsthevertexAfromB.
Set<Set<V>>getABSeparators(Graph<V,E>g,Va,Vb): thismethodcomputesthesetofminimalab-separator
in O(n3) per separator. It is an implementation based on Generating All the Minimal Separators of a
Graph[3].
Set<Set<V>>getAllMinimalSeparators(Graph<V,E>g): this method returns all the minimal ab-separators
forallpairsofvertices.
2.2 Packageagape.applications
Thispackagecontaintwosoftware: agraphgraphicaleditorandcommandlineprogramthatallowstolaunchthe
previouslypresentedalgorithms.
2.2.1 Graphicaleditor: theGraphEditorclass
Thegraphicaleditorisasimpleexample, basedontheJunglibrary, asshowninFigure2. Onlythepossiblyof
savingagraphintoafilehasbeenadded.
2.2.2 Agapecommandlineapplication: theAgapeCLclass
Thecommandlineapplicationallowstoapplyanchosenalgorithmtoagraphorasetofgraphs. Allthegraphs
mustbewritteninthe.netformat. ThisformatcomesfromthePajeksoftwareforsocialnetworkanalysis. A
.net file is composed of the list of vertices and the adjacency list. An example of a Pajek file is presented in
Listing2.2.2. Thegraphiscomposedof4verticesand4edges(a,b),(b,c),(b,d),and(c,d).
TheAgapeCLcommandlineapplicationcanbeusedwiththestandalonepackagedistributedonthewebsite:
java -jar AgapeCL.jar graphFilePath|graphDirectoryPath algorithm
Thefirstparameteristhenameofthe.netfile(orthedirectorythatcontainsmultiplefiles)andthesecond
oneisthealgorithmnamethathastobechosenamongCN,MISBF,MISMM,MISDegMax,MISFGK,MVCBF,
6
2.3 Packageagape.generators P.Berthomé,J.-F.Lalande,V.Levorato
Exampleof.netfile
∗Vertices4
1"a"
2"b"
3"c"
4"d"
∗edgeslist
12
234
34
MVCBG,MVCDBS,MVCN,DFVS,SEPthatcorrespondtothealgorithmofTable1. Thetwofollowinglistings
showexamplesofexecution.
Exampleofexecutionontest.net Exampleofexecutiononadirectory
java -jar AgapeCL.jar ../test.net MISFGK java -jar AgapeCL.jar ../GenGraphs/temp/
MISFGK
V:50 E:238
660.0 ms 16cell.net
Size: 14 V:8 E:24
[v0, v48, v17, v18, v36, v6, v25, v13, v9, 36.0 ms
v40, v34, v44, v31, v32] Size: 2
[3, 2]
snark.net
V:12 E:15
5.0 ms
Size: 6
[2, 10, 0, 5, 8, 11]
thomassen20.net
V:20 E:37
18.0 ms
Size: 8
[1, 6, 19, 4, 17, 9, 14, 11]
2.3 Packageagape.generators
This package contains several graph generators. Two categories of generators have been implemented: random
and non random generators. Some generators are based on Jung generators and others have been implemented
fromscratch. Belowislistedalltheavailablegenerators. Allthegeneratorsneedfactoriestoinstantiatevertices
andedges.
2.3.1 Randomgraphgenerators
• ErdösRényirandomgraphs[8].
• Eppsteinrandomgraphs(fromJung)[7].
• Barabasi-Albertrandomgraphs(fromJung)[2].
• Kleinbergsmallworldgraphs[10].
• Watts-Strogatzsmallworldgraphs[17].
• k-regularrandomgraphs.
7
2.4 Packageagape.io P.Berthomé,J.-F.Lalande,V.Levorato
2.3.2 Structuredgraphgenerators
SeeSection3.1.4foranexampleofuseofthesetwogenerators.
• 2Dgrids.
• K-regularrings.
Inordertousethegenerators,theuserhastodefinefirstagraphfactorybeforeusingoneofthegenerators. A
tutorialaboutfactoriesispresentedinSection3.1.3.
2.4 Packageagape.io
Thispackagecontainstwoclassesfortheread/writeoperationongraphs(ImportandExport).
Formatssupportedforreading:
• .netorientedornonoriented(Pajek)[6].
• .mglMascopt[11].
• .tgfWolframMathematicahttp://www.wolfram.com/mathematica/.
Formatssupportedforwritting:
• .netorientedornonoriented(Pajek)[6].
• .gvGraphVizhttp://www.graphviz.org/.
Atutorialaboutinput/outputispresentedinsection3.1.2.
2.5 Packageagape.tools
This package is a set of toolboxes for classical graph operations. In the Operations class, we implemented
metric detection (diameter, degrees, ...), type identification (clique, regular, simple edge, ...), copy operations
(copy,merge,subgraphs,...),...Forexample,thegetMinDeg(Graph<V,E> g)returnsthevertexthathas
thesmallestdegreeandisRegular(Graph<V,E> gtestifthegraphisk-regular. IntheComponentsclass,
weimplementedmethodsforconnectedcomponentsofagraph,forexampletheTarjan’smethodthatcomputes
allthestronglyconnectedcomponentsingetAllStronglyConnectedComponent(Graph<V,E> g.
2.6 Packageagape.visualization
This package contains the class Visualization that provides a method to display a graph (showGraph) and a
methodtorepresentagraphasaB-matrix[1],asshowninFigure3.
8
P.Berthomé,J.-F.Lalande,V.Levorato
10
9
8
7
6
5
4
3
2
1 10 20 30 40 50 60 70 80 90 100
Figure3: B-matrixforaWatts-STrogatzsmallworld
3 Tutorials
3.1 Tutorialsforbasics
3.1.1 CreatingJunggraphs
JunggraphsareeasytobuildusingtemplatedclassessuchasDirectedSparseGraph. Verticesandedgesare
javaobjectsthataremanipulatedbytheJungclassgraphs.
Tutorial: agape.tutorials.JungGraphTutorial Tutorial: consoleoutput
/∗ Vertices:n1,n3,n2
∗CopyrightUniversityofOrleans−ENSIdeBourges. Edges:1[n1,n2]
∗SourcecodeunderCeCILLlicense. Vertices:n1,n4,n3,n2
∗/ Edges:1[n1,n2]2[n1,n4]
packageagape.tutorials; Vertices:n4,n3,n2
Edges:
importedu.uci.ics.jung.graph.DirectedSparseGraph;
importedu.uci.ics.jung.graph.util.Pair;
publicclassJungGraphTutorial{
publicstaticvoidmain(String[]args){
DirectedSparseGraph<String,Integer>g=new
DirectedSparseGraph<String,Integer>();
g.addVertex("n1");
g.addVertex("n2");
g.addVertex("n3");
//Jungfindsmatchingnodesevenifpointersaredifferent
g.addEdge(1,newPair<String>("n1","n2"));
System.out.println(g);
//Jungaddsautomaticallynewnodes
g.addEdge(2,newPair<String>("n1","n4"));
System.out.println(g);
g.removeVertex("n1");
System.out.println(g);
}
}
9
3.1 Tutorialsforbasics P.Berthomé,J.-F.Lalande,V.Levorato
3.1.2 Input/Output
A.netreaderhavebeenimplementedintheclassImport. Thefirstlineofthefileisignored(title), theneach
lineisparsedtoreadvertices(name“label”)untilthestring*edgeslistisfound.Then,theedges/arcsareread
until the end. The .net file instanciates Graph<String,Integer> which implies that vertices are String
andedges/arcsareInteger. Exportingagraphtoafileworksthesameway. TheExportclasscanalsowrite
filesusingthegraphvizformat.
Tutorial: agape.tutorials.IOTutorial Tutorial: IOTutorial.net
∗Vertices4
1"a"
2"b"
3"c"
/∗ 4"d"
∗CopyrightUniversityofOrleans−ENSIdeBourges. ∗edgeslist
∗SourcecodeunderCeCILLlicense. 12
∗/ 234
packageagape.tutorials; 34
importjava.io.IOException;
Tutorial: IOTutorial.gv
importagape.io.Export;
importagape.io.Import; digraphG{
importedu.uci.ics.jung.graph.Graph; size="100,20";ratio=auto;
node[style=filled];
/∗∗ "a"−>"b"[color="0.6490.7010.701"];
∗@authorjf "b"−>"c"[color="0.6490.7010.701"];
∗/ "b"−>"d"[color="0.6490.7010.701"];
publicclassIOTutorial{ "c"−>"d"[color="0.6490.7010.701"];
publicstaticvoidmain(String[]args){ "d"[color=grey];
Graph<String,Integer>g=Import.readDNet("src/agape/tutorials/ "b"[color=grey];
IOTutorial.net"); "c"[color=grey];
System.out.println(g); "a"[color=grey];
try{ }
Export.writeGV("src/agape/tutorials/IOTutorial",g);
}catch(IOExceptione){
e.printStackTrace();
}
}
}
10