API Reference

This reference is generated from Virne’s public classes and docstrings. Optional machine-learning and optimization dependencies are mocked while building the documentation, so importing the API does not install packages or require a GPU.

Network Models and Generators

class virne.network.base_network.BaseNetwork(*args, **kwargs)[source]

Bases: Graph

Network class inherited from networkx.Graph.

Variables:
  • node_attrs – Node attributes.

  • link_attrs – Link attributes.

  • graph_attrs – Graph attributes.

Parameters:
  • incoming_graph_data (networkx.Graph | None)

  • config (DictConfig | dict | None)

property adjacency_matrix

Get the adjacency matrix of Network.

check_attrs_existence()[source]

Check if all defined node and link attributes exist in the graph. Raises AssertionError with a clear message if any attribute is missing.

Return type:

None

clone()[source]

Return a deep copy of the network instance.

Return type:

BaseNetwork

create_attrs_from_setting()[source]

Create node and link attribute dictionaries from their respective settings.

classmethod from_gml(fpath, label='id')[source]

Create a Network object from a GML file.

Parameters:
  • fpath (str) – The file path of the GML file.

  • label (str) – The label of the nodes, default is ‘id’.

generate_attrs_data(node=True, link=True)[source]

Generate the data of network attributes based on attributes.

generate_topology(num_nodes, type='path', **kwargs)[source]

Generate the network topology and update the graph structure in-place.

Parameters:
  • num_nodes (int) – The number of nodes in the generated graph. Must be >= 1.

  • type (str) – The type of graph to generate. Supported: ‘path’, ‘star’, ‘waxman’, ‘random’.

  • **kwargs – Additional keyword arguments required for certain graph types.

Raises:
  • AssertionError – If num_nodes < 1 or type is unsupported.

  • NotImplementedError – If the graph type is not implemented.

Return type:

None

get_adjacency_attrs_data(link_attrs, normalized=False)[source]

Get the data of adjacency attributes.

get_graph_attrs(names)[source]

Get the attributes of the network.

Parameters:

names (str) – The names of the attributes to retrieve. If None, return all attributes.

Returns:

A dictionary of network attributes.

Return type:

dict

Get the types of link attributes.

Get the link attributes of the network.

Parameters:
  • types (str) – The types of the link attributes to retrieve. If None, return all attributes.

  • names (str) – The names of the link attributes to retrieve. If None, return all attributes.

Returns:

A list of link attributes.

Return type:

list

Get the data of link attributes.

get_node_attr_types()[source]

Get the types of node attributes.

get_node_attrs(types=None, names=None)[source]

Get the node attributes of the network.

Parameters:
  • types (str) – The types of the node attributes to retrieve. If None, return all attributes.

  • names (str) – The names of the node attributes to retrieve. If None, return all attributes.

Returns:

A list of node attributes.

Return type:

list

get_node_attrs_data(node_attrs)[source]

Get the data of node attributes.

init_graph_attrs()[source]

Initialize the graph attributes.

Get the number of links.

property num_edges

Get the number of links.

Get the number of link features.

Returns:

The number of link features.

Return type:

int

Get the number of link resource features.

Returns:

The number of link resource features.

Return type:

int

Get the number of links.

property num_node_features: int

Get the number of node features.

Returns:

The number of node features.

Return type:

int

property num_node_resource_features: int

Get the number of node resource features.

Returns:

The number of node resource features.

Return type:

int

property num_nodes

Get the number of nodes.

save_attrs_dict(fpath)[source]

Save the graph, node, and link attributes to a file.

Parameters:

fpath (str)

Return type:

None

set_graph_attribute(name, value)[source]

Set a graph attribute attr to value.

set_graph_attrs_data(attributes_data)[source]

Set the data of graph attributes.

Set the data of link attributes.

set_node_attrs_data(node_attributes_data)[source]

Set the data of node attributes.

class virne.network.physical_network.PhysicalNetwork(*args, **kwargs)[source]

Bases: BaseNetwork

Represents a physical network, inheriting from BaseNetwork.

This class handles the generation, loading, and saving of physical network topologies

Parameters:
  • incoming_graph_data (networkx.Graph | None)

  • config (DictConfig | dict | None)

  • kwargs (Any)

classmethod from_setting(config, seed=None)[source]

Creates a PhysicalNetwork instance from a configuration dictionary.

The method can either load a topology from a GML file specified in the settings or generate a new topology if a file path is not provided or invalid.

