From 79f977929c13c4b71b6e5d809043ec1aeea9b030 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 13 Oct 2025 14:06:10 +0000 Subject: [PATCH 1/2] Initial plan From 13ee85fa408903d7c6030bee92dcc6a1344eb025 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 13 Oct 2025 14:13:23 +0000 Subject: [PATCH 2/2] Add GetProblem method to Solution interface and DummySolution implementation Co-authored-by: kwesiRutledge <9002730+kwesiRutledge@users.noreply.github.com> --- solution/dummy_solution.go | 12 ++++++- solution/solution.go | 4 +++ testing/solution/solution_test.go | 60 +++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) diff --git a/solution/dummy_solution.go b/solution/dummy_solution.go index 1d6dbe6..6b980ba 100644 --- a/solution/dummy_solution.go +++ b/solution/dummy_solution.go @@ -1,6 +1,9 @@ package solution -import solution_status "github.com/MatProGo-dev/MatProInterface.go/solution/status" +import ( + "github.com/MatProGo-dev/MatProInterface.go/problem" + solution_status "github.com/MatProGo-dev/MatProInterface.go/solution/status" +) type DummySolution struct { Values map[uint64]float64 @@ -11,6 +14,9 @@ type DummySolution struct { // Whether or not the solution is within the optimality threshold Status solution_status.SolutionStatus + // The optimization problem that this solution is for + Problem *problem.OptimizationProblem + // The optimality gap returned from the solver. For many solvers, this is // the gap between the best possible solution with integer relaxation and // the best integer solution found so far. @@ -28,3 +34,7 @@ func (ds *DummySolution) GetValueMap() map[uint64]float64 { func (ds *DummySolution) GetStatus() solution_status.SolutionStatus { return ds.Status } + +func (ds *DummySolution) GetProblem() *problem.OptimizationProblem { + return ds.Problem +} diff --git a/solution/solution.go b/solution/solution.go index 7c9d0bf..692d227 100644 --- a/solution/solution.go +++ b/solution/solution.go @@ -3,6 +3,7 @@ package solution import ( "fmt" + "github.com/MatProGo-dev/MatProInterface.go/problem" solution_status "github.com/MatProGo-dev/MatProInterface.go/solution/status" "github.com/MatProGo-dev/SymbolicMath.go/symbolic" ) @@ -20,6 +21,9 @@ type Solution interface { // GetStatus // GetStatus() solution_status.SolutionStatus + + // GetProblem returns the optimization problem that this solution is for + GetProblem() *problem.OptimizationProblem } func ExtractValueOfVariableWithID(s Solution, idx uint64) (float64, error) { diff --git a/testing/solution/solution_test.go b/testing/solution/solution_test.go index 3ec822c..4ad9211 100644 --- a/testing/solution/solution_test.go +++ b/testing/solution/solution_test.go @@ -4,6 +4,7 @@ import ( "strings" "testing" + "github.com/MatProGo-dev/MatProInterface.go/problem" "github.com/MatProGo-dev/MatProInterface.go/solution" solution_status "github.com/MatProGo-dev/MatProInterface.go/solution/status" "github.com/MatProGo-dev/SymbolicMath.go/symbolic" @@ -317,3 +318,62 @@ func TestSolution_FindValueOfExpression5(t *testing.T) { ) } } + +/* +TestSolution_GetProblem1 +Description: + + This function tests whether we can retrieve the problem from a solution. +*/ +func TestSolution_GetProblem1(t *testing.T) { + // Constants + p := problem.NewProblem("TestProblem1") + v1 := p.AddVariable() + + tempSol := solution.DummySolution{ + Values: map[uint64]float64{ + v1.ID: 2.1, + }, + Objective: 2.3, + Status: solution_status.OPTIMAL, + Problem: p, + } + + // Algorithm + retrievedProblem := tempSol.GetProblem() + + // Verify the problem is the same + if retrievedProblem != p { + t.Errorf("Expected GetProblem to return the same problem pointer") + } + + if retrievedProblem.Name != "TestProblem1" { + t.Errorf("Expected problem name to be 'TestProblem1'; received %v", retrievedProblem.Name) + } +} + +/* +TestSolution_GetProblem2 +Description: + + This function tests whether GetProblem returns nil when no problem is set. +*/ +func TestSolution_GetProblem2(t *testing.T) { + // Constants + tempSol := solution.DummySolution{ + Values: map[uint64]float64{ + 0: 2.1, + }, + Objective: 2.3, + Status: solution_status.OPTIMAL, + Problem: nil, + } + + // Algorithm + retrievedProblem := tempSol.GetProblem() + + // Verify the problem is nil + if retrievedProblem != nil { + t.Errorf("Expected GetProblem to return nil when no problem is set") + } +}