Connectivity_Add_Constraint: Create a Connectivity Constraint

View source: R/Connectivity.R

Connectivity_Add_ConstraintR Documentation

Create a Connectivity Constraint

Description

Connectivity_Add_Constraint creates a Connectivity Constraint in the optimization model of the form:
Target \le \sum (Condition) .
This constraint means that the parcel Target can be protected (invested) only if at least one of the parcels in Condition are protected (invested).

Usage

Connectivity_Add_Constraint(Target, Condition, Repetition = TRUE,
                                   Silence=FALSE, Env= .GlobalEnv)

Arguments

Target

A string: the name of a parcel which can only be protected (invested) only if at least one of the Condition parcels are protected (invested)

Condition

A vector of strings: the names of the parcels that if at least one of them are protected (invested), the Target can be protected (invested).

Repetition

A binary parameter: If TRUE, the Condition parcels will create a new constraint for Target. If FALSE, the Condition parcels will be added to the first existing connectivity constraint of Target, i.e. Connectivity[["Target"]][[1]]. (Default: TRUE)

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, Connectivity_Add_Constraint or Connectivity_Import_Constraint will create a list named Connectivity in the environment. When, for the first time, a connectivity constraint is added for a Target parcel, for instance named "Parcel_1", a new member named "Parcel_1" will be added to the Connectivity list, i.e. Connectivity[["Parcel_1"]].

Then, if Repetition=FALSE, whenever Connectivity_Add_Constraint or Connectivity_Import_Constraint are used for "Parcel_1", the Condition parcels will be added to the "Parcel_1"'s first connectivity constraint, i.e. Connectivity[["Parcel_1"]][[1]]. Otherwise, if Repetition=TRUE, the Condition parcels will create a new constraint for "Parcel_1", i.e. Connectivity[["Parcel_1"]][[i+1]], where i is the number of "Parcel_1"'s existing connectivity constraints.

Removing a specific connectivity constraint of a Target: Connectivity constraint i of a parcel named "Parcel_j" can be removed using the following code:

Connectivity[["Parcel_j"]][[i]]<-NULL

Removing all Connectivity constraints of a Target: Connectivity constraints of a parcel named "Parcel_j" can be removed using the following code:

Connectivity[["Parcel_j"]]<-NULL

Remove all Connectivity Constraints: All of the Connectivity constraints can be removed using the following code:

remove(Connectivity)

Value

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

See Also

Other Connectivity Constraints: Connectivity_Import_Constraint()

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

Examples

## Not run: 

Connectivity_Add_Constraint(Target= "Parcel_1", Condition= "Parcel_4",
                           Repetition=TRUE)

## This will create Connectivity[["Parcel_1"]][[1]] and
add the following constraint to the optimization model
Parcel_1 <= Parcel_4 . Now, if the code ##

Connectivity_Add_Constraint(Target= "Parcel_1", Condition= c("Parcel_2","Parcel_3"),
                            Repetition=TRUE)

## is run, Connectivity[["Parcel_1"]][[2]] will be created,
and the following constraint will be added to the optimization model
Parcel_1 <= Parcel_2 + Parcel_3 . However, if the code ##

Connectivity_Add_Constraint(Target= "Parcel_1", Condition= c("Parcel_2","Parcel_3"),
                            Repetition=FALSE)

## is run, only Connectivity[["Parcel_1"]][[1]] will be updated,
 and its existing constraint will be updated in the optimization model as
Parcel_1 <= Parcel_4 + Parcel_2 + Parcel_3 .

## End(Not run)



paymanghasemi/SiteOpt documentation built on May 18, 2024, 2:06 p.m.