Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ toolchain go1.23.9

require gonum.org/v1/gonum v0.16.0

require github.com/MatProGo-dev/SymbolicMath.go v0.2.6
require github.com/MatProGo-dev/SymbolicMath.go v0.3.1
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github.com/MatProGo-dev/SymbolicMath.go v0.2.6 h1:0THkOKIjdjadIb9MHIUflk08U7tv17KvtQPOP3eMOfk=
github.com/MatProGo-dev/SymbolicMath.go v0.2.6/go.mod h1:tW8thj4pkaTV9lFNU3OCKmwQ3mZ2Eim6S4JpHRDfRvU=
github.com/MatProGo-dev/SymbolicMath.go v0.3.1 h1:WM5lVAySD4mQDvq3RABUmJgSGkSYHT0CC+ZJXeTTJRg=
github.com/MatProGo-dev/SymbolicMath.go v0.3.1/go.mod h1:tW8thj4pkaTV9lFNU3OCKmwQ3mZ2Eim6S4JpHRDfRvU=
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
7 changes: 0 additions & 7 deletions solution/dummy_solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import (
type DummySolution struct {
Values map[uint64]float64

// The objective for the solution
Objective float64

// Whether or not the solution is within the optimality threshold
Status solution_status.SolutionStatus

Expand All @@ -23,10 +20,6 @@ type DummySolution struct {
// Gap float64
}

func (ds *DummySolution) GetOptimalValue() float64 {
return ds.Objective
}

func (ds *DummySolution) GetValueMap() map[uint64]float64 {
return ds.Values
}
Expand Down
26 changes: 24 additions & 2 deletions solution/solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,33 @@ const (
// Solution stores the solution of an optimization problem and associated
// metadata
type Solution interface {
GetOptimalValue() float64
// GetValueMap returns a map from variable ID to its value in the solution
//
// The map keys are the IDs of the variables (uint64)
// The map values are the corresponding values of those variables in the solution (float64)
//
// Example:
// If variable with ID 1 has value 3.5 in the solution, then the map will contain an entry:
// 1: 3.5
//
// This allows easy lookup of variable values by their IDs.
//
// Note: Variable IDs can be obtained from the symbolic.Variable.ID field.
//
// Example usage:
// valMap := solution.GetValueMap()
// x1Value := valMap[x1.ID] // where x1 is a symbolic.Variable
// fmt.Println("Value of x1 in solution:", x1Value)
GetValueMap() map[uint64]float64

// GetStatus
// GetStatus returns the status of the solution (e.g., optimal, infeasible, etc.).
//
// The returned value is of type solution_status.SolutionStatus, which indicates
// whether the solution is optimal, infeasible, unbounded, or has another status.
//
// Example usage:
// status := solution.GetStatus()
// fmt.Println("Solution status:", status)
GetStatus() solution_status.SolutionStatus

// GetProblem returns the optimization problem that this solution is for
Expand Down
60 changes: 27 additions & 33 deletions testing/solution/solution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ func TestSolution_ToMessage1(t *testing.T) {
0: 2.1,
1: 3.14,
},
Objective: 2.3,
Status: solution_status.NODE_LIMIT,
Status: solution_status.NODE_LIMIT,
}

// Test the ToMessage() Call on this solution.
Expand Down Expand Up @@ -114,8 +113,7 @@ func TestSolution_Value1(t *testing.T) {
v1.ID: 2.1,
v2.ID: 3.14,
},
Objective: 2.3,
Status: solution_status.NODE_LIMIT,
Status: solution_status.NODE_LIMIT,
}

// Algorithm
Expand Down Expand Up @@ -162,8 +160,7 @@ func TestSolution_FindValueOfExpression1(t *testing.T) {
v1.ID: 2.0,
v2.ID: 3.0,
},
Objective: 2.3,
Status: solution_status.OPTIMAL,
Status: solution_status.OPTIMAL,
}

// Create expression: 2*v1 + 3*v2 = 2*2.0 + 3*3.0 = 4.0 + 9.0 = 13.0
Expand Down Expand Up @@ -196,9 +193,9 @@ Description:
func TestSolution_FindValueOfExpression2(t *testing.T) {
// Constants
tempSol := solution.DummySolution{
Values: map[uint64]float64{},
Objective: 2.3,
Status: solution_status.OPTIMAL,
Values: map[uint64]float64{},

Status: solution_status.OPTIMAL,
}

// Create constant expression: 42.0
Expand Down Expand Up @@ -236,8 +233,8 @@ func TestSolution_FindValueOfExpression3(t *testing.T) {
Values: map[uint64]float64{
v1.ID: 5.5,
},
Objective: 2.3,
Status: solution_status.OPTIMAL,

Status: solution_status.OPTIMAL,
}

// Create expression: v1 + 10 = 5.5 + 10 = 15.5
Expand Down Expand Up @@ -278,8 +275,8 @@ func TestSolution_FindValueOfExpression4(t *testing.T) {
v1.ID: 2.0,
// v2 is missing
},
Objective: 2.3,
Status: solution_status.OPTIMAL,

Status: solution_status.OPTIMAL,
}

// Create expression: v1 + v2
Expand Down Expand Up @@ -311,8 +308,8 @@ func TestSolution_FindValueOfExpression5(t *testing.T) {
v2.ID: 2.0,
v3.ID: 3.0,
},
Objective: 2.3,
Status: solution_status.OPTIMAL,

Status: solution_status.OPTIMAL,
}