Parameters:
  • cls – The class itself (PhysicalNetwork).

  • setting – A dictionary containing the network configuration. Expected keys include ‘node_attrs_setting’, ‘link_attrs_setting’, ‘topology’ (which may contain ‘file_path’), and ‘num_nodes’ (if generating topology).

  • seed (int | None) – An optional random seed for reproducibility.

  • config (Dict[str, Any])

Returns:

A PhysicalNetwork instance configured according to the settings.

Raises:
  • KeyError – If essential keys are missing from the setting dictionary.

  • FileNotFoundError – If a specified GML file_path does not exist.

Return type:

_PN

generate_attrs_data(node=True, link=True)[source]

Generates attribute data for the network’s nodes and links.

This method populates attributes based on their settings and calculates benchmarks for these attributes.

Parameters:
  • node (bool) – If True, generate attributes for nodes.

  • link (bool) – If True, generate attributes for links.

Return type:

None

generate_topology(num_nodes, type='waxman', **kwargs)[source]

Generates a topology for the physical network.

Parameters:
  • num_nodes (int) – The number of nodes in the network.

  • type (str) – The type of topology to generate (e.g., ‘waxman’, ‘barabasi_albert’).

  • **kwargs (Any) – Additional keyword arguments to pass to the NetworkX topology generator.

Return type:

None

classmethod load_dataset(dataset_dir, file_name='p_net.gml')[source]

Loads a physical network from a ‘p_net.gml’ file within the specified directory.

After loading, it calculates and sets the necessary benchmarks for normalization.

Parameters:
  • cls – The class itself (PhysicalNetwork).

  • dataset_dir (str) – The directory path containing the ‘p_net.gml’ file.

  • file_name (str)

Returns:

A PhysicalNetwork instance loaded from the dataset.

Raises:

FileNotFoundError – If ‘p_net.gml’ is not found in the dataset_dir.

Return type:

_PN

save_dataset(dataset_dir, file_name='p_net.gml')[source]

Saves the current physical network (topology and attributes) to a GML file.

The file will be named ‘p_net.gml’ within the specified directory. The directory will be created if it doesn’t exist.

Parameters:
  • dataset_dir (str) – The directory path where the ‘p_net.gml’ file will be saved.

  • file_name (str)

Return type:

None

class virne.network.virtual_network.VirtualNetwork(*args, **kwargs)[source]

Bases: BaseNetwork

VirtualNetwork class is a subclass of Network class. It represents a virtual network.

Variables:
  • incoming_graph_data – Data to initialize the graph.

  • config – Configuration dictionary for the network.

Parameters:
  • incoming_graph_data (Any | None)

  • config (DictConfig | dict | None)

  • kwargs (Any)

generate_topology(num_nodes, type='random', **kwargs)[source]

Generates a virtual network topology.

Parameters:
  • num_nodes (int)

  • type (str)

  • kwargs (Any)

Return type:

None

Calculates the total resource demand of all links in the virtual network.

property total_node_resource_demand: float

Calculates the total resource demand of all nodes in the virtual network.

property total_resource_demand: float

Calculates the total resource demand of all nodes and links in the virtual network.

class virne.network.virtual_network_request_simulator.VirtualNetworkRequestSimulator(v_nets=None, events=None, v_sim_setting=None, **kwargs)[source]

Bases: object

A class for simulating sequentially arriving virtual network requests.

Variables:
  • v_sim_setting (dict) – A dictionary containing the setting for the virtual network request simulator.

  • num_v_nets (int) – The number of virtual networks to be simulated.

  • aver_arrival_rate (float) – The average arrival rate of virtual network requests.

  • aver_lifetime (float) – The average lifetime of virtual network requests.

  • v_nets (list) – A list of VirtualNetwork objects representing the virtual networks.

  • events (list) – A list of tuples representing the events in the simulation.

Parameters:
  • v_nets (Sequence[VirtualNetwork] | None)

  • events (Sequence[VirtualNetworkEvent] | None)

  • v_sim_setting (dict | None)

arrange_v_nets()[source]

Arrange virtual networks, including length, lifetime, arrival_time

static from_setting(setting, seed=None)[source]

Create a VirtualNetworkRequestSimulator object from a config dict (new style)

Parameters:
  • setting (dict | DictConfig)

  • seed (int | None)

static load_dataset(dataset_dir)[source]

Load the Virtual Network Simulator dataset from a directory.

The following files are expected to be present in the directory: - v_nets: Directory containing virtual network files in GML format. - events.yaml: YAML file containing event data. - setting.yaml: YAML file containing the simulator settings.

