Simulation Framework
The simulation module provides tools for simulating attacks and analyzing their effects on hypernetworks.
hiper.simulation.simulator
simulator.py
Defines the HypernetworkSimulator class for orchestrating attack simulations.
- class hiper.simulation.simulator.HypernetworkSimulator(simulator_id)[source]
Bases:
objectOrchestrates and manages hypernetwork attack simulations.
The simulator provides high-level functionality for running attack simulations, analyzing results, and managing multiple scenarios. It can work with both individual attacks and attack sequences.
- __init__(simulator_id)[source]
Initialize the hypernetwork simulator.
- Parameters:
simulator_id (
str) – Unique identifier for this simulator instance.
- set_hypernetwork(hypernetwork, create_backup=True)[source]
Set the target hypernetwork for simulations.
- Parameters:
hypernetwork (
Hypernetwork) – The hypernetwork to use for simulations.create_backup (
bool) – If True, creates a backup of the original state.
- Return type:
- simulate_attack(attack, restore_after=True)[source]
Simulate a single attack on the current hypernetwork.
- simulate_sequence(sequence, restore_after=True, stop_on_failure=False)[source]
Simulate an attack sequence on the current hypernetwork.
- Parameters:
sequence (
AttackSequence) – The attack sequence to simulate.restore_after (
bool) – If True, restore the hypernetwork to its originalsequence. (state after the)
stop_on_failure (
bool) – If True, stop execution when an attack fails.
- Return type:
- Returns:
Dictionary containing simulation results.
- Raises:
RuntimeError – If no hypernetwork has been set.
hiper.simulation.attack
attack.py
Defines the base Attack class and specific attack implementations.
- class hiper.simulation.attack.Attack(attack_id)[source]
Bases:
ABCAbstract base class for hypernetwork attacks.
An attack represents a single operation that can be applied to a hypernetwork, such as adding or removing nodes or hyperedges.
- __init__(attack_id)[source]
Initialize the attack with a unique identifier.
- Parameters:
attack_id (
str) – Unique identifier for this attack.
- abstractmethod execute(hypernetwork)[source]
Execute the attack on the given hypernetwork.
- Parameters:
hypernetwork (
Hypernetwork) – The target hypernetwork.- Return type:
- Returns:
True if the attack was successful, False otherwise.
- class hiper.simulation.attack.AddNodeAttack(attack_id, node_id)[source]
Bases:
AttackAttack that adds a single node to the hypernetwork.
- execute(hypernetwork)[source]
Execute the node addition attack.
- Parameters:
hypernetwork (
Hypernetwork) – The target hypernetwork.- Return type:
- Returns:
True if the node was added successfully.
- class hiper.simulation.attack.RemoveNodeAttack(attack_id, node_id)[source]
Bases:
AttackAttack that removes a single node from the hypernetwork.
- execute(hypernetwork)[source]
Execute the node removal attack.
- Parameters:
hypernetwork (
Hypernetwork) – The target hypernetwork.- Return type:
- Returns:
True if the node was removed successfully.
- class hiper.simulation.attack.AddHyperedgeAttack(attack_id, edge_id, members)[source]
Bases:
AttackAttack that adds a single hyperedge to the hypernetwork.
- execute(hypernetwork)[source]
Execute the hyperedge addition attack.
- Parameters:
hypernetwork (
Hypernetwork) – The target hypernetwork.- Return type:
- Returns:
True if the hyperedge was added successfully.
- class hiper.simulation.attack.RemoveHyperedgeAttack(attack_id, edge_id)[source]
Bases:
AttackAttack that removes a single hyperedge from the hypernetwork.
- execute(hypernetwork)[source]
Execute the hyperedge removal attack.
- Parameters:
hypernetwork (
Hypernetwork) – The target hypernetwork.- Return type:
- Returns:
True if the hyperedge was removed successfully.
hiper.simulation.sequence
sequence.py
Defines the AttackSequence class for managing multiple attacks.
- class hiper.simulation.sequence.AttackSequence(sequence_id)[source]
Bases:
objectManages and executes a sequence of attacks on a hypernetwork.
An attack sequence represents a series of operations that can be applied to a hypernetwork in order. It provides functionality to execute all attacks track results, and handle failures.
- __init__(sequence_id)[source]
Initialize the attack sequence.
- Parameters:
sequence_id (
str) – Unique identifier for this sequence.
- execute(hypernetwork, stop_on_failure=False)[source]
Execute all attacks in the sequence on the given hypernetwork.
- Parameters:
hypernetwork (
Hypernetwork) – The target hypernetwork.stop_on_failure (
bool) – If True, stop execution when an attack fails.
- Return type:
- Returns:
True if all attacks were successful, False otherwise.
- reset()[source]
Reset the sequence state to allow re-execution.
This resets both the sequence and all individual attacks.
- Return type:
- describe()[source]
Return a human-readable description of the sequence.
- Return type:
- Returns:
String description of the attack sequence.