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

AttractionPointConstraint

Extends:

ConstraintSoftConstraint → AttractionPointConstraint

Implements bias of motion in the direction of a supplied "attraction point". This constraint computes the cosine of the angle alpha between the direction of the copy attempt (from source to target pixel), and the direction from the source to the attraction point. This cosine is 1 if these directions are aligned, 0 if they are perpendicular, and 1 if they are opposite. We take the negative (so that deltaH is negative for a copy attempt in the right direction), and modify the strength of this bias using the lambda parameter. The constraint only acts on copy attempts from the cell that is responding to the field; it does not take into account the target pixel (except for its location to determine the direction of the copy attempt).

The current implementation works for torus grids as long as the grid size in each dimension is larger than a few pixels.

Automatic adding of this constraint via the conf object is currently not supported, so you will have to add this constraint using the CPM#add method.

Example:

// Build a CPM and add the constraint
let CPM = require( "path/to/build" )
let C = new CPM.CPM( [200,200], { T : 20 } )
C.add( new CPM.AttractionPointConstraint( {
	LAMBDA_ATTRACTIONPOINT : [0,100],
	ATTRACTIONPOINT: [[0,0],[100,100]],
} ) )

// We can even add a second one at a different location
C.add( new CPM.AttractionPointConstraint( {
	LAMBDA_ATTRACTIONPOINT : [0,100],
	ATTRACTIONPOINT: [50,50],
} ) )

Constructor Summary

Public Constructor
public

The constructor of an AttractionPointConstraint requires a conf object with two parameters.

Method Summary

Public Methods
public

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

public

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

Method to compute the Hamiltonian for this constraint.

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 an AttractionPointConstraint requires a conf object with two parameters.

Override:

Constraint#constructor

Params:

NameTypeAttributeDescription
conf object

parameter object for this constraint

conf.LAMBDA_ATTRACTIONPOINT PerKindNonNegative

strength of the constraint per cellkind.

conf.ATTRACTIONPOINT ArrayCoordinate

coordinate of the attraction point.

Public Methods

public confChecker() source

This method checks that all required parameters are present in the bject 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 deltaH(src_i: IndexCoordinate, tgt_i: IndexCoordinate, src_type: CellId, tgt_type: CellId): number source

Method to compute the Hamiltonian for this constraint.

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. This argument is not actually used but is given for consistency with other soft constraints; the CPM always calls this method with four arguments.

Return:

number

the change in Hamiltonian for this copy attempt and this constraint.