-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy path.Rhistory
More file actions
136 lines (136 loc) · 5.01 KB
/
.Rhistory
File metadata and controls
136 lines (136 loc) · 5.01 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
setwd("~/Documents/linearprogramming")
source("CapFacility.R")
d <- c(100, 200, 200, 150, 200)
s <- c(1200, 800)
f <- c(3000, 3000)
CapFacility(d, s, f, c)
c <- matrix(c(1,4,5,6,6,4,3,7,6,9),2,5 )
c
source("CapFacility.R")
demand <- c(100, 200, 200, 150, 200)
capacity <- c(1200, 800)
fixed.costs <- c(3000, 3000)
transp.costs <- matrix(c(1,4,5,6,6,4,3,7,6,9),2,5)
CapFacility(demand, capacity, fixed.costs, transp.costs)
plan <- CapFacility(demand, capacity, fixed.costs, transp.costs)
solution <- as.matrix(plan$solution, 2, 5, byrow=TRUE)
solution
solution <- as.matrix(plan$solution, 2, 5)
solution
solution <- as.matrix(plan$solution[1:10], 2, 5)
solution
?as.matrix
as.matrix(1:10, 2, 5)
as.matrix(1:10, nrow=2, ncol=5)
as.matrix(1:4, 2, 2)
dim(plan$solution[1:10]) <- c(2,5)
plan$solution
plan <- CapFacility(demand, capacity, fixed.costs, transp.costs)
plan
source("CapFacility.R")
source("CapFacility.R")
plan <- CapFacility(demand, capacity, fixed.costs, transp.costs)
plan
source("CapFacility.R")
plan <- CapFacility(demand, capacity, fixed.costs, transp.costs)
plan
sum(demand)
source("CapFacility.R")
demand <- c(100, 200, 200, 150, 200)
capacity <- c(1200, 800)
fixed.costs <- c(3000, 3000)
transp.costs <- matrix(c(1,4,5,6,6,4,3,7,6,9),2,5,byrow=TRUE)
plan <- CapFacility(demand, capacity, fixed.costs, transp.costs)
plan
demand <- c(200, 400, 300, 450, 300)
sum(demand)
demand.B <- c(200, 400, 300, 450, 300)
capacity <- c(1200, 800)
fixed.costs <- c(3000, 3000)
transp.costs <- matrix(c(1,4,5,6,6,4,3,7,6,9),2,5,byrow=TRUE)
plan.caseB <- CapFacility(demand.B, capacity, fixed.costs, transp.costs)
plan.B <- CapFacility(demand.B, capacity, fixed.costs, transp.costs)
plan.B
demand.C <- c(200, 400, 300, 450, 300)
capacity.C <- c(1000, 600)
fixed.costs <- c(3000, 3000)
transp.costs <- matrix(c(1,4,5,6,6,4,3,7,6,9),2,5,byrow=TRUE)
plan.C <- CapFacility(demand.B, capacity, fixed.costs, transp.costs)
plan.C
plan.C <- CapFacility(demand.C, capacity.C, fixed.costs, transp.costs)
plan.C
rm(list=ls())
source("CapFacility.R")
#model parameters (case A)
demand <- c(100, 200, 200, 150, 200)
capacity <- c(1200, 800)
fixed.costs <- c(3000, 3000)
transp.costs <- matrix(c(1,4,5,6,6,4,3,7,6,9),2,5,byrow=TRUE)
#the solution is stored in the plan variable
plan.caseA <- CapFacility(demand, capacity, fixed.costs, transp.costs)
#model parameters (case B)
demand.B <- c(200, 400, 300, 450, 300)
capacity <- c(1200, 800)
fixed.costs <- c(3000, 3000)
transp.costs <- matrix(c(1,4,5,6,6,4,3,7,6,9),2,5,byrow=TRUE)
plan.B <- CapFacility(demand.B, capacity, fixed.costs, transp.costs)
#model parameters (case C):non-feasible solution
demand.C <- c(200, 400, 300, 450, 300)
capacity.C <- c(1000, 600)
fixed.costs <- c(3000, 3000)
transp.costs <- matrix(c(1,4,5,6,6,4,3,7,6,9),2,5,byrow=TRUE)
#non-feasible solution: plan.C$status equals one, all other variables of plan.C zero
plan.C <- CapFacility(demand.C, capacity.C, fixed.costs, transp.costs)
rm(list=ls())
#example of use of the CapFaciliy function
#loading the function
source("CapFacility.R")
#model parameters (case A)
demand <- c(100, 200, 200, 150, 200)
capacity <- c(1200, 800)
fixed.costs <- c(3000, 3000)
transp.costs <- matrix(c(1,4,5,6,6,4,3,7,6,9),2,5,byrow=TRUE)
#the solution is stored in the plan variable
plan.A <- CapFacility(demand, capacity, fixed.costs, transp.costs)
#model parameters (case B)
demand.B <- c(200, 400, 300, 450, 300)
capacity <- c(1200, 800)
fixed.costs <- c(3000, 3000)
transp.costs <- matrix(c(1,4,5,6,6,4,3,7,6,9),2,5,byrow=TRUE)
plan.B <- CapFacility(demand.B, capacity, fixed.costs, transp.costs)
#model parameters (case C):non-feasible solution
demand.C <- c(200, 400, 300, 450, 300)
capacity.C <- c(1000, 600)
fixed.costs <- c(3000, 3000)
transp.costs <- matrix(c(1,4,5,6,6,4,3,7,6,9),2,5,byrow=TRUE)
#non-feasible solution: plan.C$status equals one, all other variables of plan.C zero
plan.C <- CapFacility(demand.C, capacity.C, fixed.costs, transp.costs)
install.packages("Rsymphony")
SolverLP <- function(model, method="CPLEX_LP", decimal=0){
library(Rglpk)
model1.lp <- Rglpk_read_file(model, type = method, verbose=F)
model1.lp.sol <- Rglpk_solve_LP(model1.lp$objective, model1.lp$constraints[[1]], model1.lp$constraints[[2]], model1.lp$constraints[[3]], model1.lp$bounds, model1.lp$types, model1.lp$maximum)
library(xtable)
model1.lp.sol.df <- as.data.frame(model1.lp.sol$solution)
model1.lp.sol.df <- rbind(model1.lp.sol.df, c(model1.lp.sol$optimum))
rownames(model1.lp.sol.df) <- c(attr(model1.lp, "objective_vars_names"),"obj")
colnames(model1.lp.sol.df) <- "Solution"
table.sol <- xtable(model1.lp.sol.df, digits=decimal)
results <- list(sol=model1.lp.sol, df=model1.lp.sol.df, latex=table.sol)
return(results)
}
setwd("~/Documents/linearprogramming")
SolverLP("PO3_a.mod")
SolverLP("PO4.mod")
setwd("~/Documents/linearprogramming")
library(Rglpk)
Rglpk_read_file("P03_b.mod")
Rglpk_read_file("P03_b.mod", method="CPLEX_LP")
?Rglpk_read_file
Rglpk_read_file("P03_b.mod", type ="CPLEX_LP")
SolverLP("P03_b.mod")
install.packages("xtable")
SolverLP("P03_b.mod")
SolverLP("ProdAmpl.mod", "MathProg")
library(xtable)
?xtable