44 "fmt"
55
66 "github.com/MatProGo-dev/MatProInterface.go/problem"
7+ solution_status "github.com/MatProGo-dev/MatProInterface.go/solution/status"
78 "github.com/MatProGo-dev/SymbolicMath.go/symbolic"
9+ simplex_solution "github.com/MatProGo-dev/simplex/solution"
810 "github.com/MatProGo-dev/simplex/utils"
911 "gonum.org/v1/gonum/mat"
1012)
@@ -178,11 +180,11 @@ Description:
178180 - The values of the basic variables
179181 - The values of the non-basic variables
180182*/
181- func (algo * StanfordAlgorithm ) ComputeSolutionFromState (state StanfordAlgorithmState ) (problem. Solution , error ) {
183+ func (algo * StanfordAlgorithm ) ComputeSolutionFromState (state StanfordAlgorithmState ) (simplex_solution. SimplexSolution , error ) {
182184 // Setup
183185 fmt .Printf ("Computing solution from state...\n " )
184- solution := problem. Solution {
185- Status : problem . OptimizationStatus_OPTIMAL ,
186+ solution := simplex_solution. SimplexSolution {
187+ Status : solution_status . OPTIMAL ,
186188 }
187189
188190 // Compute the feasible solution of the basic variables
@@ -192,26 +194,25 @@ func (algo *StanfordAlgorithm) ComputeSolutionFromState(state StanfordAlgorithmS
192194 }
193195
194196 // Compute the value of the objective function
195- objValue , err : = algo .ComputeObjectiveFunctionValueWithFeasibleBasicSolution (state , xBasic )
197+ _ , err = algo .ComputeObjectiveFunctionValueWithFeasibleBasicSolution (state , xBasic )
196198 if err != nil {
197199 return solution , fmt .Errorf ("StanfordAlgorithm: Failed to compute objective function value (%v)" , err )
198200 }
199- solution .Objective = objValue
200201
201202 // Set the values of the basic variables
202203 for ii , bv := range state .BasicVariables {
203- solution .Values [bv .ID ] = xBasic .AtVec (ii )
204+ solution .VariableValues [bv .ID ] = xBasic .AtVec (ii )
204205 }
205206
206207 // Set the values of the non-basic variables
207208 for jj , nv := range state .GetNonBasicVariables () {
208- solution .Values [nv .ID ] = state .NonBasicValues .AtVec (jj )
209+ solution .VariableValues [nv .ID ] = state .NonBasicValues .AtVec (jj )
209210 }
210211
211212 return solution , nil
212213}
213214
214- func (algo * StanfordAlgorithm ) Solve (initialState StanfordAlgorithmState ) (problem. Solution , error ) {
215+ func (algo * StanfordAlgorithm ) Solve (initialState StanfordAlgorithmState ) (simplex_solution. SimplexSolution , error ) {
215216 // Setup
216217 var stateII StanfordAlgorithmState = initialState
217218
@@ -221,7 +222,7 @@ func (algo *StanfordAlgorithm) Solve(initialState StanfordAlgorithmState) (probl
221222 // Test for Termination
222223 r , err := stateII .GetReducedCostVector ()
223224 if err != nil {
224- return problem. Solution {}, fmt .Errorf (
225+ return simplex_solution. SimplexSolution {}, fmt .Errorf (
225226 "StanfordAlgorithm: Failed to get reduced cost vector (%v) at iteration #%v" ,
226227 err ,
227228 iter ,
@@ -248,7 +249,7 @@ func (algo *StanfordAlgorithm) Solve(initialState StanfordAlgorithmState) (probl
248249 var ABasicInv mat.Dense
249250 ABasic , err := stateII .ABasic ()
250251 if err != nil {
251- return problem. Solution {}, fmt .Errorf ("StanfordAlgorithm: Failed to get ABasic matrix (%v)" , err )
252+ return simplex_solution. SimplexSolution {}, fmt .Errorf ("StanfordAlgorithm: Failed to get ABasic matrix (%v)" , err )
252253 }
253254 ABasicInv .Inverse (ABasic )
254255 var ABasicAe mat.VecDense
@@ -263,7 +264,7 @@ func (algo *StanfordAlgorithm) Solve(initialState StanfordAlgorithmState) (probl
263264 }
264265 }
265266 if objectiveIsUnboundedBelow {
266- return problem. Solution {}, fmt .Errorf (
267+ return simplex_solution. SimplexSolution {}, fmt .Errorf (
267268 "StanfordAlgorithm: Objective function is unbounded below, no solution exists at iteration %d" ,
268269 iter ,
269270 )
@@ -274,13 +275,13 @@ func (algo *StanfordAlgorithm) Solve(initialState StanfordAlgorithmState) (probl
274275 // Compute the feasible Solution of the Basic variables
275276 xBasicII , err := algo .ComputeFeasibleBasicSolution (stateII )
276277 if err != nil {
277- return problem. Solution {}, err
278+ return simplex_solution. SimplexSolution {}, err
278279 }
279280
280281 // Compute the value of the objective function
281282 objII , err := algo .ComputeObjectiveFunctionValueWithFeasibleBasicSolution (stateII , xBasicII )
282283 if err != nil {
283- return problem. Solution {}, err
284+ return simplex_solution. SimplexSolution {}, err
284285 }
285286 fmt .Printf ("Iteration %d: Basic Solution: %v, Objective Value: %f\n " , iter , xBasicII , objII )
286287
@@ -290,13 +291,12 @@ func (algo *StanfordAlgorithm) Solve(initialState StanfordAlgorithmState) (probl
290291 // Check if the solution is optimal
291292
292293 if iter == algo .IterationLimit {
293- return problem.Solution {
294- Objective : objII ,
295- Status : problem .OptimizationStatus_ITERATION_LIMIT ,
294+ return simplex_solution.SimplexSolution {
295+ Status : solution_status .ITERATION_LIMIT ,
296296 }, nil
297297 }
298298
299299 }
300300
301- return problem. Solution {}, nil
301+ return simplex_solution. SimplexSolution {}, nil
302302}
0 commit comments