property num_events

Get the number of events

property num_v_nets

Get the number of virtual networks

renew(v_nets=True, events=True, seed=None)[source]

Renew virtual networks and events

Parameters:
  • v_nets (bool, optional) – Whether to renew virtual networks. Defaults to True.

  • events (bool, optional) – Whether to renew events. Defaults to True.

  • seed (int, optional) – Random seed. Defaults to None.

save_dataset(save_dir)[source]

Save the dataset to a directory

save_setting(fpath)[source]

Save the setting to a file

validate_v_net_lifecycles()[source]

Validate every VN before event generation or environment execution.

class virne.network.dataset_generator.Generator[source]
static generate_changeable_v_nets_dataset_from_config(config, save=False)[source]

Generate a dynamic virtual network request simulator dataset based on the given configuration.

Parameters:
  • config (dict or object) – Configuration object containing the settings for the generator.

  • save (bool) – Whether or not to save the generated dataset.

Returns:

A VirtualNetworkRequestSimulator object representing the generated dataset.

Return type:

VirtualNetworkRequestSimulator

static generate_dataset(config, p_net=True, v_nets=True, save=False)[source]

Generate a dataset consisting of a physical network and a virtual network request simulator.

Parameters:
  • config (dict or object) – Configuration object containing the settings for the generator.

  • p_net (bool) – Whether or not to generate a physical network dataset.

  • v_nets (bool) – Whether or not to generate a virtual network request simulator dataset.

  • save (bool) – Whether or not to save the generated datasets.

Returns:

A tuple consisting of the generated physical network and virtual network request simulator.

Return type:

Tuple

static generate_p_net_dataset_from_config(config, save=False)[source]

Generate a physical network dataset based on the given configuration.

Parameters:
  • config (omegaconf.DictConfig or dict) – Configuration object containing the settings for the generator.

  • save (bool) – Whether or not to save the generated dataset.

Returns:

A PhysicalNetwork object representing the generated dataset.

Return type:

PhysicalNetwork

static generate_v_nets_dataset_from_config(config, save=False)[source]

Generate a virtual network request simulator dataset based on the given configuration.

Parameters:
  • config (omegaconf.DictConfig or dict) – Configuration object containing the settings for the generator.

  • save (bool) – Whether or not to save the generated dataset.

Returns:

A VirtualNetworkRequestSimulator object representing the generated dataset.

Return type:

VirtualNetworkRequestSimulator

class virne.network.attribute.BaseAttribute(name, owner, type, generative=False, **kwargs)[source]

Bases: ABC

Abstract base class for all network attributes.

Parameters:
  • name (str)

  • owner (str)

  • type (str)

  • generative (bool)

generate_data(network)[source]

Generate data for the attribute based on the network.

Parameters:

network (BaseNetwork)

Return type:

ndarray

update_data(network, attribute_data)[source]

Update the attribute data in the network.

Parameters:
  • network (BaseNetwork)

  • attribute_data (dict | list | ndarray)

Return type:

None

class virne.network.attribute.AttributeBenchmarkManager(network)[source]

Computes attribute benchmarks for a BaseNetwork instance.

Parameters:

network (BaseNetwork)

classmethod add_to_cache(cache_key, benchmarks)[source]

Add computed benchmarks to the class-level cache.

Parameters:
  • cache_key (str) – The key to identify the cached benchmarks.

  • benchmarks (AttributeBenchmarks) – The benchmarks to cache.

Return type:

None

classmethod clear_cache()[source]

Clear the class-level cache.

Return type:

None

classmethod get_from_cache(cache_key)[source]

Retrieve cached benchmarks using the provided key.

Parameters:

cache_key (str) – The key to identify the cached benchmarks.

Returns:

The cached benchmarks, or None if not found.

Return type:

Optional[AttributeBenchmarks]

Computes benchmarks for link attributes.

Parameters:
  • network (BaseNetwork) – The network instance.

  • link_attr_types (Optional[List[str]]) – Types of link attributes to consider.

Returns:

Benchmarks for each link attribute.

Return type:

Dict[str, float]

Computes benchmarks for aggregated link attributes.

Parameters:
  • network (BaseNetwork) – The network instance.

  • link_attr_types (Optional[List[str]]) – Types of link attributes to aggregate.

Returns:

Benchmarks for each aggregated link attribute.

Return type:

Dict[str, float]

static get_node_attr_benchmarks(network, node_attr_types=['resource', 'extrema'])[source]

Computes benchmarks for node attributes.

