GC_Khalil_Gorpinich2012 module

class GC_Khalil_Gorpinich2012.BPSO(grid, NumCandidates=10, TieLines=None, fitness_ratio=1, loss_factor=0.08, verbose_logging=30)[source]

Bases: object

Binary Particle Swarm Optimization (BPSO) class for optimizing network configurations.

net

An object representing the network to be optimized.

NumCandidates

Number of candidate solutions to generate.

NumOffLines

Number of lines that can be taken out of service.

order

Optional parameter for ordering.

flagUsed

Flag indicating whether to use certain properties.

shuffled

Flag indicating whether to shuffle candidates.

verbose_logging

Logging level for debug messages.

CalculateFitness(configuration)[source]

Calculates the fitness of a candidate configuration.

Parameters:

candidate – List of selected configurations to evaluate.

Returns:

A tuple containing the fitness value and a boolean indicating if the configuration is valid.

CalculateNewPosition(candidate_idx, c1, c2, w)[source]

Calculates the new position of a candidate based on its velocity and best known positions.

Parameters:
  • candidate_idx – Index of the candidate whose position is being updated.

  • c1 – Cognitive coefficient for personal best influence.

  • c2 – Social coefficient for global best influence.

  • w – Inertia weight for velocity.

Returns:

A tuple of the new candidate position and the updated velocity.

CreateCandidateList()[source]

Creates a list of candidates and evaluates their fitness.

DefineActionSpace()[source]

Defines the action space for the optimization based on network configurations.

RandomCandidateGenerator(n=1)[source]
Solve(wmax=0.9, wmin=0.5, beta=1, maxiter=30, vmax=4, c1=2, c2=2)[source]

Solves the optimization problem using the BPSO algorithm.

Parameters:
  • wmax – Maximum inertia weight.

  • wmin – Minimum inertia weight.

  • beta – Parameter for the sigmoid function.

  • maxiter – Maximum number of iterations for the optimization.

  • vmax – Maximum velocity for the particles.

Returns:

The best global configuration found during optimization.

SortCandidates(Candidates, Loops)[source]
UpdateCandidateFitness(candidate_idx)[source]

Updates the fitness of a specific candidate and updates personal and global bests if needed.

Parameters:

candidate_idx – Index of the candidate to update.

Returns:

A boolean indicating if the candidate configuration is valid.

UpdateCandidateNewPosition(candidate_idx, w, c1, c2)[source]

Updates the position of a candidate based on the BPSO algorithm.

Parameters:
  • candidate_idx – Index of the candidate to update.

  • w – Inertia weight for velocity calculation.

  • c1 – Cognitive coefficient for personal best influence.

  • c2 – Social coefficient for global best influence.

__init__(grid, NumCandidates=10, TieLines=None, fitness_ratio=1, loss_factor=0.08, verbose_logging=30)[source]

Initializes the BPSO with the given parameters.

Parameters:
  • net – Network object for optimization.

  • NumCandidates – Number of candidate solutions.

  • order – Order for configurations, if any.

  • flagUsed – Whether to use specific properties.

  • shuffled – Whether to shuffle candidates.

  • verbose_logging – Logging level for debug messages.

config()[source]

Configures the BPSO instance by defining the action space and initializing parameters.

getConvergeceList()[source]