All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.cloudsimplus.network.topologies.TopologicalGraph Maven / Gradle / Ivy

Go to download

CloudSim Plus: A modern, highly extensible and easier-to-use Java 8+ Framework for Modeling and Simulation of Cloud Computing Infrastructures and Services

The newest version!
/*
 * Title:        CloudSim Toolkit
 * Description:  CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
 * Licence:      GPL - http://www.gnu.org/copyleft/gpl.html
 *
 * Copyright (c) 2009-2012, The University of Melbourne, Australia
 */

package org.cloudsimplus.network.topologies;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;

/**
 * Represents a graph containing vertices (nodes) and edges (links),
 * used for input with a network-layer.
 *
 * 

Graphical-Output Restrictions: *

    *
  • EdgeColors: GraphicalProperties.getColorEdge
  • *
  • NodeColors: GraphicalProperties.getColorNode
  • *
*

* * @author Thomas Hohnstein * @since CloudSim Toolkit 1.0 */ public class TopologicalGraph { /** * The list of links (edges) of the network graph. */ private final List linksList; /** * The list of nodes (vertices) of the network graph. */ private final List nodeList; /** * Creates an empty network topology graph. */ public TopologicalGraph() { linksList = new LinkedList<>(); nodeList = new LinkedList<>(); } /** * Adds a link between two topological nodes. * * @param edge the topological link */ public void addLink(final TopologicalLink edge) { linksList.add(Objects.requireNonNull(edge)); } /** * Adds a Topological Node to this graph. * * @param node the topological node to add */ public void addNode(final TopologicalNode node) { nodeList.add(Objects.requireNonNull(node)); } /** * Gets the number of nodes contained inside the topological-graph. * * @return number of nodes */ public int getNumberOfNodes() { return nodeList.size(); } /** * Gets the number of links contained inside the topological-graph. * * @return number of links */ public int getNumberOfLinks() { return linksList.size(); } /** * Gets a read-only List of all network-graph links. * * @return the List of network-graph links */ public List getLinksList() { return Collections.unmodifiableList(linksList); } /** * Gets a read-only list of nodes of the network graph. */ public List getNodeList() { return Collections.unmodifiableList(nodeList); } @Override public String toString() { final var builder = new StringBuilder(61); builder.append("topological-node-information: ").append(System.lineSeparator()); for (final TopologicalNode node : nodeList) { builder.append("%d | %s%n".formatted(node.getId(), node.getWorldCoordinates())); } builder.append("%n%n node-link-information:%n".formatted()); for (final TopologicalLink link : linksList) { builder.append( "from: %d to: %d delay: %.2f%n" .formatted(link.getSrcNodeID(), link.getDestNodeID(), link.getLinkDelay())); } return builder.toString(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy