Movatterモバイル変換


[0]ホーム

URL:


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 argumenteqs isprovided.

m

Character vector with the relationship between the left andright-hand side of the goals. It can be any of=, ==, <=, >=.= allows for positive (excess) andnegative (lack) deviations.== do not allow any deviation,enforcing fulfillment of the goal.<= automatically assignsa weight equal to zero to the negative (lack) deviation.>=automatically assigns a weight equal to zero to the positive(excess) deviation.

b

Numeric vector with the values on the right hand side of thegoals. Ignored if argumenteqs is provided.

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 ifeqs is provided.If omitted andeqs is not provided either, default weightsare dependent on the type of goal, as follows.

  • =: Positive and negative deviations are assignedequal weights of 1.

  • ==: Positive and negative deviations are assignedequal weights of NA, as these deviations will beexcluded from the problem, i.e. the goalwill be enforced.

  • >=: Positive deviation is assigned a weight of0, so it does not influence the objectivefunction (and therefore the solution to theproblem). The negative deviation is assigneda weight of 1, but if manually set to NA,then the inequality is enforced.

  • <=: Negative deviation is assigned a weight of0, so it does not influence the objectivefunction (and therefore the solution to theproblem). The positive deviation is assigneda weight of 1, but if manually set to NA,then the inequality is enforced.

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 ifeqs is provided.If omitted and not provided ineqs either, defaultpriorities are dependent on the type of goal, as follows.

  • =: Positive and negative deviations are assignedequal priority of 1.

  • ==: Positive and negative deviations are assignedequal priority of NA, as these deviations willbe excluded from the problem, i.e. thegoal will be enforced.

  • >=: Positive deviation is assigned a priority of+Inf, making it irrelevant. The negativedeviation is assigned a priority of 1.

  • <=: Negative deviation is assigned a priority of+Inf, making it irrelevant. The positivedeviation is assigned a priority of 1.

varType

Named character vector. Defines the type of each variable.It can be defined asc(x1="int", x2="cont"). Omittedvariables are assumed to be integer. Each element can beeither"continuous" (i.e. non-negative real values),"integer" (i.e. non-negative natural values), or"binary" (i.e. only take values 0 or 1). Using onlythe first letters is accepted too. If omitted, all variablesare assumed to be integer.

normW

Logical. TRUE to scale the weights by the inverse of thecorresponding right-hand size value of the goal (b).Useful to balance the relevance of all goals.Equivalent to normalising the problem sob=1 for allgoals.

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:

On the other hand, the following are not valid expressions:

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.


: 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

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:

The following are not valid expressions:

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.


: 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 inA.

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.


[8]ページ先頭

©2009-2025 Movatter.jp