| Type: | Package |
| Title: | Weighted and Lexicographic Goal Programming Interface |
| Version: | 0.3.1 |
| Description: | Solves goal programming problems of the weighted and lexicographic type, as well as combinations of the two, as described by Ignizio (1983) <doi:10.1016/0305-0548(83)90003-5>. Allows for a simple human-readable input describing the problem as a series of equations. Relies on the 'lpSolve' package to solve the underlying linear optimisation problem. |
| License: | GPL (≥ 3) |
| Encoding: | UTF-8 |
| Depends: | R (≥ 4.0.0) |
| Imports: | lpSolve |
| RoxygenNote: | 7.2.2 |
| Suggests: | rmarkdown, knitr, testthat (≥ 3.0.0) |
| Config/testthat/edition: | 3 |
| VignetteBuilder: | knitr |
| NeedsCompilation: | no |
| Packaged: | 2022-11-28 16:19:15 UTC; tradpa |
| Author: | David Palma [aut, cre], Richard Hodgett [ctb] |
| Maintainer: | David Palma <D.Palma@leeds.ac.uk> |
| Repository: | CRAN |
| Date/Publication: | 2022-11-29 10:30:02 UTC |
Solves a (linear) goal programming problem
Description
Given a set of equations representing goals of a linear goalprogramming problem, it finds the optimal solution.
Usage
goalp( eqs, A = NULL, m = NULL, b = NULL, w = NULL, p = NULL, varType = NULL, normW = FALSE, silent = FALSE)Arguments
eqs | Character vector describing a set of linear equations. The vectorcan either contain a single element with one equation per line,or multiple elements, each with a single equation. Equations mustbe valid R expressions (see details). |
A | Numeric matrix with the coefficients of the variables. One row perequation, one column per variable. Columns can be named accordingto the variables they correspond to. Rows can be named for theircorresponding goals. Ignored if argument |
m | Character vector with the relationship between the left andright-hand side of the goals. It can be any of |
b | Numeric vector with the values on the right hand side of thegoals. Ignored if argument |
w | Numeric matrix with the weights associated to the deviations fromeach goal. It should have as many rows as goals, andtwo columns: the first column corresponding to the weight of thepositive deviation (excess), and the second column correspondingto the weight of the negative deviation (lack).This argument is ignored if
|
p | Numeric matrix indicating the priority of each deviation undera lexicographic approach. Lower numbers represent higherpriority (e.g. from lower to higher priority: 1, 2, 3, ...).It must have as many rows as goals, and two columns.This argument is ignored if
|
varType | Named character vector. Defines the type of each variable.It can be defined as |
normW | Logical. TRUE to scale the weights by the inverse of thecorresponding right-hand size value of the goal ( |
silent | Logical. TRUE to prevent the function writing anythingto the console (or the default output). Default is FALSE. |
Details
The actual solution of the linear programming problem is found using lp_solvehttps://lpsolve.sourceforge.net/, through its R interface (the lpSolvepackage).
Argument 'eqs' defines the goals of the goal programming problemthrough easy human-readable text. When writing a constranit, all variablesmust be on the left-hand side, with only numeric values on the right-handside. Equations must be valid R expressions. Examples of valid equationsare the following:
"3*x + 2*y = 16""4*x - y = 3"
On the other hand, the following are not valid expressions:
"3*x = 16 - 2*y""4x + 1y = 5"
While optional, it is highly encouraged to provide names for each goal.The user can also provide weights and/or lexicographic priorities for thepositive (excess) and negative (lack) deviations associated to eachgoal. The following example shows how to provide this information:"Labour : 20*A + 12*B + 40*C = 1200 | 0.2 0.1 | 1# 2#Profit : 11*A + 16*B + 8*C = 1000 | 0.1 0.3 | 3# 4#Batteries: 4*A + 3*B + 6*C = 200 | 0.2 0.1 | 5# 6#"The name of the goal must be followed by a colon (:) or splitvertical bars (|). Then the goal. Then the weights associatedto the positive deviation first (excess), and the negative deviation (lack)last, separated by an empty space. Finally, the lexicographic prioritiesfor the positive (excess) and negative (lack) deviations can be providedas numbers, each followed by a hashtag, and separated by an space, inthat order. Lower values imply a higher priority, and the same prioritycan be assigned to multiple deviations. Only the equation is mandatory.If the weights are omitted, all of them are assumed to be equal to one.If the lexicographic priorities are omitted, all of them are assumed tobe equal to one.
Value
goalp object. It contains the following elements.
A: The coefficient matrix of the decision variables.It does not include the coefficients of thedeviations.m: The relationship between the left- and right-handside of the goals.b: The right-hand side of the goals.w: The weights of the deviation variables.p: The lexicographic priorities of deviationsvariables.A_: The coefficient matrix of the decision anddeviation variables.w_: The weights of the decision and deviationvariables.eqs: Text version of the goal programming problem.varType: Vector describing the type of the decisionvariables (binary, integer, or continuous).x: Optimal value of the decision variables.d: Optimal value of the deviation variables.obj: The value of the objective function (sum ofweighted deviations). If using lexicographicpriorities, the value for the objectivefunction using all deviations (i.e. ignoring thepriority) in each stage.X: The value of the decision variables for theoptimal solution in each stage of thelexicographic problem. If there are nolexicographic priorities, then a single row matrix.lp: lp object describing the solution of theunderlying linear programming problem. Seelp.object. When usinglexicographic priorities, the solution to thelast stage.solutionFound: Logical taking value TRUE if asolution was found, FALSE otherwise.
: msg: Formats and prints a message to screen.
Description
Message function
Usage
msg(...)Arguments
... | A series of objects (usually strings and numbers) to concatenateand print to screen. |
new_goalp: Creates a new goalp object
Description
Constructor of goalp object
Usage
new_goalp(lp, A, m, b, w, p, varType, X, obj, eqs)Arguments
lp | lp object. The solution of the underlying linear program. |
A | Numeric matrix with goals coefficients. Only for originalvariables. Rows and columns must be named. |
m | Character vector containg the relation between Ax and b. Eachelement can be |
b | Numeric vector with the right hand side of the goals. |
w | Numeric matrix (nC x 2) with the weights of each deviation. |
p | Numeric matrix containing the priorities of each deviationvariable for lexicographic goal programming. Lower numbers implyhigher priority. |
varType | Character vector describing the type of the originalvariables, as either "b", "i", or "c". |
X | Numeric matrix with the value of the (decision) variables ineach iteration of the lexicographic optimisation. |
obj | Numeric vector with the value of the objective function ineach iteration of the lexicographic optimisation. |
eqs | Character vector with the human-readable formulation of theproblem. Generated automatically from A, b and w if not provided. |
Details
It doesn't do any checks, but it does generate objects
x: Vector with the optimal value of decision variables.d: Matrix with the optimal value of the deviations.solutionFound: TRUE if a solution was found, FALSE otherwise.
Value
A goalp object.
Parses text describing goal programming problem.
Description
Given a character vector describing a series of linear equations, it parsesthem into anA numerical matrix describing the variables coefficientin the left hand size, ab numerical vector with values on the righthand size, and anm character vector indicating the relation betweenthe left and right hand side (=, ==, <=, >=, <, >).
Usage
parseGoal(eqs)Arguments
eqs | Character vector describing a set of linear equations. The vectorcan either contain a single element with one equation per line,or multiple elements, each with a single equation. Equations mustbe valid R expressions (see details). |
Details
This function can only parse linear equations. All variables must be on theleft-hand side, with only numeric values on the right-hand side. Equationsmust be valid R expressions. Examples of valid equations are the following:
"3*x + 2*y = 16""4*x - y = 3"
The following are not valid expressions:
"3*x = 16 - 2*y""4x + 1y = 5"
Signs= and== are considered equivalent, and the first willbe replaced by the second after parsing.
Optionally, names, weights and lexicographic priorities can be provided foreach goal (equation) using the following format:"Labour : 20*A + 12*B + 40*C = 1200 | 0.2 0.1 | 1# 2#Profit : 11*A + 16*B + 8*C = 1000 | 0.1 0.3 | 3# 4#Batteries: 4*A + 3*B + 6*C = 200 | 0.2 0.1 | 5# 6#"The name of the goal must be followed by a colon (:) orvertical bars (|). Then the goal. Then the weights associatedto the negative deviation first (lack), and the positive deviation (excess)last, separated by an empty space. Finally, the lexicographic prioritiesfor the negative (lack) and positive (excess) deviations can be providedas numbers, each followed by a hashtag (#), and separated by anspace, in that order. Lower values imply a higher priority, and the samepriority can be assigned to multiple deviations. Only the equation ismandatory. If the weights are omitted, all of them are assumed to beequal to one for equations with the= sign. If the equation isactually an inequality with>=, then the default positive (excess)deviation weight is zero. If<=, then the default negative (lack)deviation is zero. If the lexicographic priorities are omitted, all of themare assumed to be equal to one for equations, but for inequalities>=the positive (excess) deviation is given a priority of +Inf (i.e. it willnever be minimised), and for inequalities<= the negative (lack)deviation is given a default priority of +Inf (i.e. it will never beminimised).
Value
List with five elements.
A: Numeric matrix with the coefficients of thevariables. One row per equation, one column pervariable. Columns are named according to thevariables they represent. Rows are named for eachequation, if a name for them was provided.b: Numeric vector with the values on the righthand side of the equations.m: Character vector with as many elements asequations. Each element is one of=, ==, <=, >=, <, >.w: Numeric matrix with the weights associated tothe deviations of each goal. Each rowcorresponds to a goal. The first columncorresponds to the positive deviation (excess)and the second column to the negative deviation(lack).p: Numeric matrix with the lexicographic priorityassociated to each goal. Lower valuesrepresent higher priority. Each row correspondsto a goal. The first column correspondsto the positive deviation (excess) and the secondcolumn to the negative deviation (lack).
: print.goalp: Prints a summary of a goalp object to screen.
Description
Prints a human-readable formulation of a goal programming problem.
Usage
## S3 method for class 'goalp'print(x, ...)Arguments
x | A goalp object. |
... | Additional arguments. Ignored. |
Value
A scalar character (i.e. a text string) with a human-readableformulation of the goal programming problem represented bygoalp objectx. This can be edited and used as an inputtogoalp, if modifications to the goal programming problemare required.
Solves a weighted Linear Goal Programming problem
Description
Does not perform any check. It receives set of matrices and vectorsdescribing the original problem, and expands them adding thecorresponding deviations. It omits deviations with weight equal to NA.
Usage
solveGP(A, b, w, varType, silent = FALSE)Arguments
A | Numeric matrix of coefficients of the goals (left-hand-side). |
b | Numerical vector. Right hand-side of the goals. |
w | Numerical matrix of the weights of the constrains. As many rowsas goals, and two columns (positive and negative deviations). |
varType | Character vector. Type of each variable ("i", "c" or "b" forinteger, continuous or binary, respectively). Must have asmany elements as columns in |
silent | Logical. TRUE to prevent the function writing anythingto the console (or the default output). Default is FALSE. |
Value
An lp object, generated by the lpSolve package, which in turn callsthe lp_solve C package.
: summary.goalp: Prints a summary of a goalp object to screen.
Description
Prints a summary of a goalp object to the console.
Usage
## S3 method for class 'goalp'summary(object, ...)Arguments
object | A goalp object. |
... | Additional arguments. Ignored. |
Value
No return value (NULL). Called for its side effect ofprinting a summary of a goalp object to the standard output(usually the console).
Validates the input of a goal programming problem
Description
Validates the input of a goal programming problem
Usage
validateMatrices( A, b, m, w = NULL, p = NULL, setDefaults = FALSE, silent = FALSE)Arguments
A | Numeric matrix with the coefficients of the variables. One rowper equation, one column per variable. |
b | Numeric vector with the values on the right hand side of thegoals. |
m | Character vector with the relationship between the left andright-hand side of the goals. It can be any of |
w | Numeric matrix with the weights associated to the deviationsfrom each goal. It should have as many rows as goals,and two columns: the first column corresponding to the weight ofthe positive deviation (excess), and the second columncorresponding to the weight of the negative deviation (lack). |
p | Numeric matrix indicating the priority of each deviation undera lexicographic approach. Lower numbers represent higherpriority (e.g. from lower to higher priority: 1, 2, 3, ...).It must have as many rows as goals, and two columns. |
setDefaults | Scalar logical. If TRUE, A, b, m, w, and p are filledin with default values as required. |
silent | Logical. TRUE to prevent the function writing anythingto the console (or the default output). Default is FALSE. |
: validate_goalp: A validator for goalp objects.
Description
Checks that the internals of a goalp object are consistent.
Usage
validate_goalp(gp)Arguments
gp | A goalp object. |
Value
The unmodified input invisibly.