Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Greedy color PR #70

Open
wants to merge 157 commits into
base: GreedyColorPR
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
157 commits
Select commit Hold shift + click to select a range
f83f77b
init interval graphs, implemented centered interval tree
danielmock Apr 16, 2018
b782f92
updated
danielmock Apr 16, 2018
b4eca98
Merge pull request #2 from danielmock/intervalgraph
pdelvo Apr 17, 2018
129f592
init IntervalGraphInterface
christophgruene Apr 18, 2018
59b9261
init BinarySearchTree
christophgruene Apr 18, 2018
fe728c3
added class Node and RedBlackTree
christophgruene Apr 18, 2018
89ef8da
modified existing implemntations
christophgruene Apr 18, 2018
337de7a
small changes
christophgruene Apr 18, 2018
63c42b8
first implementations of the interval graph data structure
christophgruene Apr 18, 2018
d5ee236
Added GraphTests.isIntervalGraph(graph) as an interface for the inter…
Apr 18, 2018
939d68a
Added complete graph, circle graph and an arbitrary graph for testing…
Apr 18, 2018
fb35288
changed real line to number line (since we actually use integers and …
Apr 18, 2018
da72c33
typo
Apr 18, 2018
9e43092
added IntervalSpecifics (not finished), finished IntervalGraph
christophgruene Apr 18, 2018
24e8f30
finished first implementation of interval graph, added intervalGraphV…
christophgruene Apr 19, 2018
fa76b5d
modified interval graph data structures
christophgruene Apr 19, 2018
758458c
added constructor to IntervalVertexTree
christophgruene Apr 19, 2018
ce4a890
implemented necessary getter and setter for node
christophgruene Apr 19, 2018
b34d408
added methods for rotation and color flipping to red black tree
christophgruene Apr 19, 2018
2d6a683
made methods of node protected
christophgruene Apr 19, 2018
bcf622a
added interface for IntervalTree, modified implementations
christophgruene Apr 19, 2018
9652366
removed error
christophgruene Apr 19, 2018
84ecd64
added IntervalVertex as interface for vertices in interval graphs
christophgruene Apr 19, 2018
6187c21
added to all interval graph specific classes that vertices have to im…
christophgruene Apr 19, 2018
f2bb253
Implemented RBTree
danielmock Apr 19, 2018
6b77b32
Implemented RBTree
danielmock Apr 19, 2018
3f87634
Merge remote-tracking branch 'origin/intervalGraphs' into intervalGraphs
danielmock Apr 19, 2018
0aa0a87
Implemented LBFS/LBFS+
Watercrystal Apr 19, 2018
0ad1170
Add some tests for the interval tree and fix a found bug
pdelvo Apr 20, 2018
5237507
Merge pull request #5 from pdelvo/intervalTreeTests
danielmock Apr 20, 2018
4c5be67
Implemented IntervalTree
danielmock Apr 20, 2018
52369bf
Added overlapsWith() and very few comments
danielmock Apr 20, 2018
a2eb258
changes in interval tree data strcuture to ensure correct abstraction…
christophgruene Apr 20, 2018
23399e2
IOrdering Algorithm added
AbdallahAt Apr 21, 2018
835fa4e
LBFS/+ changed to work around existing LBFS implementation, hopefully
Watercrystal Apr 22, 2018
ed9c4e7
added class IntervalTreeNodeValue to use this as wrapper class for th…
christophgruene Apr 22, 2018
d8c77a3
Add some tests for the interval tree and fix a found bug
pdelvo Apr 20, 2018
1c5d35d
Interval Graph Recognition Algorithm - General Skeleton
Apr 22, 2018
5ad3f1c
updated method addIntervalEdges() and addVertex() in IntervalGraph su…
christophgruene Apr 22, 2018
93cf6db
added new line at end of file
christophgruene Apr 22, 2018
cdcd83c
fixed adding to intervaltree
christophgruene Apr 22, 2018
509eff6
added Override to insert() method of RedBlackIntervalTree
christophgruene Apr 23, 2018
cfb5cac
Merge remote-tracking branch 'christophgruene/intervalGraphs' into in…
pdelvo Apr 23, 2018
5083f7e
Implemented basically the missing parts of the algorithm; still need …
Watercrystal Apr 23, 2018
8dd0dff
Fix bugs in the interval graph detection and add some tests
pdelvo Apr 24, 2018
0a96f91
adpated Test to new Implementations
christophgruene Apr 24, 2018
3062411
added implementation of IntervalVertexInterface and modified interfac…
christophgruene Apr 24, 2018
2dd1053
commented code
christophgruene Apr 26, 2018
943cd47
add implementation of Serializable interface
christophgruene Apr 26, 2018
f16d378
added interval graph constructor with initial vertices
christophgruene Apr 26, 2018
5809ff9
Merge pull request #8 from christophgruene/origin/intervalGraphs
christophgruene Apr 27, 2018
423481a
Merge remote-tracking branch 'upstream/intervalGraphs-Algo' into inte…
Apr 28, 2018
00e983b
added the last forbidden interval graph test
Apr 28, 2018
cba4928
changed the minimal size for some tests
Apr 28, 2018
2f9f22e
added linear graph and unconnected graph to tests for algo
Apr 28, 2018
27cd154
Added a RBTree using Comparator instead of Keys
danielmock Apr 29, 2018
f5c0ed0
Fixed typo
Watercrystal Apr 30, 2018
23385af
Merge branch 'intervalGraphs-Algo' of https://github.com/tj-developer…
Watercrystal Apr 30, 2018
a112521
Added documentation, refactored recognizer to be an object with field…
Watercrystal Apr 30, 2018
a9f5c10
Added more documentation for the recognizer class and some notes fors…
Watercrystal Apr 30, 2018
d2b663c
Refactored tests to work with recognizer instances rather than a stat…
Watercrystal Apr 30, 2018
87ef7ee
Implemented linear time I-Ordering algorithm
Watercrystal Apr 30, 2018
1d6f922
Add tests for RedBlackTree
May 1, 2018
0e4fa06
Fix typos in RedBlackTree
May 1, 2018
dae17f8
fixed bug while deleting vertices
christophgruene May 2, 2018
1820898
Merge pull request #18 from christophgruene/origin/intervalGraphs
christophgruene May 2, 2018
b79cbea
refreshed redblackintervaltree integration
christophgruene May 2, 2018
0ae4e6b
redone incorrect changes
christophgruene May 2, 2018
4285a04
added Intervalgraph Tree Decomposition Algorithm
May 2, 2018
f44e0f7
fixed RedBlackTree.min
danielmock May 3, 2018
13aadda
add doc for type <K> in RedBlackIntervalTree
christophgruene May 3, 2018
a39a3af
Added list constructor
danielmock May 3, 2018
e517d1c
Merge remote-tracking branch 'origin/intervalGraphs' into intervalGraphs
danielmock May 3, 2018
800eb5b
added initialization of graph with given vertices, edge construction …
christophgruene May 3, 2018
c63d472
Change isIOrdering to use an array list instead of a hash map
pdelvo May 3, 2018
c8b2b28
Merge branch 'intervalGraphs-Algo' into intervalGraphs
pdelvo May 3, 2018
976750c
finished first version of asIntervalGraph starring the longest generi…
christophgruene May 3, 2018
f05dc21
Added test class and some changes to treedecomposition for interval g…
May 3, 2018
3c104be
Merge branch 'intervalGraphs' into intervalAlgoTest
May 3, 2018
d99f7c0
changed the tests to the new interface
May 3, 2018
7ab7608
Merge branch 'intervalGraphs' into intervalGraphsTests
May 3, 2018
80c64ea
added GraphTests.isIntervalGraph() implementation
May 3, 2018
58280ab
Fix bugs in the interval graph detection algorithm
pdelvo May 3, 2018
47a9732
Fix typos
May 4, 2018
9f42f43
Refactoring
May 4, 2018
a7c8ba0
Refactoring and documentation for Interval
May 4, 2018
302f19e
Merge pull request #9 from PhoenixIra/intervalAlgoTest
pdelvo May 4, 2018
e35e5b1
Add tests for RedBlackComparatorTree
May 4, 2018
87a67e7
Fix NullPointerException in RedBlackTree
May 4, 2018
ca5d0ee
rewrite constructor with initial vertices, init of asIntervalGraph() …
christophgruene May 4, 2018
3149d45
changed signature of interval graph constructors such that they are o…
christophgruene May 4, 2018
78aabcc
Merge pull request #21 from pdelvo/intervalAlgoTest
pdelvo May 6, 2018
61d9748
Tests for IntervalGraph
AbdallahAt May 6, 2018
636cc00
Merge pull request #23 from AbdallahAt/intervalGraphs
pdelvo May 7, 2018
2bb071e
Implement the required interface to build an interval graph
pdelvo May 7, 2018
a1a37d4
Add a mapping from the vertices to the intervals
pdelvo May 7, 2018
75fdc97
Make the isIntervalGraph method private
pdelvo May 7, 2018
c95fd67
Return interval vertices instead of intervals
pdelvo May 7, 2018
1ee683c
finished asIntervalGraph(Graph)
christophgruene May 7, 2018
87d5867
Address PR feedback
pdelvo May 7, 2018
5764157
Merge pull request #24 from pdelvo/recognizerIntervalInterface
pdelvo May 7, 2018
c826c40
Merge pull request #19 from christophgruene/intervalGraphs
pdelvo May 7, 2018
1f2404c
Remove old comments
pdelvo May 7, 2018
cc59205
again changed some interfaces
May 7, 2018
817c016
Merge branch 'intervalGraphs' into treedecomposition
May 7, 2018
3f55e9d
Fix that the code does not compile
pdelvo May 7, 2018
e6ce44f
Fix failing tests
pdelvo May 7, 2018
a211849
Use interval as vertex
May 7, 2018
12fbc76
changed some issues with pointer und Hash stuff
May 7, 2018
8de6bff
Fix all style violations
pdelvo May 7, 2018
97ac52f
Fix invalid html in javadocs
pdelvo May 7, 2018
2300c64
Merge pull request #26 from pdelvo/oldComments
pdelvo May 7, 2018
f2cd965
Merge pull request #25 from PhoenixIra/intervalGraphsTests
pdelvo May 7, 2018
f166ae0
fixed generic shit in asIntervalGraph()
christophgruene May 7, 2018
de1afad
Merge branch 'intervalGraphs' of github.com:tj-developers/jgrapht int…
christophgruene May 7, 2018
7e898f2
solved merge conflict
christophgruene May 7, 2018
99548c1
Merge branch 'magnificent-tony-intervalGraphs' into intervalGraphs
christophgruene May 7, 2018
3c0c94d
fixed javaDoc
christophgruene May 7, 2018
ae8cd02
deleted unnecessary classes
christophgruene May 7, 2018
d380a50
Tests for IntervalGraph
AbdallahAt May 8, 2018
d51458c
Merge pull request #29 from AbdallahAt/intervalGraphs
christophgruene May 8, 2018
2e57f7b
fixed tests
christophgruene May 8, 2018
7985599
Finally fixed decomposition algo
May 12, 2018
0f64ee5
Merge branch 'intervalGraphs' into treedecomposition
May 12, 2018
e3332c4
added Comparator to Intervals
May 12, 2018
1d77dbb
fixes and changes in the structure
May 14, 2018
74b247a
added doc
May 14, 2018
ca56ef0
oops - removed debug output
May 14, 2018
dca3484
changed according to check style
May 14, 2018
622e086
changed Set of Roots to Join Node Construction of Root
May 15, 2018
ead4923
negative list did not need to be reversed in radixSortInteger (abs ma…
May 15, 2018
7e538d7
having fun with edge cases (list.size = 0)
May 15, 2018
655b9b8
initial commit, optimization and tests needed
May 23, 2018
f909902
changes according to PR and changed structure back to path decomposition
May 25, 2018
9115526
Added comments, need to optimize and include generalisations
May 26, 2018
d43d681
need to add more tests
May 26, 2018
347e1c8
needed to put it in a new package
May 27, 2018
10cbd1a
good enough for now
May 27, 2018
8470e25
refactored structure for chordal graph decomposition
May 31, 2018
8971c51
added javadoc for builder class
May 31, 2018
a2c9761
removed some special symbols
May 31, 2018
6a9fe77
Refactores tests methods a bit
Jun 2, 2018
e4bcaa7
... and this
Jun 2, 2018
139709b
refactored/renamed and changed an isEmpty
Jun 9, 2018
75f490c
ci fix
Jun 9, 2018
e6c6609
changed abstract nice Decomposition Builder class
Jun 13, 2018
f8faedf
Merge pull request #31 from PhoenixIra/treedecomposition
Jun 14, 2018
7f92249
Minor changes, need to change the input parameters
Jun 16, 2018
e3289be
Minor changes, need to change the input parameters
Jun 16, 2018
8253cc4
Input parameters changed to Graph<Int,Edge> and Map<Int,Set<V>>
Jun 16, 2018
f014e21
Added tests, need to add more tests
Jun 16, 2018
08517c2
Moved DecompositionTreeColour to the color package
Aug 10, 2018
b46bb2a
Merge branch 'intervalDecomposition' of https://github.com/tj-develop…
Aug 10, 2018
1826b31
Moved DecompositionTreeColourTest to color package
Aug 10, 2018
c251b2c
temporary changes
Aug 13, 2018
7c61980
changed the tabs to spaces and added javadoc
Aug 14, 2018
c57371f
added javadoc
Aug 14, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions jgrapht-core/src/main/java/org/jgrapht/GraphTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.jgrapht.alg.connectivity.KosarajuStrongConnectivityInspector;
import org.jgrapht.alg.cycle.ChordalityInspector;
import org.jgrapht.alg.cycle.HierholzerEulerianCycle;
import org.jgrapht.alg.intervalgraph.*;

import java.util.*;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -495,6 +496,24 @@ public static <V, E> boolean isChordal(Graph<V, E> graph){
Objects.requireNonNull(graph, GRAPH_CANNOT_BE_NULL);
return new ChordalityInspector<>(graph).isChordal();
}

/**
* Tests whether a graph is an interval graph. <a href="https://en.wikipedia.org/wiki/Interval_graph">
* Interval graphs</a> are a familiy of graphs, which can be represented as intersections of intervals.
* The vertices are intervals on the number line and two vertices are connected if and only if the intervals of
* these vertices intersect each other.
*
* @param graph the input graph
* @param <V> the graph vertex type
* @param <E> the graph edge type
* @return true if the graph is an interval graph, false otherwise
* @see IntervalGraphRecognizer#isIntervalGraph()
*
*/
public static <V, E> boolean isIntervalGraph(Graph<V, E> graph) {
Objects.requireNonNull(graph, GRAPH_CANNOT_BE_NULL);
return new IntervalGraphRecognizer<>(graph).isIntervalGraph();
}

/**
* Tests whether an undirected graph meets Ore's condition to be Hamiltonian.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package org.jgrapht.alg.color;

import java.util.Collections;
import org.jgrapht.Graph;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import org.jgrapht.alg.interfaces.VertexColoringAlgorithm;

/**
* Colouring of decomposition trees (currently done for interval graphs). This
* algorithm iterates over lists of vertices and assigns the smallest colour to
* each of the vertices such that the no vertex in the same list has the same
* colour.
*
* @author Suchanda Bhattacharyya (dia007)
*
* @param <V>
* The type of graph vertex
* @param <E>
* The type of graph edge
*/

public class DecompositionTreeColour<V, E> implements VertexColoringAlgorithm<V> {

/**
* The input graph
*/
private Graph<Integer, E> graph;
/**
* The map of the vertices in the input graph to it's interval sets
*/
private Map<Integer, Set<V>> decompositionMap;

/**
*
* @param graph the input graph
* @param decompositionMap the input decomposition map
*/
public DecompositionTreeColour(Graph<Integer, E> graph, Map<Integer, Set<V>> decompositionMap) {
this.graph = Objects.requireNonNull(graph, "Graph cannot be null");
this.decompositionMap = Objects.requireNonNull(decompositionMap, "there must be some decomposition present");
}

/**
* Getting the ordering for the vertices
*
* @return the ordering of the vertices
*/

protected Iterable<Integer> getVertexOrdering() {
return (Iterable<Integer>) graph.vertexSet();

}

/*
* (non-Javadoc)
*
* @see org.jgrapht.alg.interfaces.VertexColoringAlgorithm#getColoring()
*/
@Override
public Coloring<V> getColoring() {

Map<V, Integer> asssignedColors = new HashMap<>();
Set<Integer> used = new HashSet<>();
Set<V> free = new HashSet<>();

// self loops not allowed, repetitions of inner vertices not allowed

for (Integer vertex : getVertexOrdering()) {

// find the intervals corresponding to the vertex
// need to sort the vertices
List<V> intervalSet = decompositionMap.get(vertex).stream().sorted().collect(Collectors.toList());

for (V innerVertex : intervalSet) {
// first need to iterate over each innerVertex in the outerVertex to check that
// if there is any vertex with an already assigned colour
if (asssignedColors.containsKey(innerVertex)) {
used.add(asssignedColors.get(innerVertex));

} else {
// these are the vertices without any assigned colours
free.add(innerVertex);

}
}

// here we assign colours to the free vertices

for (V freeVertex : free) {
int colourCandidate = 0;
while (used.contains(colourCandidate)) {
colourCandidate++;
}

asssignedColors.put(freeVertex, colourCandidate);

used.add(colourCandidate);

}
free.clear();
used.clear();

}

int maxColourAssigned = Collections.max(asssignedColors.values());

return new ColoringImpl<>(asssignedColors, maxColourAssigned + 1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
package org.jgrapht.alg.decomposition;

import java.util.*;
import org.jgrapht.*;
import org.jgrapht.alg.intervalgraph.IntervalGraphRecognizer;
import org.jgrapht.intervalgraph.*;
import org.jgrapht.intervalgraph.interval.*;

/**
* Class for calculating the nice Tree Decomposition for interval graphs
*
* @param <T> the value type of the intervals of the interval graph
* @param <V> the type of the nodes of the input graph
*
* @author Ira Justus Fesefeldt (PhoenixIra)
* @since Mai 14, 2018
*/
public class IntervalGraphNiceDecompositionBuilder<T extends Comparable<T>, V> extends NiceDecompositionBuilder<V>
{
// input to the algorithm, list of sorted intervals
private List<Interval<T>> startSort, endSort;
private Map<Interval<T>, V> intervalToVertexMap;
private Map<V, Interval<T>> vertexToIntervalMap;

// helper attributes
private Integer currentVertex = null;

/**
* Private constructor for the factory methods, which changes the inputs
*
* @param sortedByStartPoint the intervals sorted after the starting points
* @param sortedByEndPoint the intervals sorted after the ending points
* @param intervalToVertexMap maps intervals to the vertices of the graph (may be the same)
*/
private IntervalGraphNiceDecompositionBuilder(
List<Interval<T>> sortedByStartPoint, List<Interval<T>> sortedByEndPoint,
Map<Interval<T>, V> intervalToVertexMap, Map<V, Interval<T>> vertexToIntervalMap)
{
super();

this.startSort = sortedByStartPoint;
this.endSort = sortedByEndPoint;
this.intervalToVertexMap = intervalToVertexMap;
this.vertexToIntervalMap = vertexToIntervalMap;

computeNiceDecomposition();
}

/**
* Factory method for creating a nice tree decomposition for interval graphs. This factory
* method uses general graphs and the IntervalGraphRecognizer to generate a list of intervals
* sorted by starting and ending points. The complexity of this method depends on the sorting
* algorithm in IntervalGraphRecognizer (probably quasi linear in the number of intervals)
*
* @param graph the graph which should transformed to an interval graph and then into a
* corresponding nice tree decomposition
* @param <V> the vertex type of the graph
* @param <E> the edge type of the graph
* @return the algorithm for the computation of the nice tree decomposition, returns null if
* graph was no interval graph
* @see IntervalGraphRecognizer
*/
public static <V, E> IntervalGraphNiceDecompositionBuilder<Integer, V> create(Graph<V, E> graph)
{
IntervalGraphRecognizer<V, E> recog = new IntervalGraphRecognizer<>(graph);

HashMap<V, Interval<Integer>> vertexToIntegerMap =
new HashMap<>(recog.getVertexToIntervalMap().size());

Map<V,IntervalVertexInterface<V, Integer>> vertexToIntervalVertexMap = recog.getVertexToIntervalMap();
for (V key : vertexToIntervalVertexMap.keySet())
vertexToIntegerMap.put(key, vertexToIntervalVertexMap.get(key).getInterval());

if (recog.isIntervalGraph())
return new IntervalGraphNiceDecompositionBuilder<Integer, V>(
recog.getIntervalsSortedByStartingPoint(),
recog.getIntervalsSortedByEndingPoint(), recog.getIntervalToVertexMap(),
vertexToIntegerMap);
else
return null;
}

/**
* Factory method for creating a nice tree decomposition for interval graphs. This factory
* method extracts the intervals from the interval graph and uses them as an input for the
* computation. The complexity of this method depends on the sorting algorithm of ArrayList
* (probably O(|V| log(|V|))
*
* @param intervalGraph the input for which a nice tree decomposition should be computed
* @param <V> the IntervalVertex Type of the interval graph
* @param <E> the edge type of the interval graph
* @param <VertexType> the vertex type of the graph
* @param <T> the value of the intervals
* @return the algorithm for the computation of the nice tree decomposition
* @see ArrayList#sort(Comparator)
*/
public static <V extends IntervalVertexInterface<VertexType, T>, E, VertexType,
T extends Comparable<T>> IntervalGraphNiceDecompositionBuilder<T, V> create(
IntervalGraph<V, E, VertexType, T> intervalGraph)
{
Set<V> vertexSet = intervalGraph.vertexSet();
List<Interval<T>> intervals = new ArrayList<Interval<T>>(vertexSet.size());
Map<Interval<T>, V> intervalToVertexMap = new HashMap<>(vertexSet.size());
Map<V, Interval<T>> vertexToIntervalMap = new HashMap<>(vertexSet.size());
for (V iv : vertexSet) {
intervals.add(iv.getInterval());
intervalToVertexMap.put(iv.getInterval(), iv);
vertexToIntervalMap.put(iv, iv.getInterval());
}
ArrayList<Interval<T>> startSort = new ArrayList<>(intervals);
ArrayList<Interval<T>> endSort = new ArrayList<>(intervals);
startSort.sort(Interval.<T> getStartingComparator());
endSort.sort(Interval.<T> getEndingComparator());
return new IntervalGraphNiceDecompositionBuilder<T, V>(
startSort, endSort, intervalToVertexMap, vertexToIntervalMap);
}

/**
* Factory method for creating a nice tree decomposition for interval graphs. This factory
* method needs to lists of intervals, the first sorted after starting points, the second after
* ending points The complexity of this method is linear in the number of intervals
*
* @param sortedByStartPoint a list of all intervals sorted by the starting point
* @param sortedByEndPoint a list of all intervals sorted by the ending point
* @param <T> the value of the intervals
* @return the algorithm for the computation of the nice tree decomposition
*/
public static <T extends Comparable<T>> IntervalGraphNiceDecompositionBuilder<T, Interval<T>> create(
List<Interval<T>> sortedByStartPoint, List<Interval<T>> sortedByEndPoint)
{
HashMap<Interval<T>, Interval<T>> identity = new HashMap<>(sortedByStartPoint.size());
for (Interval<T> interval : sortedByStartPoint)
identity.put(interval, interval);
return new IntervalGraphNiceDecompositionBuilder<T, Interval<T>>(
new ArrayList<Interval<T>>(sortedByStartPoint),
new ArrayList<Interval<T>>(sortedByEndPoint), identity, identity);
}

/**
* Factory method for creating a nice tree decomposition for interval graphs. This factory
* method needs to lists of intervals, which then is sorted by ArrayList.sort(). The complexity
* of this method depends on the sorting Algorithm of ArrayList (probably O(|List| log(|List|))
*
* @param intervals the (unsorted) list of all intervals
* @param <T> the values of the intervals
* @return the algorithm for the computation of the nice tree decomposition
* @see ArrayList#sort(Comparator)
*/
public static <T extends Comparable<T>> IntervalGraphNiceDecompositionBuilder<T, Interval<T>> create(
List<Interval<T>> intervals)
{
ArrayList<Interval<T>> startSort = new ArrayList<>(intervals);
ArrayList<Interval<T>> endSort = new ArrayList<>(intervals);
startSort.sort(Interval.<T> getStartingComparator());
endSort.sort(Interval.<T> getEndingComparator());
return create(startSort, endSort);
}

/**
* Main method for computing the nice tree decomposition
*/
private void computeNiceDecomposition()
{

// create all objects and set new root
currentVertex = getRoot();

int endIndex = 0;

// as long as intervals remain
for (Interval<T> current : startSort) {
// first forget until you need to introduce new nodes
while (endSort.get(endIndex).getEnd().compareTo(current.getStart()) < 0) {
V forgetElement = intervalToVertexMap.get(endSort.get(endIndex));
currentVertex = addForget(forgetElement, currentVertex);
endIndex++;
}
V introduceElement = intervalToVertexMap.get(current);
currentVertex = addIntroduce(introduceElement, currentVertex);
}
// add the last forget nodes
while (endIndex < endSort.size()) {
V forgetElement = intervalToVertexMap.get(endSort.get(endIndex++));
currentVertex = addForget(forgetElement, currentVertex);
}
}

/**
* getter for interval to vertex Map
*
* @return a map that maps intervals to vertices
*/
public Map<Interval<T>, V> getIntervalToVertexMap()
{
return intervalToVertexMap;
}

/**
* getter for vertex to interval map
*
* @return a map that maps vertices to intervals
*/
public Map<V, Interval<T>> getVertexToIntervalMap()
{
return vertexToIntervalMap;
}
}
Loading