diff --git a/go.mod b/go.mod index 2c1ffb6..4ae99a9 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index d1772a3..526c9ae 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/solution/dummy_solution.go b/solution/dummy_solution.go index 6b980ba..410c5a5 100644 --- a/solution/dummy_solution.go +++ b/solution/dummy_solution.go @@ -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 @@ -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 } diff --git a/solution/solution.go b/solution/solution.go index bae1285..5c018f6 100644 --- a/solution/solution.go +++ b/solution/solution.go @@ -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 diff --git a/testing/solution/solution_test.go b/testing/solution/solution_test.go index c3a4f71..804adf1 100644 --- a/testing/solution/solution_test.go +++ b/testing/solution/solution_test.go @@ -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. @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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