Parameters:
  • network (BaseNetwork) – The network instance.

  • node_attr_types (Optional[List[str]]) – Types of node attributes to consider.

Returns:

Benchmarks for each node attribute.

Return type:

Dict[str, float]

class virne.network.attribute.AttributeBenchmarks(node_attr_benchmarks=None, link_attr_benchmarks=None, link_sum_attr_benchmarks=None)[source]

Data class to hold benchmarks for node and link attributes.

Parameters:
  • node_attr_benchmarks (Dict[str, float] | None)

  • link_attr_benchmarks (Dict[str, float] | None)

  • link_sum_attr_benchmarks (Dict[str, float] | None)

class virne.network.topology.TopologyGenerator[source]

Utility class to generate various networkx topologies for BaseNetwork.

class virne.network.topology.TopologicalMetricCalculator(network, degree=True, closeness=False, eigenvector=False, betweenness=False)[source]

Calculates and returns topological metrics for a BaseNetwork instance.

Parameters:
  • network (BaseNetwork)

  • degree (bool)

  • closeness (bool)

  • eigenvector (bool)

  • betweenness (bool)

classmethod add_to_cache(cache_key, metrics)[source]

Adds a new entry to the cache.

Parameters:
  • cache_key (str) – The key under which to store the metrics.

  • metrics (TopologicalMetrics) – The metrics to store.

Return type:

None

classmethod clear_cache()[source]

Clears the cache of topological metrics.

Return type:

None

classmethod get_from_cache(cache_key)[source]

Retrieves metrics from the cache.

Parameters:

cache_key (str) – The key for the metrics to retrieve.

Returns:

The cached metrics, or None if not found.

Return type:

Optional[TopologicalMetrics]

class virne.network.topology.TopologicalMetrics(node_degree_centrality=None, node_closeness_centrality=None, node_eigenvector_centrality=None, node_betweenness_centrality=None)[source]

Data class to hold topological metrics for a network.

Parameters:
  • node_degree_centrality (ndarray | None)

  • node_closeness_centrality (ndarray | None)

  • node_eigenvector_centrality (ndarray | None)

  • node_betweenness_centrality (ndarray | None)

Core Simulation Objects

class virne.core.environment.BaseEnvironment(p_net, v_net_simulator, controller, recorder, counter, logger, config, **kwargs)[source]

Bases: object

A general environment for various solvers based on heuristics and RL

Parameters:
add_record(record, extra_info={})[source]

Add extra information to the record and add the record to the recorder.

Parameters:
  • record (dict) – the record to be added.

  • extra_info (dict) – the extra information to be added.

Returns:

the record with extra information.

Return type:

record (dict)

compute_reward()[source]

Compute the reward for the current Virtual Network.

Return type:

float

count_and_add_record(extra_info={})[source]

Count the record and add the record to the recorder.

Parameters:

extra_info (dict) – the extra information to be added.

Return type:

Dict[str, Any]

display_record(record, display_items=['result', 'v_net_id', 'v_net_cost', 'v_net_revenue', 'p_net_available_resource', 'total_revenue', 'total_cost', 'description'], extra_items=[])[source]

Display the record, including the default display items and extra display items.

Parameters:
  • record (dict) – the record to be displayed.

  • display_items (list) – the default display items.

  • extra_items (list) – the extra display items.

Return type:

None

get_failure_reason(solution)[source]

Get the reason of failure, which is used to rollback the state of the physical network.

Parameters:

solution (Solution) – the solution of the current Virtual Network.

Returns:

the reason of failure.

Return type:

reason (str)

get_info(record=None)[source]

Return an isolated copy of the current step record.

Parameters:

record (Dict[str, Any] | None)

Return type:

Dict[str, Any]

get_observation()[source]

Get the observation for the current Virtual Network.

Return type:

Dict[str, Any]

property num_placed_v_net_nodes: int

Get the number of already placed virtual nodes for the current Virtual Network.

property placed_v_net_nodes: List[Any]

Get the already placed virtual nodes for the current Virtual Network.

ready(event_id=0)[source]

Prepare for the given event.

Parameters:

event_id (int) – the position of the event to be processed.

Return type:

None

release()[source]

Release the current Virtual Network when it leaves the system.

Return type:

Dict[str, Any]

render(mode='human')[source]

Render the environment.

Parameters:

mode (str) – the mode to render the environment.

Return type:

None

reset(seed=None)[source]

Reset the environment.

Parameters:

seed (int | None) – the seed for the random number generator. If None, use the seed in the config.

