import SoftConnectivityConstraint from 'Artistoo/src/hamiltonian/SoftConnectivityConstraint.js'
public class | source

SoftConnectivityConstraint

Extends:

ConstraintSoftConstraint → SoftConnectivityConstraint
this class is experimental.

This constraint encourages that cells stay 'connected' throughout any copy attempts. In contrast to the hard version of the ConnectivityConstraint, this version does not completely forbid copy attempts that break the cell connectivity, but punishes them through a positive term in the Hamiltonian.

Constructor Summary

Public Constructor
public

The constructor of the ConnectivityConstraint requires a conf object with one parameter.

Member Summary

Public Members
public set

CPM

The set CPM method attaches the CPM to the constraint.

public

Object tracking the borderpixels of each cell.

public

components: *[]

Private Members
private

Private property used by updateBorderPixels to track borders.

Method Summary

Public Methods
public

checkConnected(tgt_i: IndexCoordinate, src_type: CellId, tgt_type: CellId): number

This method checks the difference in connectivity when pixel tgt_i is changed from tgt_type to src_type.

public

This method checks that all required parameters are present in the object supplied to the constructor, and that they are of the right format.

public

Get the connected components of a set of pixels.

public

Get the connected components of the borderpixels of the current cell.

public

connectivity(components: Array, cellid: CellId): number

Compute the 'connectivity' of a cell; a number between 0 and 1.

public

deltaH(src_i: IndexCoordinate, tgt_i: IndexCoordinate, src_type: CellId, tgt_type: CellId): boolean

Method for hard constraints to compute whether the copy attempt fulfills the rule.

public

To speed things up: first check if a pixel change disrupts the local connectivity in its direct neighborhood.

public

The postSetpixListener of the ConnectivityConstraint updates the internally tracked borderpixels after every copy.

public

Update the borderpixels when pixel i changes from t_old into t_new.

Inherited Summary

From class Constraint
public get abstract

This method is actually implemented in the subclass.

public set

CPM(C: CPM)

This function attaches the relevant CPM to this constraint, so that information about this cpm can be requested from the constraint.

public get

Get the parameters of this constraint from the conf object.

public

C: CPM

CPM on which this constraint acts.

public

Configuration object for this constraint.

public abstract

cellParameter(param: string, cid: CellId): any

Get a cellid or cellkind-specific parameter for a constraint.

public abstract

The optional confChecker method should verify that all the required conf parameters are actually present in the conf object and have the right format.

public

paramOfCell(param: string, cid: CellId): any

Get a cellId specific parameter, only used if CPMEvol is used: looks whether the requested parameter is overwritten in an @object Cell and otherwise returns @function paramOfKind

public

paramOfKind(param: string, cid: CellId): any

Returns a cellKind specfic variable: Assumes that the parameter is indexable by cellkind.

From class SoftConstraint
public get

Let the CPM know that this is a soft constraint, so return 'soft'.

public abstract

deltaH(src_i: IndexCoordinate, tgt_i: IndexCoordinate, src_type: CellId, tgt_type: CellId): number

Soft constraints must have a deltaH method to compute the Hamiltonian.

Public Constructors

public constructor(conf: object) source

The constructor of the ConnectivityConstraint requires a conf object with one parameter.

Override:

Constraint#constructor

Params:

NameTypeAttributeDescription
conf object

parameter object for this constraint.

conf.LAMBDA_CONNECTIVITY PerKindBoolean

should the cellkind be connected or not?

Public Members

public set CPM source

The set CPM method attaches the CPM to the constraint.

Override:

Constraint#CPM

public borderpixelsbycell: CellObject source

Object tracking the borderpixels of each cell. This is kept up to date after every copy attempt.

public components: *[] source

Private Members

private _neighbours: Uint16Array source

Private property used by updateBorderPixels to track borders.

Public Methods

public checkConnected(tgt_i: IndexCoordinate, src_type: CellId, tgt_type: CellId): number source

This method checks the difference in connectivity when pixel tgt_i is changed from tgt_type to src_type.

Params:

NameTypeAttributeDescription
tgt_i IndexCoordinate

the pixel to change

src_type CellId

the new cell for this pixel.

tgt_type CellId

the cell the pixel belonged to previously.

Return:

number

conndiff - the difference: connectivity_after - connectivity_before.

public confChecker() source

This method checks that all required parameters are present in the object supplied to the constructor, and that they are of the right format. It throws an error when this is not the case.

Override:

Constraint#confChecker

public connectedComponentsOf(pixelobject: object): object source

Get the connected components of a set of pixels.

Params:

NameTypeAttributeDescription
pixelobject object

an object with as keys the IndexCoordinates of the pixels to check.

Return:

object

an array with an element for every connected component, which is in turn an array of the ArrayCoordinates of the pixels belonging to that component.

public connectedComponentsOfCellBorder(cellid: CellId): object source

Get the connected components of the borderpixels of the current cell.

Params:

NameTypeAttributeDescription
cellid CellId

cell to check the connected components of.

Return:

object

an array with an element for every connected component, which is in turn an array of the ArrayCoordinates of the pixels belonging to that component.

public connectivity(components: Array, cellid: CellId): number source

Compute the 'connectivity' of a cell; a number between 0 and 1. If the cell is completely connected, this returns 1. A cell split into many parts gets a connectivity approaching zero. It also matters how the cell is split: splitting the cell in two near-equal parts results in a lower connectivity than separating one pixel from the rest of the cell.

Params:

NameTypeAttributeDescription
components Array

an array of arrays (one array per connected component, in which each entry is the ArrayCoordinate of a pixel belonging to that component).

cellid CellId

the cell these components belong to.

Return:

number

connectivity of this cell.

public deltaH(src_i: IndexCoordinate, tgt_i: IndexCoordinate, src_type: CellId, tgt_type: CellId): boolean source

Method for hard constraints to compute whether the copy attempt fulfills the rule.

Override:

SoftConstraint#deltaH

Params:

NameTypeAttributeDescription
src_i IndexCoordinate

coordinate of the source pixel that tries to copy.

tgt_i IndexCoordinate

coordinate of the target pixel the source is trying to copy into.

src_type CellId

cellid of the source pixel.

tgt_type CellId

cellid of the target pixel.

Return:

boolean

whether the copy attempt satisfies the constraint.

public localConnected(tgt_i: IndexCoordinate, tgt_type: CellId): boolean source

To speed things up: first check if a pixel change disrupts the local connectivity in its direct neighborhood. If local connectivity is not disrupted, we don't have to check global connectivity at all. This currently only works in 2D, so it returns false for 3D (ensuring that connectivity is checked globally).

Params:

NameTypeAttributeDescription
tgt_i IndexCoordinate

the pixel to change

tgt_type CellId

the cell the pixel belonged to before the copy attempt.

Return:

boolean

does the local neighborhood remain connected if this pixel changes?

public postSetpixListener(i: IndexCoordinate, t_old: CellId, t: CellId) source

The postSetpixListener of the ConnectivityConstraint updates the internally tracked borderpixels after every copy.

Params:

NameTypeAttributeDescription
i IndexCoordinate

the pixel to change

t_old CellId

the cell the pixel belonged to previously

t CellId

the cell the pixel belongs to now.

public updateBorderPixels(i: IndexCoordinate, t_old: CellId, t_new: CellId) source

Update the borderpixels when pixel i changes from t_old into t_new.

Params:

NameTypeAttributeDescription
i IndexCoordinate

the pixel to change

t_old CellId

the cell the pixel belonged to previously

t_new CellId

the cell the pixel belongs to now.