Huge Collections of Software Manuals and Knowledgebase

GreatManuals.com
Huge Collections of Software Manuals and Knowledgebase

 
Home Contact Us Request to publish your help manuals Request to remove your help manuals
Introduction
» Linear Programming Library Gipals32
Library Interface
» Library Interface
» Specifying & Updating Variables
» Specifying & Updating Constraints
» Importing LP from MPS file
» Calculating
» Getting Calculation Results
» Calculation Settings
 

Specifying & Updating Constraints

NOTE: Only non-zero constraint elements should be specified.

Constraints form the matrix that has as many columns as variables and as many rows as constraints. There are three types of constraint signs available:

iint sign_Less = 0; // <= (Less or Equal)
int sign_Equal = 1; // = (Equal)
int sign_More = 2; // >= (More or Equal)

Gipals32 provides several routines to manipulate with the constraints.

int AddConstraint(double Right, // Right side of the constraint
int Sign // Sign (sign_Less, sign_Equal, sign_More)
)

This function creates a new constraint in the LP and sets its right side and sing. Sing can be one of the constants described above. The function returns the constraint’s index if succeeded and -1 if the maximum size (5,000) has been reached. The function can be used to create a new constraint only up to 5,000 constraints because behind this size the performance is dramatically slows down. For the LP with more than 5,000 constraints the procedure SetConstraintCount should be used.

DeleteConstraint(int Index)
This procedure deletes the specified constraint from LP.

void SetConstraintCount(int ACount)
This procedure creates the specified number of the constraints in the LP. This procedure works faster than function AddConstraint and provides the best performance.

best data recovery professional data recovery software send bulk sms
unerase digital pictures digital pictures recovery usb flash data recovery
drive recovery unerase usb data usb drive recovery software

int GetConstraintCount()
The function returns the number of the constraints that have been specified in the LP.

int SetConstraint(int Index, // Index of the constraint
double Right, // Right side of the constraint
int Sign // Sign (sign_Less, sign_Equal, sign_More)
)

The function setups the right side and the sign of the existing constraint Index. If the constraint doesn’t exist then returns 0.

int SetConstraintElement(int RowIndex, // Index of the constraint (row in matrix) int VarIndex, // Index of the variable (column in matrix) double Value // Value of coefficient
)

This function assigns the specified Value to the coefficient for variable VarIndex in the constraint RowIndex. In other words it setups the matrix element at position Row = RowIndex and Column = VarIndex to Value. The function returns 1 if succeeded.

The following two functions provide the best performance during the setting up the constraints. These function are recommended for middle and big LPs.

int DirectSelectConstraint(int Index // Index of the constraint
)
This function prepares the internal LP for specifying (adding elements) the constraint Index. It returns 0 if the constraint does not exist.

int DirectAddConstraintElement(int Index, // Index of the variable (column in matrix)
double Value // Variable coefficient
)

This function appends the specified non-zero element the end of the constraint selected by function DirectSelectConstraint. Index indicates the variable and Value specifies the variable coefficient. Variable indices MUST follow in an ascending order. At the result the constraint looks like sequence of pair (Index, Value).

For example the constraint (0:2.3), (5:-6.3), (6:2.0), (10:8.5) where the bold numbers are indices of all non-zero elements of the constraint can be specified by the following sequence of calls:

DirectAddConstraintElement(0, 2.3);
DirectAddConstraintElement(5, -6.3); DirectAddConstraintElement(6, 2.0); DirectAddConstraintElement(10, 8.5);

WARNING! The following calls are wrong and will result in error during the calculation:

DirectAddConstraintElement(0, 2.3);
DirectAddConstraintElement(6, 2.0); // Error - Element with index 6 must be specified after element 5.
DirectAddConstraintElement(5, -6.3); DirectAddConstraintElement(10, 8.5);

Example 3. Creating new constraints using AddConstraint and SetConstraintElement functions:

Int Index;

  1. Define a new constraint: 2*X0 – 10.2*X3 + 0.36*X8 <= 50: Index = AddConstraint(50, sign_Less); SetConstraintElement(Index, 0, 2); SetConstraintElement(Index, 3, -10.2); SetConstraintElement(Index, 8, 0.36);
  2. Define a new constraint: X1 – X4 + 15*X5 – 10*X6 = -88.5
    Index = AddConstraint(–88.5, sign_Equal); SetConstraintElement(Index, 1, 1); SetConstraintElement(Index, 4, -1);

SetConstraintElement(Index, 5, 15);
SetConstraintElement(Index, 6, -10);

Example 4. Constraints from Example 3 created using the method with the best performance setConstraintCount, SetConstraint, DirectSelectConstraint and DirectAddConstraintElement functions:

// Create two constraints
SetConstraintCount(2);

// Setup the right sides and signs of the constraints
SetConstraint(0, 50, sign_Less);
SetConstraint(1, -88.5, sign_Equal);

// Select the first constraint for direct element insertion
DirectSelectConstraint(0);
// Direct element insertion
DirectAddConstraintElement(0, 2);
DirectAddConstraintElement(3, -10.2);
DirectAddConstraintElement(8, 0.36);

// Select the second constraint for direct element insertion
DirectSelectConstraint(1);
// Direct element insertion
DirectAddConstraintElement(1, 1);
DirectAddConstraintElement(4, -1); DirectAddConstraintElement(5, 15); DirectAddConstraintElement(6, -10);

NOTE: The only methods to change existing constraints are SetConstraint and SetConstraintElement.

Home | Contact Us | Request to publish your help manuals | Request to remove your help manuals