-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathetriutils.R
More file actions
36 lines (29 loc) · 963 Bytes
/
etriutils.R
File metadata and controls
36 lines (29 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
etriutils.addVariables <- function(constr, names){
##
w <- matrix(0, ncol=length(names), nrow=nrow(constr))
colnames(w) <- names
constr <- cbind(constr, w)
return(constr)
}
etriutils.getVariablesCount <- function(constr){
return(ncol(constr))
}
etriutils.solve <- function(objectioveFunction, varTypes, lhs, dir, rhs, max){
obj <- L_objective(objectioveFunction)
roiConst <- L_constraint(lhs, dir, rhs)
lp <- OP(objective=obj, constraints=roiConst, maximum=max, types=varTypes)
ret <- ROI_solve(lp, .solver)
return(ret)
}
etriutils.getConstraintTypes <- function(varnames, binaryVarNames){
types <- matrix("C", nrow = 1, ncol=length(varnames))
colnames(types) <- varnames
types[,binaryVarNames] <- "B"
return(types[1,])
}
etriutils.buildObjectiveFunction <- function(varnames, objectivesVarNames){
row <- matrix(0, ncol=length(varnames))
colnames(row) <- varnames
row[,objectivesVarNames] <- 1
return(row[1,])
}