Return type:

Dict[str, Any]

rollback_for_failure(reason='place')[source]

Rollback the state of the physical network for the failure of the current Virtual Network.

Parameters:

reason (str) – the reason of failure.

Return type:

None

property selected_p_net_nodes: List[Any]

Get the already selected physical nodes for the current Virtual Network.

step(action)[source]

Take an action and return the next observation, reward, done, and info.

Parameters:

action (Any) – the action to be taken.

Returns:

the observation after taking the action. reward: the reward after taking the action. done: whether the episode is done. info: the extra information.

Return type:

observation

summary_records(extra_summary_info={}, summary_file_name=None, record_file_name=None)[source]

Summarize the records and save the summary information and records to the file.

Parameters:
  • extra_summary_info (dict) – the extra summary information to be added.

  • summary_file_name (str) – the name of the summary file.

  • record_file_name (str) – the name of the record file.

Return type:

Dict[str, Any]

transit_obs()[source]

Automatically Transit the observation to the next event until the next enter event comes or episode has done.

Returns:

whether the episode is done.

Return type:

done (bool)

class virne.core.environment.SolutionStepEnvironment(p_net, v_net_simulator, controller, recorder, counter, logger, config, **kwargs)[source]

Bases: BaseEnvironment

compute_reward()[source]

Compute the reward for the current Virtual Network.

get_observation()[source]

Get the observation for the current Virtual Network.

step(solution)[source]

Step the environment with the solution.

Parameters:

solution (Solution) – the solution to be deployed.

Returns:

the observation of the environment. reward (float): the reward of the step. done (bool): whether the episode is done. info (dict): the information of the step.

Return type:

observation (dict)

class virne.core.environment.JointPRStepEnvironment(p_net, v_net_simulator, controller, recorder, counter, logger, config, **kwargs)[source]

Bases: BaseEnvironment

compute_reward()[source]

Compute the reward of the step.

property curr_v_node_id

Get the current virtual node id to be placed.

get_observation()[source]

Get the observation of the environment.

property last_placed_v_node_id

Get the last placed virtual node id.

step(p_node_id)[source]

Step the environment with the solution.

Parameters:

p_node_id (int) – the physical node id to be deployed.

Returns:

the observation of the environment. reward (float): the reward of the step. done (bool): whether the episode is done. info (dict): the information of the step.

Return type:

observation (dict)

class virne.core.recorder.Recorder(counter, config)[source]

Bases: object

Record the environment’s states and solutions’ information during the deployment process.

Variables:
  • counter (Counter) – the counter of the environment.

  • summary_dir (str) – the directory to save the summary of the records.

  • save_dir (str) – the directory to save the records.

  • if_temp_save_records (bool) – whether to save the records temporarily.

  • record_dir (str) – the directory to save the records.

  • curr_record (dict) – the current record.

  • memory (list) – the memory of the records.

  • v_net_event_dict (dict) – for querying the record of v_net.

  • p_net_nodes_for_v_net_dict (dict) – for querying the record of p_net.

  • state (dict) – the state of the environment.

add_info(info_dict, **kwargs)[source]

Add information to the current record.

Parameters:

info_dict (dict) – The information to be added.

Return type:

None

add_record(record, extra_info={}, **kwargs)[source]

Add a record to the memory.

Parameters:
  • record (dict) – The record to be added.

  • extra_info (dict, optional) – The extra information to be added. Defaults to {}.

  • **kwargs – The extra information to be added.

Returns:

The record added.

Return type:

dict

count(v_net, p_net, solution)[source]

Count the state of the environment, including the resource utilization of the physical network. :param v_net: The virtual network. :type v_net: VirtualNetwork :param p_net: The physical network. :type p_net: PhysicalNetwork :param solution: The solution. :type solution: Solution

Parameters:
Return type:

Dict[str, Any]

count_init_p_net_info(p_net)[source]

Count the initial information of the physical network.

Parameters:

p_net (PhysicalNetwork) – The physical network.

Return type:

None

count_state(v_net, p_net, solution)[source]

Count the state of the environment, including the resource utilization of the physical network.

Parameters:
Return type:

None

display_record(record, display_items=['result', 'v_net_id', 'v_net_cost', 'v_net_revenue', 'p_net_available_resource', 'total_revenue', 'total_cost', 'description'], extra_items=[])[source]

Display the record.

Parameters:
  • record (dict) – The record.

  • display_items (list) – The items to display.

  • extra_items (list) – The extra items to display.

