Skip to main content

ModelCenter Custom Optimization Algorithm SDK 2026 R1

OptConstraint Class

Last update: 19.06.2026

Namespace: Phoenix.Optimization

Overview

Class to hold contraint information

Inheritance

OptConstraint

Declaration

class OptConstraint

Description

Class to hold contraint information

Public Member Functions

Type Name Description
int Compare (double x, double y) Compares to values to see which violates the constraint worse.
override bool Equals (object obj) Determines whether the specified Object is equal to the current Object.
bool Equals (OptConstraint constraint) Determines whether the specified OptConstraint is equal to the current OptConstraint.
double GetConstraintViolation (double p) Given a particular value, returns an amount by which the constraint is violated.
override int GetHashCode () Serves as a hash function for OptConstraint.
OptConstraint (OptConstraint constraint) Copy constructor to create a new constraint from an existing constraint
OptConstraint (string name, double lowerBound, double upperBound) Create a new constraint with the given name, lower and upper bound.

Properties

Type Name Description
double LowerBound [get] Lower bound of the constraint or NaN if no lower bound exists.
string Name [get] Name of the constraint
double UpperBound [get] Upper bound of constraint or NaN if no upper bound exists.

Properties inherited from IVariableName

Type Name Description
string Name [get] The name of the variable

Constructor & Destructor Documentation

OptConstraint()

OptConstraint ( OptConstraint constraint)

Copy constructor to create a new constraint from an existing constraint

Parameters:

  • constraint - Constraint to be copied

OptConstraint()

OptConstraint ( string name, double lowerBound, double upperBound )

Create a new constraint with the given name, lower and upper bound. At least one bound must be specified. If a bound is not specified, it should be set to NaN.

Parameters:

  • name - Name of the constraint.
  • lowerBound - Lower bound of the constraint, or NaN if no lower constraint.
  • upperBound - Upper bound of the constraint, or NaN if no upper constraint.

Member Function Documentation

Compare

int Compare ( double x, double y )

Compares to values to see which violates the constraint worse.

Parameters:

  • x - Test value 1
  • y - Test value 2

Returns: -1 if x violates less, 0 if they violate the same, 1 if x violates it more

Equals

override bool Equals ( object obj)

Determines whether the specified Object is equal to the current Object.

Parameters:

  • obj - The object to compare with the current object.

Returns:

  • true if the specified Object is equal to the current Object; otherwise, false.

Equals

bool Equals ( OptConstraint constraint)

Determines whether the specified OptConstraint is equal to the current OptConstraint.

Parameters:

  • constraint - The OptConstraint object to compare with the current OptConstraint.

Returns:

  • true if the specified OptConstraint is equal to the current OptConstraint; otherwise, false.

GetConstraintViolation

double GetConstraintViolation ( double p)

Given a particular value, returns an amount by which the constraint is violated. If the constraint is not violated, returns 0. If it is violated, always returns a positive value.

Parameters:

  • p - The value to test

Returns:

  • The value of the constraint violation

GetHashCode

override int GetHashCode ( )

Serves as a hash function for OptConstraint.

Returns:

  • A hash code for the current OptConstraint.

operator!=

static bool operator!= ( OptConstraint a, OptConstraint b )

Determines whether the specified OptConstraint instances are considered not equal.

Parameters:

  • a - The first OptConstraint to compare.
  • b - The second OptConstraint to compare.

Returns:

  • true if the OptConstraints are not considered equal; otherwise, false.

operator==

static bool operator== ( OptConstraint a, OptConstraint b )

Determines whether the specified OptConstraint instances are considered equal.

Parameters:

  • a - The first OptConstraint to compare.
  • b - The second OptConstraint to compare.

Returns:

  • true if the OptConstraints are considered equal; otherwise, false.

LowerBound

double LowerBound

Lower bound of the constraint or NaN if no lower bound exists.

Name

string Name

Name of the constraint

Implements IVariableName.

UpperBound

double UpperBound

Upper bound of constraint or NaN if no upper bound exists.

Property Documentation

LowerBound

double LowerBound

Lower bound of the constraint or NaN if no lower bound exists.

Name

string Name

Name of the constraint

Implements IVariableName.

UpperBound

double UpperBound

Upper bound of constraint or NaN if no upper bound exists.

Connect with Ansys