indigoX
IXLocalOptimisation Class Reference

Local optimisation electron assignment algorithm. More...

#include <indigox/algorithm/electron_assignment/local_optimisation.hpp>

+ Inheritance diagram for IXLocalOptimisation:
+ Collaboration diagram for IXLocalOptimisation:

Classes

struct  Settings
 

Public Member Functions

 IXLocalOptimisation ()=delete
 
 IXLocalOptimisation (const ScoreTable &t)
 Normal constructor. More...
 
bool ApplyAssignment (size_t idx)
 Apply an optimised assignment. More...
 
graph::AssignmentGraph GetAssignmentGraph ()
 Obtain the AssignmentGraph in use by the algorithm. More...
 
size_t GetOptimalCount () const
 Get the number of optimal assignments found. More...
 
score_t GetOptimisedScore () const
 Get the optimised score. More...
 
virtual void Initalise (const Molecule &mol) override
 Initalisation method. More...
 
bool IsInitalised () const
 If the algorithm has been initalised or not. More...
 
virtual void Run () override
 Run the algorithm. More...
 

Protected Types

enum  _bool_opts
 Normal enum for algorithm option indexing. More...
 

Protected Member Functions

score_t CalculateAssignmentScore (const AssignMask &a)
 Calculate the score of an assignment. More...
 
AssignMask CalculateUpperLimit ()
 Calculates the upper score limit. More...
 
score_t CalculateVertexScore (const graph::AGVertex &v) const
 Calculate the score of a vertex. More...
 
void SetAssignment (const AssignMask &a)
 Apply an assignment to the AssignmentGraph. More...
 

Protected Attributes

graph::AssignmentGraph _g
 Assignment graph working on. More...
 
const score_t _inf
 Infinity value. More...
 
score_t _limit
 Upper limit of optimised score. More...
 
std::vector< graph::AGVertex_locs
 Locations to possibly place electrons. More...
 
int16_t _max_charge
 Maximum charge magnitude. More...
 
uint16_t _max_results
 Maximum number of results. More...
 
score_t _min_score
 Score of optimisied assignments. More...
 
_Molecule _mol
 Molecule working with. More...
 
size_t _num_e
 Number of electrons to assign. More...
 
std::bitset< __num_opts > _opts
 State of boolean options. More...
 
AssignMask _previous_mask
 Previous assignment mask. More...
 
std::vector< AssignMask_results
 Optimised assignments. More...
 
const ScoreTable_table
 Reference to the score table. More...
 

Detailed Description

Local optimisation electron assignment algorithm.

Stuff

Member Enumeration Documentation

◆ _bool_opts

enum _bool_opts
protectedinherited

Normal enum for algorithm option indexing.

Enumerator
__pairs 

Use pairs of electrons.

__charged_c 

Allow charge carbon.

__preplace 

Preassign electrons.

__initalised 

Algorithm initailised.

__num_opts 

Number of options.

Constructor & Destructor Documentation

◆ IXLocalOptimisation() [1/2]

IXLocalOptimisation ( )
delete

◆ IXLocalOptimisation() [2/2]

Normal constructor.

Sets the options of the algorithm from their state at the time of construction. Also calls the base constructor.

Parameters
tthe score table to use.

Member Function Documentation

◆ ApplyAssignment()

bool ApplyAssignment ( size_t  idx)
inherited

Apply an optimised assignment.

Applies the optimised assignment at position idx to the Molecule. Application involves determining the bond order and formal charges from the electron assignment. This method requires the algorithm the have been initalised.

Parameters
idxthe index of the assignment to apply.
Returns
if the application process was successful or not.

◆ CalculateAssignmentScore()

score_t CalculateAssignmentScore ( const AssignMask a)
protectedinherited

Calculate the score of an assignment.

Simply sets the assignment to that provided, and sums all the scores of the vertices in the AssignmentGraph. If any vertex is given a score if infinity, the summation halts and infinity is returned for the score of the assignment. This method requires the algorithm to have been initialised.

Parameters
athe assignment to calculate the score of.
Returns
the score of the assignment.
Exceptions
std::runtime_errorif the method is called before initalistion.

◆ CalculateUpperLimit()

AssignMask CalculateUpperLimit ( )
protectedinherited

Calculates the upper score limit.

The upper score limit can be used by an assignment algorithm to improve its execution time. The upper limit is calculated by iteratively generating an assignment. Iteration involves assigning electrons to the lowest scoring location, and iterating until all electrons have been assigned. Once the assignment has been generated, its score is calculated. If the score is finite, it is incremented by one. This increment allows easier handling of assignments having a score the same as the upper limit. This method requires the algorithm to have been initialised.

