Skip to content

Commit eccb7e9

Browse files
Remove the GetObjective() function from the solution.Solution Interface + Upgrade SymbolicMath.go version (#28)
* Removed unnecessary objective getter from Solution interface * fixed all tests related to the Objective member of DummySolution * Upgraded go module for SymbolicMath * Update solution/solution.go Improved comment for GetStatus interface method. Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent ea9d244 commit eccb7e9

File tree

5 files changed

+54
-45
lines changed

5 files changed

+54
-45
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ toolchain go1.23.9
66

77
require gonum.org/v1/gonum v0.16.0
88

9-
require github.com/MatProGo-dev/SymbolicMath.go v0.2.6
9+
require github.com/MatProGo-dev/SymbolicMath.go v0.3.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
github.com/MatProGo-dev/SymbolicMath.go v0.2.6 h1:0THkOKIjdjadIb9MHIUflk08U7tv17KvtQPOP3eMOfk=
2-
github.com/MatProGo-dev/SymbolicMath.go v0.2.6/go.mod h1:tW8thj4pkaTV9lFNU3OCKmwQ3mZ2Eim6S4JpHRDfRvU=
1+
github.com/MatProGo-dev/SymbolicMath.go v0.3.1 h1:WM5lVAySD4mQDvq3RABUmJgSGkSYHT0CC+ZJXeTTJRg=
2+
github.com/MatProGo-dev/SymbolicMath.go v0.3.1/go.mod h1:tW8thj4pkaTV9lFNU3OCKmwQ3mZ2Eim6S4JpHRDfRvU=
33
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
44
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=

solution/dummy_solution.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ import (
88
type DummySolution struct {
99
Values map[uint64]float64
1010

11-
// The objective for the solution
12-
Objective float64
13-
1411
// Whether or not the solution is within the optimality threshold
1512
Status solution_status.SolutionStatus
1613

@@ -23,10 +20,6 @@ type DummySolution struct {
2320
// Gap float64
2421
}
2522

26-
func (ds *DummySolution) GetOptimalValue() float64 {
27-
return ds.Objective
28-
}
29-
3023
func (ds *DummySolution) GetValueMap() map[uint64]float64 {
3124
return ds.Values
3225
}

solution/solution.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,33 @@ const (
1515
// Solution stores the solution of an optimization problem and associated
1616
// metadata
1717
type Solution interface {
18-
GetOptimalValue() float64
18+
// GetValueMap returns a map from variable ID to its value in the solution
19+
//
20+
// The map keys are the IDs of the variables (uint64)
21+
// The map values are the corresponding values of those variables in the solution (float64)
22+
//
23+
// Example:
24+
// If variable with ID 1 has value 3.5 in the solution, then the map will contain an entry:
25+
// 1: 3.5
26+
//
27+
// This allows easy lookup of variable values by their IDs.
28+
//
29+
// Note: Variable IDs can be obtained from the symbolic.Variable.ID field.
30+
//
31+
// Example usage:
32+
// valMap := solution.GetValueMap()
33+
// x1Value := valMap[x1.ID] // where x1 is a symbolic.Variable
34+
// fmt.Println("Value of x1 in solution:", x1Value)
1935
GetValueMap() map[uint64]float64
2036

21-
// GetStatus
37+
// GetStatus returns the status of the solution (e.g., optimal, infeasible, etc.).
38+
//
39+
// The returned value is of type solution_status.SolutionStatus, which indicates
40+
// whether the solution is optimal, infeasible, unbounded, or has another status.
2241
//
42+
// Example usage:
43+
// status := solution.GetStatus()
44+
// fmt.Println("Solution status:", status)
2345
GetStatus() solution_status.SolutionStatus
2446

2547
// GetProblem returns the optimization problem that this solution is for

testing/solution/solution_test.go

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ func TestSolution_ToMessage1(t *testing.T) {
3333
0: 2.1,
3434
1: 3.14,
3535
},
36-
Objective: 2.3,
37-
Status: solution_status.NODE_LIMIT,
36+
Status: solution_status.NODE_LIMIT,
3837
}
3938

4039
// Test the ToMessage() Call on this solution.
@@ -114,8 +113,7 @@ func TestSolution_Value1(t *testing.T) {
114113
v1.ID: 2.1,
115114
v2.ID: 3.14,
116115
},
117-
Objective: 2.3,
118-
Status: solution_status.NODE_LIMIT,
116+
Status: solution_status.NODE_LIMIT,
119117
}
120118

121119
// Algorithm
@@ -162,8 +160,7 @@ func TestSolution_FindValueOfExpression1(t *testing.T) {
162160
v1.ID: 2.0,
163161
v2.ID: 3.0,
164162
},
165-
Objective: 2.3,
166-
Status: solution_status.OPTIMAL,
163+
Status: solution_status.OPTIMAL,
167164
}
168165

169166
// Create expression: 2*v1 + 3*v2 = 2*2.0 + 3*3.0 = 4.0 + 9.0 = 13.0
@@ -196,9 +193,9 @@ Description:
196193
func TestSolution_FindValueOfExpression2(t *testing.T) {
197194
// Constants
198195
tempSol := solution.DummySolution{
199-
Values: map[uint64]float64{},
200-
Objective: 2.3,
201-
Status: solution_status.OPTIMAL,
196+
Values: map[uint64]float64{},
197+
198+
Status: solution_status.OPTIMAL,
202199
}
203200

204201
// Create constant expression: 42.0
@@ -236,8 +233,8 @@ func TestSolution_FindValueOfExpression3(t *testing.T) {
236233
Values: map[uint64]float64{
237234
v1.ID: 5.5,
238235
},
239-
Objective: 2.3,
240-
Status: solution_status.OPTIMAL,
236+
237+
Status: solution_status.OPTIMAL,
241238
}
242239

243240
// Create expression: v1 + 10 = 5.5 + 10 = 15.5
@@ -278,8 +275,8 @@ func TestSolution_FindValueOfExpression4(t *testing.T) {
278275
v1.ID: 2.0,
279276
// v2 is missing
280277
},
281-
Objective: 2.3,
282-
Status: solution_status.OPTIMAL,
278+
279+
Status: solution_status.OPTIMAL,
283280
}
284281

285282
// Create expression: v1 + v2
@@ -311,8 +308,8 @@ func TestSolution_FindValueOfExpression5(t *testing.T) {
311308
v2.ID: 2.0,
312309
v3.ID: 3.0,
313310
},
314-
Objective: 2.3,
315-
Status: solution_status.OPTIMAL,
311+
312+
Status: solution_status.OPTIMAL,
316313
}
317314

318315
// Create expression: (v1 + v2) * v3 + 5 = (1.0 + 2.0) * 3.0 + 5 = 3.0 * 3.0 + 5 = 9.0 + 5 = 14.0
@@ -351,9 +348,9 @@ func TestSolution_GetProblem1(t *testing.T) {
351348
Values: map[uint64]float64{
352349
v1.ID: 2.1,
353350
},
354-
Objective: 2.3,
355-
Status: solution_status.OPTIMAL,
356-
Problem: p,
351+
352+
Status: solution_status.OPTIMAL,
353+
Problem: p,
357354
}
358355

359356
// Algorithm
@@ -381,9 +378,9 @@ func TestSolution_GetProblem2(t *testing.T) {
381378
Values: map[uint64]float64{
382379
0: 2.1,
383380
},
384-
Objective: 2.3,
385-
Status: solution_status.OPTIMAL,
386-
Problem: nil,
381+
382+
Status: solution_status.OPTIMAL,
383+
Problem: nil,
387384
}
388385

389386
// Algorithm
@@ -422,9 +419,8 @@ func TestSolution_GetOptimalObjectiveValue1(t *testing.T) {
422419
v1.ID: 2.0,
423420
v2.ID: 3.0,
424421
},
425-
Objective: 13.0,
426-
Status: solution_status.OPTIMAL,
427-
Problem: p,
422+
Status: solution_status.OPTIMAL,
423+
Problem: p,
428424
}
429425

