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:
GraphNetwork 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
- 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_link_attrs(types=None, names=None)[source]¶
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_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
- property links¶
Get the number of links.
- property num_edges¶
Get the number of links.
- property num_link_features: int¶
Get the number of link features.
- Returns:
The number of link features.
- Return type:
int
- property num_link_resource_features: int¶
Get the number of link resource features.
- Returns:
The number of link resource features.
- Return type:
int
- property num_links¶
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.
- class virne.network.physical_network.PhysicalNetwork(*args, **kwargs)[source]¶
Bases:
BaseNetworkRepresents 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:
BaseNetworkVirtualNetwork 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
- property total_link_resource_demand: float¶
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:
objectA 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)
- 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
- 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:
- 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:
- 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:
- class virne.network.attribute.BaseAttribute(name, owner, type, generative=False, **kwargs)[source]¶
Bases:
ABCAbstract 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 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]
- static get_link_attr_benchmarks(network, link_attr_types=['resource', 'extrema'])[source]¶
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]
- static get_link_sum_attr_benchmarks(network, link_attr_types=['resource', 'extrema'])[source]¶
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 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:
objectA general environment for various solvers based on heuristics and RL
- Parameters:
p_net (PhysicalNetwork)
v_net_simulator (VirtualNetworkRequestSimulator)
controller (Controller)
recorder (Recorder)
counter (Counter)
logger (Logger)
config (DictConfig)
kwargs (Any)
- 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)
- 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]
- class virne.core.environment.SolutionStepEnvironment(p_net, v_net_simulator, controller, recorder, counter, logger, config, **kwargs)[source]¶
Bases:
BaseEnvironment- 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- property curr_v_node_id¶
Get the current virtual node id to be placed.
- 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:
objectRecord 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:
v_net (VirtualNetwork)
p_net (PhysicalNetwork)
solution (Solution)
- 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:
v_net (VirtualNetwork) – The virtual network.
p_net (PhysicalNetwork) – The physical network.
solution (Solution) – The solution.
- 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
- 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
- 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_sum_link_resource(network)[source]¶
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_v_net_link_cost(v_net, solution)[source]¶
Calculate the deployment cost of current v_net according to link paths.
- Parameters:
v_net (VirtualNetwork)
solution (Solution)
- 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:
v_net (VirtualNetwork)
solution (Solution)
- count_partial_solution(v_net, solution)[source]¶
Count the revenue and cost of a partial solution
- Parameters:
v_net (VirtualNetwork) – Virtual network
solution (Solution) – Partial solution
- 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:
v_net (VirtualNetwork) – Virtual network
solution (Solution) – Solution
- 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.
- 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:
- construct_candidates_dict(v_net, p_net)[source]¶
Constructs a dictionary of candidates for each node in v_net.
- Parameters:
v_net (VirtualNetwork) – Virtual network object.
p_net (PhysicalNetwork) – Physical network object.
- 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:
v_net (VirtualNetwork) – The virtual network.
p_net (PhysicalNetwork) – The physical network.
solution (Solution) – The solution of mapping virtual network to physical network.
- 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:
v_net (VirtualNetwork) – The virtual network object.
p_net (PhysicalNetwork) – The physical network object.
solution (Solution) – The mapping solution.
- 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
Network System¶
- class virne.system.base_system.BaseSystem(env, solver, logger, counter, controller, recorder, config)[source]¶
Bases:
object- Parameters:
env (BaseEnvironment)
solver (Solver)
logger (Logger)
counter (Counter)
controller (Controller)
recorder (Recorder)
config (DictConfig)