Returns
the assignment that generated the upper limit score.
Exceptions
std::runtime_errorif the method is called before initalistion.

◆ CalculateVertexScore()

score_t CalculateVertexScore ( const graph::AGVertex v) const
protectedinherited

Calculate the score of a vertex.

Determines the key of the vertex and returns the score of that key as present in the score table. There are three possibilities for the score returned. The first is the score present in the score table. The second is infinity. For a vertex mapped v, this occurs when charged carbons are not allowed and the formal charge on a carbon is non-zero, when the magnitude of the formal charge on the atom is larger than that allowed, and if the valency of the atom exceeds that allowed by its element. For an edge mapped v, infinty occurs when either atom of the bond exceeds its allowed valence. Finally, in either vertex or edge mapped cases, infinity is returned when the key is not found in the score table. The final possible score is zero, which occurs when v cannot be assigned any electrons and, in the vertex mapped case, when none of the neighbours of v can have electrons assigned either. This method requires the algorithm to have been initialised.

Parameters
vthe vertex to calculate the score of.
Returns
the score of the vertex.
Exceptions
std::runtime_errorif the method is called before initalistion.

◆ GetAssignmentGraph()

graph::AssignmentGraph GetAssignmentGraph ( )
inherited

Obtain the AssignmentGraph in use by the algorithm.

If the molecule assocaited with the assignment algorithm is no longer valid, or the algorithm has not been initalised, the returned shared_ptr is empty.

Returns
the AssignmentGraph used by the algorithm.

◆ GetOptimalCount()

size_t GetOptimalCount ( ) const
inlineinherited

Get the number of optimal assignments found.

Returns
the number of optimal assignments found.

◆ GetOptimisedScore()

score_t GetOptimisedScore ( ) const
inlineinherited

Get the optimised score.

If the optimisation has not been run, returned score will be infinity.

Returns
the score of the optimised electron assignment.

◆ Initalise()

virtual void Initalise ( const Molecule mol)
overridevirtual

Initalisation method.

Overrides the base class initalisation method so that location masks can be generated as part of initalisation.

Parameters
molthe Molecule to initalise with.

Reimplemented from IXElectronAssigner::AssignAlgorithm.

◆ IsInitalised()

bool IsInitalised ( ) const
inlineinherited

If the algorithm has been initalised or not.

Returns
if the initalise method has been called.

◆ Run()

virtual void Run ( )
overridevirtual

Run the algorithm.

Runs the algorithm and populates the results.

Implements IXElectronAssigner::AssignAlgorithm.

◆ SetAssignment()

void SetAssignment ( const AssignMask a)
protectedinherited

Apply an assignment to the AssignmentGraph.

Sets the assigned electron counts for all vertices in the AssignmentGraph given the provided mask. Only those assignments which have changed since the previous call to this method are actually modified. As such, all modification to the AssignmentGraph assigned counts should only go through this method. This method requires the algorithm to have been initialised.

Parameters
athe assignment to set.
Exceptions
std::runtime_errorif the method is called before initalistion.

Member Data Documentation

◆ _g

graph::AssignmentGraph _g
protectedinherited

Assignment graph working on.

◆ _inf

const score_t _inf
protectedinherited

Infinity value.

◆ _limit

score_t _limit
protectedinherited

Upper limit of optimised score.

◆ _locs

std::vector<graph::AGVertex> _locs
protectedinherited

Locations to possibly place electrons.

◆ _max_charge

int16_t _max_charge
protectedinherited

Maximum charge magnitude.

◆ _max_results

uint16_t _max_results
protectedinherited

Maximum number of results.

◆ _min_score

score_t _min_score
protectedinherited

Score of optimisied assignments.

Referenced by IXElectronAssigner::AssignAlgorithm::GetOptimisedScore().

◆ _mol

_Molecule _mol
protectedinherited

Molecule working with.

◆ _num_e

size_t _num_e
protectedinherited

Number of electrons to assign.

◆ _opts

std::bitset<__num_opts> _opts
protectedinherited

State of boolean options.

Referenced by IXElectronAssigner::AssignAlgorithm::IsInitalised().

◆ _previous_mask

AssignMask _previous_mask
protectedinherited

Previous assignment mask.

◆ _results

std::vector<AssignMask> _results
protectedinherited

Optimised assignments.

Referenced by IXElectronAssigner::AssignAlgorithm::GetOptimalCount().

◆ _table

const ScoreTable& _table
protectedinherited

Reference to the score table.


The documentation for this class was generated from the following file: