Class HyperGraph
java.lang.Object
org.unifi.mecvirtualresourceallocation.graph.HyperGraph
This class represents a hypergraph, which consists of a set of hyperedges and vertices. In the
context of Mobile Edge Computing (MEC), a hypergraph is used to model the complex relationships
between virtual machine (VM) instances and physical machines (PMs). Each hyperedge connects
multiple vertices (VMs).
-
Constructor Summary
ConstructorsConstructorDescriptionHyperGraph
(int[][] placementMatrix, double[] weights) Constructs a hypergraph from a placement matrix and vertex weights.HyperGraph
(Set<Vertex> vertices, Set<HyperEdge> hyperEdges) Constructs a hypergraph with the specified vertices and hyperedges. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addHyperEdge
(HyperEdge hyperEdge) Adds a hyperedge to the hypergraph, ensuring no duplicate hyperedge IDs exist.Generates a conflict graph based on the hypergraph.Gets the hyperedges of the hypergraph.int[][]
Generates and returns a placement matrix based on the current hypergraph.Gets the vertices of the hypergraph.void
Prints the placement matrix to the console.void
Saves the current hypergraph visualization as an SVG file.void
Displays the hypergraph using a graphical user interface.toString()
Returns a string representation of the hypergraph, including its vertices and hyperedges.
-
Constructor Details
-
HyperGraph
Constructs a hypergraph with the specified vertices and hyperedges.- Parameters:
vertices
- the vertices of the hypergraphhyperEdges
- the hyperedges of the hypergraph
-
HyperGraph
public HyperGraph(int[][] placementMatrix, double[] weights) Constructs a hypergraph from a placement matrix and vertex weights. The order of vertices is determined by their corresponding weights in the weights array, which must match the order of rows in the placement matrix.- Parameters:
placementMatrix
- the placement matrix where rows represent vertices and columns represent hyperedges. Each element should be 1 if the corresponding vertex is part of the hyperedge, otherwise 0weights
- the array of weights for the vertices. The order of weights must match the order of rows in the placement matrix- Throws:
IllegalArgumentException
- if the number of weights does not match the number of rows in the placement matrix
-
-
Method Details
-
getVertices
Gets the vertices of the hypergraph.- Returns:
- the vertices
-
getHyperEdges
Gets the hyperedges of the hypergraph.- Returns:
- the hyperedges
-
addHyperEdge
Adds a hyperedge to the hypergraph, ensuring no duplicate hyperedge IDs exist. The vertices of the hyperedge are also added to the hypergraph if not already present.- Parameters:
hyperEdge
- the hyperedge to be added- Throws:
IllegalArgumentException
- if the hyperedge has no vertices or if there are duplicate IDs
-
getConflictGraph
Generates a conflict graph based on the hypergraph. The conflict graph represents conflicts between hyperedges where conflicts are defined by the presence of common vertices.- Returns:
- the generated conflict graph
-
printPlacementMatrix
public void printPlacementMatrix()Prints the placement matrix to the console. -
getPlacementMatrix
public int[][] getPlacementMatrix()Generates and returns a placement matrix based on the current hypergraph.- Returns:
- the placement matrix where rows represent vertices and columns represent hyperedges Each element is 1 if the corresponding vertex is part of the hyperedge, otherwise 0
-
toString
Returns a string representation of the hypergraph, including its vertices and hyperedges. -
showGraph
public void showGraph()Displays the hypergraph using a graphical user interface. -
saveToSvg
Saves the current hypergraph visualization as an SVG file. The file is saved as "hypergraph.svg" in the current directory.- Parameters:
filePath
- The file path where the SVG file will be saved
-