Return type:

None

get_record(event_id=None, v_net_id=None)[source]

Get the record of the service function chain v_net_id.

Parameters:
  • event_id (int)

  • v_net_id (int)

get_running_p_net_nodes()[source]

Get the running physical network nodes.

reset()[source]

Reset the recorder, clear the memory and the current record.

Return type:

None

save_records(fname)[source]

Save the records to a csv file.

save_summary(summary_info, fname='summary.csv')[source]

Save the summary to a csv file.

summary_records(records)[source]

Summary the records.

temp_save_record(record)[source]

Temporarily save the record to a csv file.

update_state(info_dict)[source]

Update the state of the environment.

Parameters:

info_dict (dict) – The information to be updated.

Return type:

None

class virne.core.solution.Solution(v_net)[source]

A class representing a solution to a virtual network mapping problem.

Variables:
  • v_net_id – The ID of the virtual network being mapped.

  • v_net_lifetime – The lifetime of the virtual network being mapped.

  • v_net_arrival_time – The arrival time of the virtual network being mapped.

  • v_net_num_nodes – The number of nodes in the virtual network being mapped.

  • v_net_num_egdes – The number of edges in the virtual network being mapped.

  • result – A boolean indicating whether the virtual network has been successfully mapped.

  • node_slots (collections.OrderedDict) – A dictionary mapping node IDs to the IDs of the slots they are mapped to.

  • link_paths (collections.OrderedDict) – A dictionary mapping link IDs to the IDs of the paths they are mapped to.

  • node_slots_info (collections.OrderedDict) – A dictionary mapping node IDs to the information of the slots they are mapped to.

  • link_paths_info (collections.OrderedDict) – A dictionary mapping link IDs to the information of the paths they are mapped to.

  • v_net_cost – The total cost of the virtual network being mapped.

  • v_net_revenue – The total revenue of the virtual network being mapped.

  • v_net_demand – The total demand of the virtual network being mapped.

  • v_net_node_demand – The total demand of the nodes in the virtual network being mapped.

  • v_net_link_demand – The total demand of the links in the virtual network being mapped.

  • v_net_node_revenue – The total revenue of the nodes in the virtual network being mapped.

  • v_net_link_revenue – The total revenue of the links in the virtual network being mapped.

  • v_net_node_cost – The total cost of the nodes in the virtual network being mapped.

  • v_net_link_cost – The total cost of the links in the virtual network being mapped.

  • v_net_path_cost – The total cost of the paths in the virtual network being mapped.

  • v_net_r2c_ratio – The revenue-to-cost ratio of the virtual network being mapped.

  • v_net_time_cost – The total time cost of the virtual network being mapped.

  • v_net_time_revenue – The total time revenue of the virtual network being mapped.

  • v_net_time_rc_ratio – The time revenue-to-cost ratio of the virtual network being mapped.

  • metric_schema_version – The metric semantics used for revenue and cost.

  • failure_reason – A stable machine-readable failure category.

  • description – A string describing the solution.

  • v_net_total_hard_constraint_violation – The total violation of the solution.

  • v_net_single_step_constraint_offset – The current violation of the solution.

  • place_result – A boolean indicating whether the placement of the virtual network has been successfully mapped.

  • route_result – A boolean indicating whether the routing of the virtual network has been successfully mapped.

  • early_rejection – A boolean indicating whether the virtual network has been rejected before the mapping process.

  • revoke_times – The number of times the virtual network has been revoked.

  • selected_actions – A list of actions selected by the agent.

display()[source]

Pretty print the solution object’s attributes using the pprint module.

Return type:

None

classmethod from_v_net(v_net)[source]

Creates a new Solution object from a virtual network.

Parameters:

v_net – The virtual network being mapped.

Returns:

A new Solution object.

is_feasible()[source]

Checks if the solution is feasible.

Returns:

True if the solution is feasible, False otherwise.

Return type:

bool

reset()[source]

Resets all attributes of the Solution object to their initial state. This method is called during initialization and can be called to reuse the object.

Return type:

None

update(new_dict)[source]

Update the Solution object’s attributes from a dictionary.

Parameters:

new_dict (dict) – Dictionary of attribute names and values to update.

Return type:

None

class virne.core.counter.Counter(node_attrs_setting, link_attrs_setting, graph_attrs_setting, config)[source]
Parameters:

config (DictConfig | dict)

static calculate_r2c_ratio(revenue, cost)[source]

Calculate a numerically stable revenue-to-cost ratio.

