Title: | R Interface to 'MiniZinc' |
---|---|
Description: | Constraint optimization, or constraint programming, is the name given to identifying feasible solutions out of a very large set of candidates, where the problem can be modeled in terms of arbitrary constraints. 'MiniZinc' is a free and open-source constraint modeling language. Constraint satisfaction and discrete optimization problems can be formulated in a high-level modeling language. Models are compiled into an intermediate representation that is understood by a wide range of solvers. 'MiniZinc' itself provides several solvers, for instance 'GeCode'. R users can use the package to solve constraint programming problems without using 'MiniZinc' directly, modify existing 'MiniZinc' models and also create their own models. |
Authors: | Akshit Achara, Lars Kotthoff, Hans W. Borchers, Guido Tack |
Maintainer: | Akshit Achara <[email protected]> |
License: | Mozilla Public License Version 2.0 |
Version: | 0.0.8 |
Built: | 2025-02-22 04:10:32 UTC |
Source: | https://github.com/acharaakshit/rminizinc |
Load the required libraries used by most of the functions and classes
Useful links:
Report bugs at https://github.com/acharaakshit/RMiniZinc/issues
Create Annotations in MiniZinc
.expVec
list of expressions
.delete_flag
used to delete items
.expVec
list of expressions
.delete_flag
used to delete items
new()
constructor
Annotation$new(expVec)
expVec
vector of MiniZinc expressions
getExps()
get the list of expressions
Annotation$getExps()
setExps()
set the list of expressions
Annotation$setExps(expVec)
expVec
list of expressions to be set
c_str()
get the MiniZinc expression
Annotation$c_str()
getDeleteFlag()
delete flag for internal use
Annotation$getDeleteFlag()
delete()
delete the assignment item
Annotation$delete()
clone()
The objects of this class are cloneable with this method.
Annotation$clone(deep = FALSE)
deep
Whether to make a deep clone.
Create an array in MiniZinc
rminizinc::Expression
-> Array
.exprVec
vector of value expressions
.dims
vector of dimension expressions
.delete_flag
used to delete items
.exprVec
vector of value expressions
.dims
vector of dimension expressions
.delete_flag
used to delete items
new()
constructor for an int literal
Array$new(exprVec, dimranges = NULL)
exprVec
list of expressions in the array
dimranges
list of min and max index of each dimension
ndims()
get the number of dimensions
Array$ndims()
getMinIndex()
get the minimum index of dimension i
Array$getMinIndex(i)
i
ith dimension
getMaxIndex()
get the maximum index of dimension i
Array$getMaxIndex(i)
i
ith dimension
setMinIndex()
set the minimum index of dimension i
Array$setMinIndex(i, minIndex)
i
dimension number
minIndex
integer for min index
setMaxIndex()
set the maximum index of dimension i
Array$setMaxIndex(i, maxIndex)
i
dimension number
maxIndex
integer for max index
getVal()
get the ith element from vector
Array$getVal(i)
i
index
setVal()
set the ith element from vector
Array$setVal(i, val)
i
index
val
value of expression to be set
c_str()
return the MiniZinc representation
Array$c_str()
getDeleteFlag()
delete flag for internal use
Array$getDeleteFlag()
delete()
delete the assignment item
Array$delete()
clone()
The objects of this class are cloneable with this method.
Array$clone(deep = FALSE)
deep
Whether to make a deep clone.
newArray = Array$new(exprVec = c(Int$new(1), Int$new(2))) newArray$c_str()
newArray = Array$new(exprVec = c(Int$new(1), Int$new(2))) newArray$c_str()
Create ArrayAccess elements in MiniZinc
rminizinc::Expression
-> ArrayAccess
.v
the id/value of array
.args
arguments of the array
.delete_flag
used to delete items
.v
the id/value of array
.args
arguments of the array
.delete_flag
used to delete items
new()
constructor
ArrayAccess$new(v, args)
v
the value/identifier of variable decl
args
the array indices
getV()
get the array access value
ArrayAccess$getV()
setV()
set the array access value
ArrayAccess$setV(val)
val
new array access value
nargs()
get the number of arguments
ArrayAccess$nargs()
getArgs()
get the arguments
ArrayAccess$getArgs()
setArgs()
set the arguments
ArrayAccess$setArgs(val)
val
new arguments
c_str()
return the MiniZinc representation
ArrayAccess$c_str()
getDeleteFlag()
delete flag for internal use
ArrayAccess$getDeleteFlag()
delete()
delete the assignment item
ArrayAccess$delete()
clone()
The objects of this class are cloneable with this method.
ArrayAccess$clone(deep = FALSE)
deep
Whether to make a deep clone.
vDecl1 = IntSetDecl(name = "SET", kind = "par") vDecl2 = IntArrDecl(name = "profit", kind = "par", ndim = 1, ind = list(vDecl1$getId())) newArrayAccess = ArrayAccess$new(v = vDecl2$getId(), args = list(IntDecl(name = "i", kind = "par")))
vDecl1 = IntSetDecl(name = "SET", kind = "par") vDecl2 = IntArrDecl(name = "profit", kind = "par", ndim = 1, ind = list(vDecl1$getId())) newArrayAccess = ArrayAccess$new(v = vDecl2$getId(), args = list(IntDecl(name = "i", kind = "par")))
Declare a n-dimensional array with domain
ArrDomainDecl(name, kind, dom, ndim)
ArrDomainDecl(name, kind, dom, ndim)
name |
variable name |
kind |
variable or parameter |
dom |
domain |
ndim |
number of dimensions |
Assign values to variables in MiniZinc by creating an assignment item.
rminizinc::Item
-> AssignItem
.decl
associated declaration
.e
value to be assigned
.delete_flag
used to delete items
.decl
associated declaration
.e
value to be assigned
.delete_flag
used to delete items
new()
constructor
AssignItem$new(decl, value)
decl
declaration associated with assignment.
value
expression to be assigned.
id()
get the name of assigned variable
AssignItem$id()
getValue()
get the value
AssignItem$getValue()
setValue()
set the value
AssignItem$setValue(val)
val
value/expression to be set
getDecl()
get the associated declaration
AssignItem$getDecl()
setDecl()
set the associated declaration
AssignItem$setDecl(decl)
decl
declaration to be set
c_str()
get the MiniZinc representation
AssignItem$c_str()
getDeleteFlag()
delete flag for internal use
AssignItem$getDeleteFlag()
delete()
delete the assignment item
AssignItem$delete()
clone()
The objects of this class are cloneable with this method.
AssignItem$clone(deep = FALSE)
deep
Whether to make a deep clone.
Solve an assignment problem (Goal is to minimize the cost)
assignment(n, m, cost)
assignment(n, m, cost)
n |
number of agents |
m |
number of tasks |
cost |
m x n 2D array where each row corresponds to the cost of each task for that agent. (to be provided as 1-D vector) |
Solve an assignment problem Winston "Operations Research", page 398, swimming team example Model created by Hakan Kjellerstrand(hakank(at)bonetmail.com) See : http://www.hakank.org/minizinc/assignment2.mzn
assignment_2(rows, cols, cost)
assignment_2(rows, cols, cost)
rows |
number of columns |
cols |
number of tasks |
cost |
cost matrix (to be provided as 1-D vector) |
Create a binary operation expression possible binary operators are: "+", "-", "!=", "<->", ">=", "<=", "*", ">", "<", "->", "<-", "..", "\/", "/\", "'not'", "subset", "superset", "union", "diff", "symdiff", "intersect", "^", "div", "mod", "/", "++", "xor", "in", "="
rminizinc::Expression
-> BinOp
.lhs_exp
the left hand side expression
.rhs_exp
the right hand side expression
.op
the operator
.delete_flag
used to delete items
.lhs_exp
the left hand side expression
.rhs_exp
the right hand side expression
.op
the operator
.delete_flag
used to delete items
new()
constructor
BinOp$new(lhs, binop, rhs)
lhs
the left hand side expression
binop
the binary operator to be used
rhs
the right hand side expression
getLhs()
get the lhs expression
BinOp$getLhs()
getRhs()
get the rhs expression
BinOp$getRhs()
getOp()
get the operator
BinOp$getOp()
setOp()
set the operator
BinOp$setOp(binop)
op
binary operator to be set
setLhs()
set the lhs expression
BinOp$setLhs(e)
e
expression to set
setRhs()
set the rhs expression
BinOp$setRhs(e)
e
expression to set
c_str()
return the MiniZinc representation
BinOp$c_str()
getDeleteFlag()
delete flag for internal use
BinOp$getDeleteFlag()
delete()
delete the assignment item
BinOp$delete()
clone()
The objects of this class are cloneable with this method.
BinOp$clone(deep = FALSE)
deep
Whether to make a deep clone.
newBinOp = BinOp$new(lhs = Int$new(2), binop = "+", rhs = Int$new(5)) newBinOp$c_str() newBinOp$setLhs(Int$new(5)) newBinOp$setOp("-") newBinOp$setRhs(Int$new(2)) newBinOp$c_str()
newBinOp = BinOp$new(lhs = Int$new(2), binop = "+", rhs = Int$new(5)) newBinOp$c_str() newBinOp$setLhs(Int$new(5)) newBinOp$setOp("-") newBinOp$setRhs(Int$new(2)) newBinOp$c_str()
Create a bool in MiniZinc
rminizinc::Expression
-> Bool
.value
value
.value
value
new()
constructor
Bool$new(val)
val
boolean input
v()
get boolean value
Bool$v()
c_str()
get the MiniZinc representation
Bool$c_str()
clone()
The objects of this class are cloneable with this method.
Bool$clone(deep = FALSE)
deep
Whether to make a deep clone.
newBool = Bool$new(TRUE) newBool$c_str()
newBool = Bool$new(TRUE) newBool$c_str()
Declare a new n-dimensional array of bools
BoolArrDecl(name, kind, ind, value = NULL, ndim)
BoolArrDecl(name, kind, ind, value = NULL, ndim)
name |
variable/parameter name |
kind |
"var" or "par" |
ind |
index of the array |
value |
value (NULL by default) |
ndim |
number of dimensions of the array |
Declare a new bool
BoolDecl(name, kind, value = NULL)
BoolDecl(name, kind, value = NULL)
name |
variable/parameter name |
kind |
"var" or "par" |
value |
provide TRUE or FALSE (NULL by default) |
Get a list of bool expressions
boolExpressions(vals)
boolExpressions(vals)
vals |
vector of bool values |
Declare a new set of bool
BoolSetDecl(name, kind, value = NULL)
BoolSetDecl(name, kind, value = NULL)
name |
variable/parameter name |
kind |
"var" or "par" |
value |
provide a Set object (or NULL) |
Create function calls in MiniZinc
rminizinc::Expression
-> Call
.id
the function id
.lExp
list of expressions
.delete_flag
used to delete items
.id
the function id
.lExp
list of expressions
.delete_flag
used to delete items
new()
constructor
Call$new(fnName, args)
fnName
function name
args
the list of expressions
getName()
get the function id/string
Call$getName()
setName()
get the function id/string
Call$setName(name)
name
new function name
nargs()
get the number of arguments
Call$nargs()
getArgs()
get the expression list
Call$getArgs()
setArgs()
set the expression list
Call$setArgs(args)
args
list of expressions to be set
getArg()
get the expression based on index
Call$getArg(i)
i
index
setArg()
set argument i
Call$setArg(e, i)
e
expression
i
index
c_str()
return the MiniZinc representation
Call$c_str()
getDeleteFlag()
delete flag for internal use
Call$getDeleteFlag()
delete()
delete the assignment item
Call$delete()
clone()
The objects of this class are cloneable with this method.
Call$clone(deep = FALSE)
deep
Whether to make a deep clone.
newCall = Call$new(fnName = "sum", args = list(Int$new(2), Int$new(5))) newCall$c_str()
newCall = Call$new(fnName = "sum", args = list(Int$new(2), Int$new(5))) newCall$c_str()
Create a Comprehension in MiniZinc
rminizinc::Expression
-> Comprehension
.generators
a vector of generators
.expression
the comprehension expression
.set
TRUE if comprehension is a set
.delete_flag
used to delete items
.generators
a vector of generators
.expression
the comprehension expression
.set
TRUE if comprehension is a set
.delete_flag
used to delete items
new()
constructor
Comprehension$new(generators, body, set)
generators
generators of the expression
body
body/expression of the comprehension
set
bool to specify if comprehension is a set.
ngens()
get the number of generators
Comprehension$ngens()
getGens()
get all the generator expressions
Comprehension$getGens()
setGens()
set all the generator expressions
Comprehension$setGens(generators)
generators
list of generator expressions to be set
getGen()
get the ith generator expression
Comprehension$getGen(i)
i
index
setGen()
set the ith generator expression
Comprehension$setGen(i, expGen)
i
index
expGen
generator expression to be set
getBody()
get the expression/body
Comprehension$getBody()
setBody()
set the expression/body
Comprehension$setBody(e)
e
new expression value
isSet()
check if comprehension is a set
Comprehension$isSet()
c_str()
get the MiniZinc representation
Comprehension$c_str()
getDeleteFlag()
delete flag for internal use
Comprehension$getDeleteFlag()
delete()
delete the assignment item
Comprehension$delete()
clone()
The objects of this class are cloneable with this method.
Comprehension$clone(deep = FALSE)
deep
Whether to make a deep clone.
Describe Minizinc constraints on decision variables.
rminizinc::Item
-> ConstraintItem
.e
the constraint expression
.delete_flag
used to delete items
.e
the constraint expression
.delete_flag
used to delete items
new()
Creates a new instance of Constraint class.
ConstraintItem$new(e = NULL, mzn_str = NULL)
e
The expression for the constraint (used if e is NULL)
mzn_str
string representation of Constraint item
getExp()
get the constraint expression
ConstraintItem$getExp()
setExp()
set the constraint expression
ConstraintItem$setExp(e)
e
expression
c_str()
serialize to MiniZinc syntax
ConstraintItem$c_str()
getDeleteFlag()
delete flag for internal use
ConstraintItem$getDeleteFlag()
delete()
delete the constraint item
ConstraintItem$delete()
clone()
The objects of this class are cloneable with this method.
ConstraintItem$clone(deep = FALSE)
deep
Whether to make a deep clone.
This class represents an expression in MiniZinc.
new()
constructor
Expression$new()
clone()
The objects of this class are cloneable with this method.
Expression$clone(deep = FALSE)
deep
Whether to make a deep clone.
Delete the object everywhere from the MiniZinc model
expressionDelete(classNm, model)
expressionDelete(classNm, model)
classNm |
class of the object to delete |
model |
model to delete the object from |
Create a float in MiniZinc
rminizinc::Expression
-> Float
.value
object of class expression
.value
object of class expression
new()
constructor
Float$new(val)
val
the float value
getFloatVal()
get the float value
Float$getFloatVal()
setFloatVal()
set the float value
Float$setFloatVal(val)
val
value to be set
c_str()
get the MiniZinc representation
Float$c_str()
clone()
The objects of this class are cloneable with this method.
Float$clone(deep = FALSE)
deep
Whether to make a deep clone.
newFloat = Float$new(1.5) newFloat$c_str() newFloat$setFloatVal(newFloat$getFloatVal() + 2.5) newFloat$c_str()
newFloat = Float$new(1.5) newFloat$c_str() newFloat$setFloatVal(newFloat$getFloatVal() + 2.5) newFloat$c_str()
Declare a new n-dimensional array of float
FloatArrDecl(name, kind, ind, value = NULL, ndim)
FloatArrDecl(name, kind, ind, value = NULL, ndim)
name |
variable/parameter name |
kind |
"var" or "par" |
ind |
index of the array |
value |
value (NULL by default) |
ndim |
number of dimensions of the array |
Declare a new float
FloatDecl(name, kind, value = NULL, domain = NULL)
FloatDecl(name, kind, value = NULL, domain = NULL)
name |
variable/parameter name |
kind |
"var" or "par" |
value |
pass a numeric/double value in R (NULL by default) |
domain |
domain of the float variable (NULL by default) |
Get a list of floats expressions
floatExpressions(vals)
floatExpressions(vals)
vals |
vector of floats values |
Declare a new set of float
FloatSetDecl(name, kind, value = NULL)
FloatSetDecl(name, kind, value = NULL)
name |
variable/parameter name |
kind |
"var" or "par" |
value |
provide an FloatSetVal object (or NULL) |
float set range in MiniZinc
.min
minimum FloatVal
.max
maximum FloatVal
.min
minimum FloatVal
.max
maximum FloatVal
new()
constructor
FloatSetVal$new(fmin, fmax)
fmin
the minimum FloatVal
fmax
the maximum FloatVal
getMin()
get the minimum float value
FloatSetVal$getMin()
setMin()
set the minimum float value
FloatSetVal$setMin(val)
val
float value to be set
getMax()
get the maximum float value
FloatSetVal$getMax()
setMax()
set the maximum float value
FloatSetVal$setMax(val)
val
float value to be set
clone()
The objects of this class are cloneable with this method.
FloatSetVal$clone(deep = FALSE)
deep
Whether to make a deep clone.
create a Float Value in MiniZinc
.val
the integer value
.val
the integer value
new()
constructor
FloatVal$new(val)
val
float value to be assigned
v()
return the value
FloatVal$v()
clone()
The objects of this class are cloneable with this method.
FloatVal$clone(deep = FALSE)
deep
Whether to make a deep clone.
Create Independent functions (that are not part of any other items) in a MiniZinc model
rminizinc::Item
-> FunctionItem
.id
name of the function
.e
expression in the function
.decls
parameter declarations
.ann
annotation
.ti
return type of the function
.delete_flag
used to delete items
.id
name of the function
.e
expression in the function
.decls
parameter declarations
.ann
annotation
.ti
return type of the function
.delete_flag
used to delete items
new()
constructor
FunctionItem$new( name = NULL, decls = NULL, rt = NULL, ann = NULL, body = NULL, mzn_str = NULL )
name
name of the function
decls
variable declarations
rt
the return type ("bool par", "bool var" or other)
ann
annotation
body
body of the function
mzn_str
string representation of Function Item
name()
get the name of the function
FunctionItem$name()
getDecls()
get the list of declarations
FunctionItem$getDecls()
getBody()
get the function body
FunctionItem$getBody()
getAnn()
get the function annotation
FunctionItem$getAnn()
setDecls()
set the list of declarations
FunctionItem$setDecls(decls)
decls
list of declarations to be set
setBody()
set the function body
FunctionItem$setBody()
body
function expression to set or NULL
setAnn()
set the function annotation
FunctionItem$setAnn()
ann
annotation to be set or NULL
rtype()
get if the function is a test, predicate or a function call itself.
FunctionItem$rtype()
c_str()
get the MiniZinc representation
FunctionItem$c_str()
getDeleteFlag()
delete flag for internal use
FunctionItem$getDeleteFlag()
delete()
delete the variable item
FunctionItem$delete()
clone()
The objects of this class are cloneable with this method.
FunctionItem$clone(deep = FALSE)
deep
Whether to make a deep clone.
Create a generator in MiniZinc
rminizinc::Expression
-> Generator
.decls
variable declarations
.in
in expression
where
where expression
.delete_flag
used to delete items
.decls
variable declarations
.in
in expression
where
where expression
.delete_flag
used to delete items
new()
constructor
Generator$new(decls, IN = NULL, where = NULL)
decls
list of variable declarations
IN
the in expression of generator
where
the where expression of generator
getIn()
get the in expression
Generator$getIn()
setIn()
set the in expression
Generator$setIn(expIn)
expIn
expression to be set
getWhere()
get the where expression
Generator$getWhere()
setWhere()
get the where expression
Generator$setWhere(expWhere)
expWhere
where expression (or NULL)
getDecl()
get the ith declaration
Generator$getDecl(i)
i
index
setDecl()
get the ith declaration
Generator$setDecl(i, decl)
i
index
decl
declaration to be set
c_str()
get the MiniZinc representation
Generator$c_str()
getDeleteFlag()
delete flag for internal use
Generator$getDeleteFlag()
delete()
delete the assignment item
Generator$delete()
clone()
The objects of this class are cloneable with this method.
Generator$clone(deep = FALSE)
deep
Whether to make a deep clone.
newGen = Generator$new(IN = IntSetDecl(name = "SET", kind = "par"), decls = list(IntDecl(name = "i", kind = "par")))
newGen = Generator$new(IN = IntSetDecl(name = "SET", kind = "par"), decls = list(IntDecl(name = "i", kind = "par")))
Get the values of the missing parameters
get_missing_pars(model)
get_missing_pars(model)
model |
object of Model class |
Given the return value of 'mzn_parse()', it creates a model in R using the API mirror
getRModel(mznParseList)
getRModel(mznParseList)
mznParseList |
list input |
Helper function to initialise the type.
getType(type_str, kind)
getType(type_str, kind)
type_str |
type string returned by 'parse_mzn()'. |
kind |
par or var |
helper function to search the through a model for an expression and return the object if found
helperDeleteExpression(classNm)
helperDeleteExpression(classNm)
classNm |
name of the object class |
Helper function to search the through a model for an item and return the object if found
helperDeleteItem(classNm)
helperDeleteItem(classNm)
classNm |
name of the object class |
Create a new Id in MiniZinc
rminizinc::Expression
-> Id
.id
the string identifier
.delete_flag
used to delete items
.id
the string identifier
.delete_flag
used to delete items
new()
constructor
Id$new(id)
id
id to be created
getName()
get the string identifier
Id$getName()
setName()
set the string identifier
Id$setName(name)
name
string name to set
c_str()
return the MiniZinc representation
Id$c_str()
getDeleteFlag()
delete flag for internal use
Id$getDeleteFlag()
delete()
delete the assignment item
Id$delete()
clone()
The objects of this class are cloneable with this method.
Id$clone(deep = FALSE)
deep
Whether to make a deep clone.
Include external mzn files in your model.
rminizinc::Item
-> IncludeItem
.id
name of mzn file
.delete_flag
used to delete items
.id
name of mzn file
.delete_flag
used to delete items
new()
constructor
IncludeItem$new(name = NULL, mzn_str = NULL)
name
name of the file to include
mzn_str
string representation of Include Item get file name set the file name
getmznName()
IncludeItem$getmznName()
setmznName()
IncludeItem$setmznName(name)
name
name of file
c_str()
get the MiniZinc representation
IncludeItem$c_str()
getDeleteFlag()
delete flag for internal use
IncludeItem$getDeleteFlag()
delete()
delete the include item
IncludeItem$delete()
clone()
The objects of this class are cloneable with this method.
IncludeItem$clone(deep = FALSE)
deep
Whether to make a deep clone.
Recursive helper function for initilizing expression classes
initExpression(pList)
initExpression(pList)
pList |
list from mzn_parse to initialise objects |
Initialize all the R6 objects using the list returned by 'mzn_parse()' to create exactly the same structure in R.
initItem(parsedList)
initItem(parsedList)
parsedList |
list returned by 'mzn_parse()' |
Create an integer in MiniZinc
rminizinc::Expression
-> Int
.value
object of class expression
.value
object of class expression
new()
constructor
Int$new(val)
val
the value of the integer
getIntVal()
get the IntVal value
Int$getIntVal()
setIntVal()
set the IntVal value
Int$setIntVal(val)
val
value to be set
c_str()
get the MiniZinc representation
Int$c_str()
clone()
The objects of this class are cloneable with this method.
Int$clone(deep = FALSE)
deep
Whether to make a deep clone.
newInt = Int$new(10) newInt$c_str() newInt$setIntVal(newInt$getIntVal() + 20) newInt$c_str()
newInt = Int$new(10) newInt$c_str() newInt$setIntVal(newInt$getIntVal() + 20) newInt$c_str()
Declare a new n-dimensional array of int
IntArrDecl(name, kind, ind, value = NULL, ndim)
IntArrDecl(name, kind, ind, value = NULL, ndim)
name |
variable/parameter name |
kind |
"var" or "par" |
ind |
index of the array |
value |
Array Object (NULL by default) |
ndim |
number of dimensions of the array |
Declare a new int
IntDecl(name, kind, value = NULL, domain = NULL)
IntDecl(name, kind, value = NULL, domain = NULL)
name |
variable/parameter name |
kind |
"var" or "par" |
value |
pass a numeric/integer value in R (NULL by default) |
domain |
domain of the int variable (NULL by default) |
Get a list of integer expressions
intExpressions(vals)
intExpressions(vals)
vals |
vector of integer values |
Declare a new set of int
IntSetDecl(name, kind, value = NULL)
IntSetDecl(name, kind, value = NULL)
name |
variable/parameter name |
kind |
"var" or "par" |
value |
provide an IntSetVal object (NULL by default) |
integer range set value in MiniZinc
.min
minimum value of integer range
.max
maximum value of integer range
.min
minimum value of integer range
.max
maximum value of integer range
new()
constructor
IntSetVal$new(imin, imax)
imin
minimum int value
imax
maximum int value
getMin()
get the minimum IntVal
IntSetVal$getMin()
setMin()
set the minimum IntVal
IntSetVal$setMin(val)
val
int value to be set
getMax()
get the maximum IntVal
IntSetVal$getMax()
setMax()
set the maximum IntVal
IntSetVal$setMax(val)
val
int value to be set
clone()
The objects of this class are cloneable with this method.
IntSetVal$clone(deep = FALSE)
deep
Whether to make a deep clone.
create an Integer Value in MiniZinc
.val
the integer value
.val
the integer value
new()
constructor
IntVal$new(val)
val
int value to be assigned
v()
return the value
IntVal$v()
clone()
The objects of this class are cloneable with this method.
IntVal$clone(deep = FALSE)
deep
Whether to make a deep clone.
Create if-then-else expressions in MiniZinc
rminizinc::Expression
-> Ite
.ifs
list of if expressions
.thens
list of corresponding then expressions
.else
else expression
.delete_flag
used to delete items
.ifs
list of if expressions
.thens
list of corresponding then expressions
.else
else expression
.delete_flag
used to delete items
new()
constructor
Ite$new(ifs, thens, Else)
ifs
list of if expressions
thens
list of corresponding then expressions
Else
else expression
getIfs()
get the if expression list
Ite$getIfs()
getThens()
get the then expression list
Ite$getThens()
setIfsThens()
set the if and then expression list
Ite$setIfsThens(ifs, thens)
ifs
expression list to be set
thens
expression list to be set
getIf()
get the ith if expression
Ite$getIf(i)
i
index
setIf()
set the ith if expression
Ite$setIf(i, expIf)
i
index
expIf
if expression to be set
getThen()
get the ith then expression
Ite$getThen(i)
i
index
setThen()
set the ith then expression
Ite$setThen(i, expThen)
i
index
expThen
then expression to be set
getElse()
get the else expression
Ite$getElse()
setElse()
get the else expression
Ite$setElse(expElse)
expElse
else expression to be set
c_str()
get the MiniZinc representation
Ite$c_str()
getDeleteFlag()
delete flag for internal use
Ite$getDeleteFlag()
delete()
delete the assignment item
Ite$delete()
clone()
The objects of this class are cloneable with this method.
Ite$clone(deep = FALSE)
deep
Whether to make a deep clone.
Abstract class for all items in MiniZinc grammar
new()
constructor
Item$new()
clone()
The objects of this class are cloneable with this method.
Item$clone(deep = FALSE)
deep
Whether to make a deep clone.
Find the object in the model and delete it.
itemDelete(classNm, model)
itemDelete(classNm, model)
classNm |
object to be deleted |
model |
model to delete the object from |
Given an object to delete and expression object, delete all the embedded expression objects that are identical
iterExpression(classNm, expObj)
iterExpression(classNm, expObj)
classNm |
class name of the object to delete |
expObj |
expression object to iterate through |
Find the expressions in the items and delete them if matched
iterItem(mod, classNm)
iterItem(mod, classNm)
mod |
model to be searched |
classNm |
class name of the object to be deleted |
Solve a simple knapsack problem (Goal is to maximize the profit)
knapsack(n, capacity, profit, size)
knapsack(n, capacity, profit, size)
n |
number of items |
capacity |
total capacity of carrying weight |
profit |
profit corresponding to each item |
size |
weight/size of each item |
Create let expression in MiniZinc
rminizinc::Expression
-> Let
.decl
list of local declarations
.in
body of the let
.delete_flag
used to delete items
.decl
list of local declarations
.in
body of the let
.delete_flag
used to delete items
new()
constructor
Let$new(let, body)
let
list of local declaration items and/or constraint items
body
body of the let
getLets()
access list of declaration items and/or constraint items
Let$getLets()
setLets()
set list of declaration items and/or constraint items
Let$setLets(letList)
letList
list of declaration items and/or constraint items to be set
getLet()
access declaration item and/or constraint item i
Let$getLet(i)
i
index of let declaration item and/or constraint item to be accessed
setLet()
set list of declaration item and/or constraint item i
Let$setLet(let)
let
declaration item and/or constraint item to be set
getBody()
get the body
Let$getBody()
setBody()
set the body
Let$setBody(expBody)
expBody
expression to be set for body
c_str()
get the MiniZinc representation
Let$c_str()
getDeleteFlag()
delete flag for internal use
Let$getDeleteFlag()
delete()
delete the assignment item
Let$delete()
clone()
The objects of this class are cloneable with this method.
Let$clone(deep = FALSE)
deep
Whether to make a deep clone.
Absolute path of the libminizinc library
LIBMINIZINC_PATH
LIBMINIZINC_PATH
A string containing linker flag
Solve a magic series problem in MiniZinc Model created by Hakan Kjellerstrand(hakank(at)bonetmail.com) See : http://www.hakank.org/minizinc/magic_series.mzn
magic_series(n)
magic_series(n)
n |
order of magic square |
Solve a magic squares problem in MiniZinc Model created by Hakan Kjellerstrand(hakank(at)bonetmail.com) See : http://www.hakank.org/minizinc/magic_square.mzn
magic_square(n)
magic_square(n)
n |
order of magic square |
This class will take all the objects required to create a MiniZinc model.
.items
list of items in the model
.items
list of items in the model
new()
create a new instance of model class
Model$new(items)
items
all items of the model
getItems()
get all the items
Model$getItems()
setItems()
set all the items
Model$setItems(items)
items
items to be set
getItem()
get the item using index
Model$getItem(i)
i
index
setItem()
set the item using index
Model$setItem(i, item)
i
index
item
item to be set
addItem()
add item to the model
Model$addItem(item)
item
item to add
nitems()
get the number of items
Model$nitems()
mzn_string()
get the string representation of the model
Model$mzn_string()
clone()
The objects of this class are cloneable with this method.
Model$clone(deep = FALSE)
deep
Whether to make a deep clone.
evaluates the MiniZinc model
mzn_eval( lib_path = "", r_model = NULL, mzn_path = "", model_string = "", solver = "org.gecode.gecode", dzn_path = "", all_solutions = TRUE, time_limit = 300000L, other_cl_options = NULL )
mzn_eval( lib_path = "", r_model = NULL, mzn_path = "", model_string = "", solver = "org.gecode.gecode", dzn_path = "", all_solutions = TRUE, time_limit = 300000L, other_cl_options = NULL )
lib_path |
the path of the library where the standard library files are present (the parent directory of the std directory). |
r_model |
R6 Model object |
mzn_path |
path of the mzn file to be solved |
model_string |
model string to be solved. |
solver |
the name of the solver to use.(default: Gecode) |
dzn_path |
path of the datafile to be used. |
all_solutions |
bool to specify if all solutions are specified.(default: true) |
time_limit |
stop after <time_limit> milliseconds. (default: 300000ms – 5 mins) |
other_cl_options |
other command line options/flags that you want to provide 1. Please provide as a character/string vector with each element as a flag 2. Incorrect flags or incorrect commands will throw errors. 3. Changing the default solution output options will result in parsing errors and the solutions will not be parsed correctly to R but the solution string will be returned. |
parses the MiniZinc syntax into R objects
mzn_parse(model_string = "", mzn_path = "", include_path = NULL)
mzn_parse(model_string = "", mzn_path = "", include_path = NULL)
model_string |
string representation of the MiniZinc model. |
mzn_path |
the path of model mzn. |
include_path |
path of the included mzn in the model if it exists. |
simple production planning problem taken from https://github.com/MiniZinc/minizinc-examples Goal is to maximize the profit
production_planning( nproducts, profit, pnames, nresources, capacity, rnames, consumption )
production_planning( nproducts, profit, pnames, nresources, capacity, rnames, consumption )
nproducts |
number of different products |
profit |
profit for each product (1-D vector) |
pnames |
names of each product (1-D vector) |
nresources |
number of resources |
capacity |
amount of each resource available (1-D vector) |
rnames |
names of each resource (1-D vector) |
consumption |
units of each resource required to produce 1 unit of product (2-D vector to be provided as 1-D vector) |
Absolute path of project directory
PROJECT_DIRECTORY
PROJECT_DIRECTORY
A string containing absolute path of the project directory
Create a set in MiniZinc
rminizinc::Expression
-> Set
.setVal
the value of the set
.isv
the integer range set
.fsv
the float range set
.et
empty set
.delete_flag
used to delete items
.setVal
the value of the set
.isv
the integer range set
.fsv
the float range set
.et
empty set
.delete_flag
used to delete items
new()
constuctor
Set$new(val = NULL, empty_set = FALSE)
val
the set value
empty_set
bool to specify is set is empty(FALSE by default)
getSetVec()
get the set expression
Set$getSetVec()
setSetVec()
set the set expression
Set$setSetVec(val)
val
list of expressions
isEmpty()
is the set empty
Set$isEmpty()
makeEmpty()
make the set empty
Set$makeEmpty()
getIsv()
return the integer set range
Set$getIsv()
setIsv()
set the integer set range
Set$setIsv(val)
val
integer set range
getFsv()
get the float set range
Set$getFsv()
setFsv()
set the float set range
Set$setFsv(val)
val
float set range
c_str()
get the MiniZinc representation
Set$c_str()
getDeleteFlag()
delete flag for internal use
Set$getDeleteFlag()
delete()
delete the assignment item
Set$delete()
clone()
The objects of this class are cloneable with this method.
Set$clone(deep = FALSE)
deep
Whether to make a deep clone.
newIntSet = Set$new(val = IntSetVal$new(1,5)) newIntSet$c_str() newIntSet$setIsv(IntSetVal$new(2,6)) newIntSet$c_str() newFloatSet = Set$new(val = FloatSetVal$new(1.1,5.1)) newFloatSet$c_str() newFloatSet$setFsv(FloatSetVal$new(1.2,4.1))
newIntSet = Set$new(val = IntSetVal$new(1,5)) newIntSet$c_str() newIntSet$setIsv(IntSetVal$new(2,6)) newIntSet$c_str() newFloatSet = Set$new(val = FloatSetVal$new(1.1,5.1)) newFloatSet$c_str() newFloatSet$setFsv(FloatSetVal$new(1.2,4.1))
Assign values to parameters which don't have a value assigned yet.
set_params(model, modData)
set_params(model, modData)
model |
Model object |
modData |
list of the value objects to be assigned |
can parse the JSON solution of a model to return a list output
sol_parse(solutionString)
sol_parse(solutionString)
solutionString |
solution of the model as a string representation |
specify whether the optimization problem is a satisfaction, minimization or maximization problem and/or expression to maximize/minnimize and/or annotation
rminizinc::Item
-> SolveItem
.e
the expression to maximize or minimize
.st
the solve type
.ann
annotation of the solve type
.delete_flag
used to delete items
.e
the expression to maximize or minimize
.st
the solve type
.ann
annotation of the solve type
.delete_flag
used to delete items
new()
create an instance of specify_problem class
SolveItem$new(solve_type = NULL, e = NULL, ann = NULL, mzn_str = NULL)
solve_type
satisfy, minimize or maximize
e
expression to minimize or maximize
ann
annotation
mzn_str
string representation of Solve Item
getExp()
get the expression (or NULL)
SolveItem$getExp()
getAnn()
get the annotation (or NULL)
SolveItem$getAnn()
setExp()
set the expression
SolveItem$setExp(e)
e
expression
setAnn()
set the annotation
SolveItem$setAnn(ann)
ann
annotation or Null
getSt()
get the solve type/objective
SolveItem$getSt()
setSt()
set the solve type/objective
SolveItem$setSt(objective)
objective
solve type
c_str()
to string method
SolveItem$c_str()
getDeleteFlag()
delete flag for internal use
SolveItem$getDeleteFlag()
delete()
delete the variable item
SolveItem$delete()
clone()
The objects of this class are cloneable with this method.
SolveItem$clone(deep = FALSE)
deep
Whether to make a deep clone.
Absolute path of the solver executable directory
SOLVER_BIN
SOLVER_BIN
A string containing path of solver executable directory
Create a string in MiniZinc
rminizinc::Expression
-> String
.value
string value
.value
string value
new()
constructor
String$new(val)
val
string input
getV()
get value
String$getV()
setV()
set value
String$setV(val)
val
string value
c_str()
get the MiniZinc representation
String$c_str()
clone()
The objects of this class are cloneable with this method.
String$clone(deep = FALSE)
deep
Whether to make a deep clone.
newString = String$new("example") newString$c_str() newString$setV("new example") newString$c_str()
newString = String$new("example") newString$c_str() newString$setV("new example") newString$c_str()
Declare a new n-dimensional array of strings
StringArrDecl(name, kind, ind, value = NULL, ndim)
StringArrDecl(name, kind, ind, value = NULL, ndim)
name |
variable/parameter name |
kind |
"var" or "par" |
ind |
index of the array |
value |
value (NULL by default) |
ndim |
number of dimensions of the array |
Get a list of string expressions
stringExpressions(vals)
stringExpressions(vals)
vals |
vector of string values |
declare a new set of string
StringSetDecl(name, kind, value = NULL)
StringSetDecl(name, kind, value = NULL)
name |
variable/parameter name |
kind |
"var" or "par" |
value |
provide a Set object (or NULL) |
The information of different data types
.bt
the base type
.kind
parameter or decision
.dim
the number of dimensions set or plain
.bt
the base type
.kind
parameter or decision
.dim
the number of dimensions set or plain
new()
constructor
Type$new(base_type, kind, dim = 0, set_type = FALSE)
base_type
the base type
kind
parameter or decision
dim
the number of dimensions
set_type
set or plain
bt()
return the base type
Type$bt()
st()
return if it's set type
Type$st()
kind()
return the kind
Type$kind()
ndim()
return the number of dimensions
Type$ndim()
isInt()
check if it's an int
Type$isInt()
isFloat()
check if it's a float
Type$isFloat()
isBool()
check if it's a bool
Type$isBool()
isString()
check if it's a string
Type$isString()
isSet()
return if set in MiniZinc
Type$isSet()
isIntSet()
check if it's a set of int
Type$isIntSet()
isFloatSet()
check if it's a set of float
Type$isFloatSet()
isBoolSet()
check if it's a set of bool
Type$isBoolSet()
clone()
The objects of this class are cloneable with this method.
Type$clone(deep = FALSE)
deep
Whether to make a deep clone.
Create type instantiation with indices, etc.
rminizinc::Expression
-> TypeInst
.indExpr
the index expression
.domain
the domain of possible values to be taken
.type
the type information
.indExpr
the index expression
.domain
the domain of possible values to be taken
.type
the type information
new()
constructor
TypeInst$new(type, indexExprVec = NULL, domain = NULL)
type
type of declaration
indexExprVec
expression list of indices
domain
the domain of decision variables
getDomain()
get the variable domain
TypeInst$getDomain()
setDomain()
set the variable domain
TypeInst$setDomain(dom)
dom
domain expression to be set
ranges()
return the index expression vector
TypeInst$ranges()
isArray()
check if it's an array
TypeInst$isArray()
type()
return the type information
TypeInst$type()
clone()
The objects of this class are cloneable with this method.
TypeInst$clone(deep = FALSE)
deep
Whether to make a deep clone.
TypeInst$new(type = Type$new(base_type = "int", kind = "par" ,dim = 1), domain = Set$new(IntSetVal$new(2,5)))
TypeInst$new(type = Type$new(base_type = "int", kind = "par" ,dim = 1), domain = Set$new(IntSetVal$new(2,5)))
Unary operation expression in MiniZinc Possible unary operators are: "+", "-", "not"
rminizinc::Expression
-> UnOp
.args
list of expression arguments
.op
operator to be used
.delete_flag
used to delete items
.args
list of expression arguments
.op
operator to be used
.delete_flag
used to delete items
new()
constructor
UnOp$new(args, op)
args
list of expressions
op
unary operator
nargs()
get the number of arguments
UnOp$nargs()
getArgs()
get all expression arguments
UnOp$getArgs()
setArgs()
set all expression arguments
UnOp$setArgs()
args
argument list to be set
getArg()
get the ith expression argument
UnOp$getArg(i)
i
index
setArg()
set the ith expression argument
UnOp$setArg(i, val)
i
index
val
value of expression to be set
getOp()
get the unary operator
UnOp$getOp()
setOp()
set the unary operator
UnOp$setOp(unop)
unop
unary operator to be set
c_str()
return the MiniZinc representation
UnOp$c_str()
getDeleteFlag()
delete flag for internal use
UnOp$getDeleteFlag()
delete()
delete the assignment item
UnOp$delete()
clone()
The objects of this class are cloneable with this method.
UnOp$clone(deep = FALSE)
deep
Whether to make a deep clone.
newUnOp = UnOp$new(args = list(Int$new(5)), op = "-") newUnOp$c_str() newUnOp$setArg(1, Int$new(6)) newUnOp$setOp("+") newUnOp$c_str()
newUnOp = UnOp$new(args = list(Int$new(5)), op = "-") newUnOp$c_str() newUnOp$setArg(1, Int$new(6)) newUnOp$setOp("+") newUnOp$c_str()
Contains different fields to create a variable declaration
rminizinc::Expression
-> VarDecl
.ti
type instantiation information
id
name of the variable
.expression
the initialization expression
.delete_flag
used to delete items
.ti
type instantiation information
id
name of the variable
.expression
the initialization expression
.delete_flag
used to delete items
new()
constructor
VarDecl$new(name, type_inst, value = NULL)
name
the identifier/name
type_inst
type instantiation of the variable
value
value of variable, NULL by default
getId()
get the identifier object
VarDecl$getId()
setId()
set the identifier object name
VarDecl$setId(name)
name
name to be set
isPar()
check if it's a parameter
VarDecl$isPar()
isVar()
check if it's a decision variable
VarDecl$isVar()
setDomain()
overwrite the existing domain
VarDecl$setDomain(dom)
dom
domain expression to be set
getDomain()
get the variable domain
VarDecl$getDomain()
getValue()
get the value
VarDecl$getValue()
setValue()
set the value
VarDecl$setValue(val)
val
expression to be set (NULL to remove value)
ti()
get the type-inst of the variable declaration
VarDecl$ti()
c_str()
get the domain of the variable
return string representation of MiniZinc
VarDecl$c_str()
getDeleteFlag()
delete flag for internal use
VarDecl$getDeleteFlag()
delete()
delete the assignment item
VarDecl$delete()
clone()
The objects of this class are cloneable with this method.
VarDecl$clone(deep = FALSE)
deep
Whether to make a deep clone.
newVarDecl = VarDecl$new(name = "n", type_inst = TypeInst$new(Type$new(base_type = "int", kind = "par"))) newVarDecl$c_str()
newVarDecl = VarDecl$new(name = "n", type_inst = TypeInst$new(Type$new(base_type = "int", kind = "par"))) newVarDecl$c_str()
Declaration items in the model
rminizinc::Item
-> VarDeclItem
.decl
the declaration expression
.delete_flag
used to delete items
.decl
the declaration expression
.delete_flag
used to delete items
new()
constructor
VarDeclItem$new(decl = NULL, mzn_str = NULL)
decl
the declaration expression object
mzn_str
string representation of variable declaration item
getDecl()
get the variable declaration
VarDeclItem$getDecl()
setDecl()
set the variable declaration
VarDeclItem$setDecl(e)
e
var decl expression
getId()
get the identifier object for the variable
VarDeclItem$getId()
c_str()
set the variable declaration
convert the declaration to String
VarDeclItem$c_str()
getDeleteFlag()
delete flag for internal use
VarDeclItem$getDeleteFlag()
delete()
delete the variable item
VarDeclItem$delete()
clone()
The objects of this class are cloneable with this method.
VarDeclItem$clone(deep = FALSE)
deep
Whether to make a deep clone.
Declare a 0 dimensional (int, float, bool or string) variable with domain
VarDomainDecl(name, dom)
VarDomainDecl(name, dom)
name |
variable name |
dom |
domain |