@@ -11,9 +11,8 @@ import fuookami.ospf.kotlin.core.frontend.expression.symbol.*
11
11
import fuookami.ospf.kotlin.core.frontend.inequality.*
12
12
import fuookami.ospf.kotlin.core.frontend.model.mechanism.*
13
13
import fuookami.ospf.kotlin.core.backend.plugins.scip.*
14
- import fuookami.ospf.kotlin.core.backend.solver.config.*
15
14
16
- class Demo2 {
15
+ data object Demo2 {
17
16
class Product : AutoIndexed (Product : :class)
18
17
19
18
data class Company (
@@ -30,16 +29,14 @@ class Demo2 {
30
29
31
30
private val metaModel: LinearMetaModel = LinearMetaModel (" demo2" )
32
31
33
- companion object {
34
- val subProcesses = arrayListOf (
35
- Demo2 ::initVariable,
36
- Demo2 ::initSymbol,
37
- Demo2 ::initObject,
38
- Demo2 ::initConstraint,
39
- Demo2 ::solve,
40
- Demo2 ::analyzeSolution
41
- )
42
- }
32
+ private val subProcesses = arrayListOf (
33
+ Demo2 ::initVariable,
34
+ Demo2 ::initSymbol,
35
+ Demo2 ::initObject,
36
+ Demo2 ::initConstraint,
37
+ Demo2 ::solve,
38
+ Demo2 ::analyzeSolution
39
+ )
43
40
44
41
init {
45
42
products.add(Product ())
@@ -94,29 +91,29 @@ class Demo2 {
94
91
95
92
suspend operator fun invoke (): Try {
96
93
for (process in subProcesses) {
97
- when (val result = process(this )) {
94
+ when (val result = process()) {
98
95
is Failed -> {
99
96
return Failed (result.error)
100
97
}
101
98
102
99
else -> {}
103
100
}
104
101
}
105
- return Ok (success)
102
+ return ok
106
103
}
107
104
108
- suspend fun initVariable (): Try {
105
+ private suspend fun initVariable (): Try {
109
106
x = BinVariable2 (" x" , Shape2 (companies.size, products.size))
110
107
for (c in companies) {
111
108
for (p in products) {
112
109
x[c, p].name = " ${x.name} _${c.index} ,${p.index} "
113
110
}
114
111
}
115
112
metaModel.addVars(x)
116
- return Ok (success)
113
+ return ok
117
114
}
118
115
119
- suspend fun initSymbol (): Try {
116
+ private suspend fun initSymbol (): Try {
120
117
cost = LinearExpressionSymbol (flatSum(companies) { c ->
121
118
products.map { p ->
122
119
c.cost[p]?.let { it * x[c, p] }
@@ -140,25 +137,25 @@ class Demo2 {
140
137
)
141
138
metaModel.addSymbols(assignmentProduct)
142
139
143
- return Ok (success)
140
+ return ok
144
141
}
145
142
146
- suspend fun initObject (): Try {
143
+ private suspend fun initObject (): Try {
147
144
metaModel.minimize(cost)
148
- return Ok (success)
145
+ return ok
149
146
}
150
147
151
- suspend fun initConstraint (): Try {
148
+ private suspend fun initConstraint (): Try {
152
149
for (c in companies) {
153
150
metaModel.addConstraint(assignmentCompany[c] leq 1 )
154
151
}
155
152
for (p in products) {
156
153
metaModel.addConstraint(assignmentProduct[p] eq 1 )
157
154
}
158
- return Ok (success)
155
+ return ok
159
156
}
160
157
161
- suspend fun solve (): Try {
158
+ private suspend fun solve (): Try {
162
159
val solver = SCIPLinearSolver ()
163
160
when (val ret = solver(metaModel)) {
164
161
is Ok -> {
@@ -169,10 +166,10 @@ class Demo2 {
169
166
return Failed (ret.error)
170
167
}
171
168
}
172
- return Ok (success)
169
+ return ok
173
170
}
174
171
175
- suspend fun analyzeSolution (): Try {
172
+ private suspend fun analyzeSolution (): Try {
176
173
val ret = ArrayList <Pair <Company , Product >>()
177
174
for (token in metaModel.tokens.tokens) {
178
175
if (token.result!! eq Flt64 .one
@@ -181,6 +178,6 @@ class Demo2 {
181
178
ret.add(Pair (companies[token.variable.vectorView[0 ]], products[token.variable.vectorView[1 ]]))
182
179
}
183
180
}
184
- return Ok (success)
181
+ return ok
185
182
}
186
183
}
0 commit comments