Calculate the sum of link resource.

Parameters:

network (BaseNetwork)

calculate_sum_network_resource(network, node=True, link=True)[source]

Calculate the sum of network resource.

Parameters:
  • network (BaseNetwork) – Network

  • node (bool, optional) – Whether to calculate the sum of node resource. Defaults to True.

  • link (bool, optional) – Whether to calculate the sum of link resource. Defaults to True.

Returns:

The sum of network resource

Return type:

float

calculate_sum_node_resource(network)[source]

Calculate the sum of node resource.

Parameters:

network (BaseNetwork)

Calculate the deployment cost of current v_net according to link paths.

Parameters:
calculate_v_net_node_resource(v_net)[source]

Calculate VN node resources using the selected metric schema.

Parameters:

v_net (VirtualNetwork)

calculate_v_net_revenue(v_net, solution=None)[source]

Calculate the deployment cost of current v_net according to link paths.

Parameters:
count_partial_solution(v_net, solution)[source]

Count the revenue and cost of a partial solution

Parameters:
Returns:

The information of partial solution with revenue and cost

Return type:

dict

count_solution(v_net, solution)[source]

Count the revenue and cost of a solution

Parameters:
Returns:

The information of partial solution with revenue and cost

Return type:

dict

normalize_node_resource_value(value)[source]

Apply the configured node-resource aggregation semantics.

classmethod summary_csv(fpath)[source]

Summary the records in csv file.

Parameters:

fpath (str) – The path of csv file.

Returns:

The summary information.

Return type:

dict

static summary_records(records)[source]

Summarize the records.

Parameters:

records (Union[list, pd.DataFrame]) – The records to be summarized.

Returns:

The summary information.

Return type:

dict

class virne.core.controller.Controller(node_attrs_setting=[], link_attrs_setting=[], graph_attrs_settings=[], config={})[source]

A class that controls changes in the physical network, i.e., execute the resource allocation process

Variables:
  • all_node_attrs (list) – A list of all node attributes.

  • all_link_attrs (list) – A list of all link attributes.

  • node_resource_attrs (list) – A list of node resource attributes.

  • link_resource_attrs (list) – A list of link resource attributes.

  • link_latency_attrs (list) – A list of link latency attributes.

  • reusable (bool) – A boolean indicating if the resources can be reused.

  • matching_mathod (str) – A string indicating the matching method.

  • shortest_method (str) – A string indicating the shortest path method.

Parameters:
  • node_attrs_setting (list)

  • link_attrs_setting (list)

  • graph_attrs_settings (list)

  • config (DictConfig | dict)

bfs_deploy(v_net, p_net, sorted_v_nodes, p_initial_node_id, max_visit=100, max_depth=10, shortest_method='all_shortest', k=10)[source]

Deploy a virtual network to a physical network using BFS algorithm.

Parameters:
  • v_net (VirtualNetwork) – The virtual network.

  • p_net (PhysicalNetwork) – The physical network.

  • sorted_v_nodes (list) – The sorted virtual nodes.

  • p_initial_node_id (int) – The initial physical node id.

  • max_visit (int, optional) – The maximum number of visited nodes. Defaults to 100.

  • max_depth (int, optional) – The maximum depth of BFS. Defaults to 10.

  • shortest_method (str, optional) – The shortest path method. Defaults to ‘all_shortest’. method: [‘first_shortest’, ‘k_shortest’, ‘all_shortest’, ‘bfs_shortest’, ‘available_shortest’]

  • k (int, optional) – The number of shortest paths. Defaults to 10.

Returns:

The solution of mapping virtual network to physical network.

Return type:

Solution

construct_candidates_dict(v_net, p_net)[source]

Constructs a dictionary of candidates for each node in v_net.

Parameters:
Returns:

A dictionary mapping each node in v_net to its candidate nodes in p_net.

Return type:

candidates_dict (dict)

deploy(v_net, p_net, solution)[source]

Deploy a virtual network to a physical network with the given solution.

Parameters:
Returns:

True if deployment success, False otherwise.

Return type:

bool

deploy_with_node_slots(v_net, p_net, node_slots, solution, inplace=True, shortest_method='bfs_shortest', k_shortest=10, if_allow_constraint_violation=False)[source]

Deploy a virtual network to a physical network with specified node slots.

