Add_Constraint: Create a Linear Constraint

Description Usage Arguments Details Value See Also Examples

View source: R/Constraint.R

Description

Add_Constraint creates a Constraint in the optimization model of the form:

where B and S are respectively the set of initially protected and unprotected parcels, and b is the right-hand-side of the constraint.

Usage

1
2
Add_Constraint(Parcels, Coefficients, RHS,
                      Silence=FALSE, Env= .GlobalEnv)

Arguments

Parcels

A vector of strings: the name of the parcels to appear in the constraint. The package will automatically differentiate protected from unprotected parcels.

Coefficients

A vector of doubles: the respective coefficients of the Parcels.

RHS

A double: defining the right-hand-side value of the constraint.

Silence

A binary parameter: if FALSE, the function will report a summary message. If TRUE, the function will be silent. (Default: FALSE)

Env

the environment where the package should create or access variables. By default the package works in the R's Global environment. (Default: .GlobalEnv)

Details

When used for the first time, Add_Constraint will create a list named Constraints.

Each member of the list Constraints represents a linear constraint. Each constraint is stored as a list with three members: Parcels storing the names of the parcels in the constraint, Coefficients storing the respective coefficients of the parcels, and RHS storing the constraints right-hand-side value.

In other words, the information of the i'th constraint in Constraints can be accessed by
Constraints[[i]][["Parcels"]],
Constraints[[i]][["Coefficients"]],
and Constraints[[i]][["RHS"]].

This function enables adding any types of linear constraints to the optimization model.

Removing a constraint: Constraint i can be removed using the following code:

Constraints[[i]]<-NULL

Remove all Constraints: All of the Constraints stored in Constraints can be removed using the following code:

remove(Constraints)

Value

NULL (creates some variables in the environment but returns nothing)

See Also

Other Constraints: Budget_Add_Constraint(), Connectivity_Add_Constraint(), Disconnectivity_Add_Constraint()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## Not run: 

## The constraint  {Parcel_1 + Parcel_3 + Parcel_5 >= 2}
is the same as  {-Parcel_1 - Parcel_3 - Parcel_5 <= -2},
which can be created by using the following code: ##

Add_Constraint(Parcels= c("Parcel_1","Parcel_3","Parcel_5"),
               Coefficients= c(-1,-1,-1),
               RHS=-2,
               Silence=FALSE)


## End(Not run)

paymanghasemi/SiteOpt documentation built on April 8, 2021, 3:44 a.m.