430426
// Algorithm
@@ -458,9 +454,9 @@ func TestSolution_GetOptimalObjectiveValue2(t *testing.T) {
458454
Values: map[uint64]float64{
459455
v1.ID: 2.0,
460456
},
461-
Objective: 2.3,
462-
Status: solution_status.OPTIMAL,
463-
Problem: nil,
457+
458+
Status: solution_status.OPTIMAL,
459+
Problem: nil,
464460
}
465461

466462
// Algorithm
@@ -494,9 +490,8 @@ func TestSolution_GetOptimalObjectiveValue3(t *testing.T) {
494490
Values: map[uint64]float64{
495491
v1.ID: 1.0,
496492
},
497-
Objective: 42.0,
498-
Status: solution_status.OPTIMAL,
499-
Problem: p,
493+
Status: solution_status.OPTIMAL,
494+
Problem: p,
500495
}
501496

502497
// Algorithm
@@ -544,9 +539,8 @@ func TestSolution_GetOptimalObjectiveValue4(t *testing.T) {
544539
v2.ID: 2.0,
545540
v3.ID: 3.0,
546541
},
547-
Objective: 14.0,
548-
Status: solution_status.OPTIMAL,
549-
Problem: p,
542+
Status: solution_status.OPTIMAL,
543+
Problem: p,
550544
}
551545

552546
// Algorithm

0 commit comments

Comments
 (0)