// Create expression: (v1 + v2) * v3 + 5 = (1.0 + 2.0) * 3.0 + 5 = 3.0 * 3.0 + 5 = 9.0 + 5 = 14.0
Expand Down Expand Up @@ -351,9 +348,9 @@ func TestSolution_GetProblem1(t *testing.T) {
Values: map[uint64]float64{
v1.ID: 2.1,
},
Objective: 2.3,
Status: solution_status.OPTIMAL,
Problem: p,

Status: solution_status.OPTIMAL,
Problem: p,
}

// Algorithm
Expand Down Expand Up @@ -381,9 +378,9 @@ func TestSolution_GetProblem2(t *testing.T) {
Values: map[uint64]float64{
0: 2.1,
},
Objective: 2.3,
Status: solution_status.OPTIMAL,
Problem: nil,

Status: solution_status.OPTIMAL,
Problem: nil,
}

// Algorithm
Expand Down Expand Up @@ -422,9 +419,8 @@ func TestSolution_GetOptimalObjectiveValue1(t *testing.T) {
v1.ID: 2.0,
v2.ID: 3.0,
},
Objective: 13.0,
Status: solution_status.OPTIMAL,
Problem: p,
Status: solution_status.OPTIMAL,
Problem: p,
}

// Algorithm
Expand Down Expand Up @@ -458,9 +454,9 @@ func TestSolution_GetOptimalObjectiveValue2(t *testing.T) {
Values: map[uint64]float64{
v1.ID: 2.0,
},
Objective: 2.3,
Status: solution_status.OPTIMAL,
Problem: nil,

Status: solution_status.OPTIMAL,
Problem: nil,
}

// Algorithm
Expand Down Expand Up @@ -494,9 +490,8 @@ func TestSolution_GetOptimalObjectiveValue3(t *testing.T) {
Values: map[uint64]float64{
v1.ID: 1.0,
},
Objective: 42.0,
Status: solution_status.OPTIMAL,
Problem: p,
Status: solution_status.OPTIMAL,
Problem: p,
}

// Algorithm
Expand Down Expand Up @@ -544,9 +539,8 @@ func TestSolution_GetOptimalObjectiveValue4(t *testing.T) {
v2.ID: 2.0,
v3.ID: 3.0,
},
Objective: 14.0,
Status: solution_status.OPTIMAL,
Problem: p,
Status: solution_status.OPTIMAL,
Problem: p,
}

// Algorithm
Expand Down