Parameters:
  • v_net (VirtualNetwork) – The virtual network to be deployed.

  • p_net (PhysicalNetwork) – The physical network to deploy on.

  • node_slots (dict) – A dictionary of node slots. Keys are the virtual nodes and values are the physical nodes.

  • solution (Solution) – The solution class which contains the node slots and link paths.

  • inplace (bool, optional) – Whether to operate on the original physical network or a copy. Defaults to True.

  • shortest_method (str, optional) – The method used to find the shortest path. Defaults to ‘bfs_shortest’. [‘first_shortest’, ‘k_shortest’, ‘all_shortest’, ‘bfs_shortest’, ‘available_shortest’]

  • k_shortest (int, optional) – The number of shortest paths to find. Defaults to 10.

  • if_allow_constraint_violation (bool, optional) – Whether to check the feasibility of the node slots. Defaults to True.

Returns:

True if deployment success, False otherwise.

Return type:

bool

find_candidate_nodes(v_net, p_net, v_node_id, filter=None, check_node_constraint=True, check_link_constraint=True)[source]

Find candidate nodes from physical network according to given virtual node.

Parameters:
  • v_net (VirtualNetwork) – The virtual network object.

  • p_net (PhysicalNetwork) – The physical network object.

  • v_node_id (Any) – The virtual node identifier.

  • filter (list, optional) – Physical nodes to exclude. Defaults to None.

  • check_node_constraint (bool, optional) – Whether to check node constraints. Defaults to True.

  • check_link_constraint (bool, optional) – Whether to check link constraints. Defaults to True.

Returns:

The list of candidate nodes.

Return type:

candidate_nodes (list)

find_feasible_nodes(v_net, p_net, v_node_id, node_slots)[source]

Find feasible nodes in physical network for a given virtual node.

Parameters:
  • v_net (Virtual Network) – Virtual Network

  • p_net (Physical Network) – Physical Network

  • v_node_id (int) – ID of the virtual node

  • node_slots (dict) – Dictionary of node slots, where key is virtual node id and value is physical node id

Returns:

List of feasible physical nodes ids

Return type:

feasible_nodes (list)

place_and_route(v_net, p_net, v_node_id, p_node_id, solution, shortest_method='bfs_shortest', k=1, if_allow_constraint_violation=False)[source]

Attempt to place and route the virtual node v_node_id to the physical node p_node_id in the solution solution.

Parameters:
  • v_net (VirtualNetwork) – The virtual network.

  • p_net (PhysicalNetwork) – The physical network.

  • v_node_id (int) – The virtual node ID.

  • p_node_id (int) – The physical node ID.

  • solution (Solution) – The solution.

  • shortest_method (str) – The shortest path method. Default: ‘bfs_shortest’. [‘first_shortest’, ‘k_shortest’, ‘all_shortest’, ‘bfs_shortest’, ‘available_shortest’]

  • k (int) – The number of shortest paths to find. Default: 1.

  • if_allow_constraint_violation (bool) – Whether to check the feasibility of the solution. Default: True.

Returns:

The result of the placement and routing. check_info (dict): The check info of the placement and routing.

Return type:

result (bool)

release(v_net, p_net, solution)[source]

Release resources occupied by the Virtual network of the physical network, when the virtual network leaves the physical network.

Parameters:
Returns:

True if the release is successful, False otherwise.

Return type:

bool

undo_deploy(v_net, p_net, solution)[source]

Undo the deployment of the virtual network in the physical network.

Parameters:
  • v_net (VirtualNetwork) – The virtual network.

  • p_net (PhysicalNetwork) – The physical network.

  • solution (Solution) – The solution class which contains the node slots and link paths.

Returns:

True if the undo process is successful.

Return type:

bool

undo_place_and_route(v_net, p_net, v_node_id, p_node_id, solution)[source]

Undo the place and route operation, including the place and route of the neighbors of the virtual node.

Parameters:
  • v_net (VirtualNetwork) – The virtual network.

  • p_net (PhysicalNetwork) – The physical network.

  • v_node_id (int) – The ID of a virtual node.

  • p_node_id (int) – The ID of a physical node.

  • solution (Solution) – The solution class which contains the node slots and link paths.

Returns:

True if the undo process is successful.

Return type:

bool

class virne.core.logger.Logger(config)[source]

A unified logger supporting multiple backends: console, file, wandb, tensorboard, etc.

Parameters:

config (dict | DictConfig)

Network System

class virne.system.base_system.BaseSystem(env, solver, logger, counter, controller, recorder, config)[source]

Bases: object

Parameters:

Solver Infrastructure

class virne.solver.base_solver.SolverRegistry[source]

Bases: object

Registry for solver classes. Supports registration and retrieval by name.