From f6d68adb2eccd323f3b22974452569faa6b331c8 Mon Sep 17 00:00:00 2001 From: Mikalai Radchuk Date: Fri, 1 Dec 2023 15:12:01 +0000 Subject: [PATCH] Export internal solver Signed-off-by: Mikalai Radchuk --- cmd/dimacs/cmd.go | 16 +++++++++++++--- cmd/sudoku/cmd.go | 9 ++++++--- {internal => pkg/deppy}/solver/bench_test.go | 0 {internal => pkg/deppy}/solver/constraints.go | 0 .../deppy}/solver/constraints_test.go | 0 {internal => pkg/deppy}/solver/doc.go | 0 {internal => pkg/deppy}/solver/lit_mapping.go | 0 {internal => pkg/deppy}/solver/search.go | 0 {internal => pkg/deppy}/solver/search_test.go | 0 {internal => pkg/deppy}/solver/solve.go | 0 {internal => pkg/deppy}/solver/solve_test.go | 0 {internal => pkg/deppy}/solver/tracer.go | 0 {internal => pkg/deppy}/solver/variable.go | 0 {internal => pkg/deppy}/solver/zz_search_test.go | 0 14 files changed, 19 insertions(+), 6 deletions(-) rename {internal => pkg/deppy}/solver/bench_test.go (100%) rename {internal => pkg/deppy}/solver/constraints.go (100%) rename {internal => pkg/deppy}/solver/constraints_test.go (100%) rename {internal => pkg/deppy}/solver/doc.go (100%) rename {internal => pkg/deppy}/solver/lit_mapping.go (100%) rename {internal => pkg/deppy}/solver/search.go (100%) rename {internal => pkg/deppy}/solver/search_test.go (100%) rename {internal => pkg/deppy}/solver/solve.go (100%) rename {internal => pkg/deppy}/solver/solve_test.go (100%) rename {internal => pkg/deppy}/solver/tracer.go (100%) rename {internal => pkg/deppy}/solver/variable.go (100%) rename {internal => pkg/deppy}/solver/zz_search_test.go (100%) diff --git a/cmd/dimacs/cmd.go b/cmd/dimacs/cmd.go index 25fcc88..fb7d1be 100644 --- a/cmd/dimacs/cmd.go +++ b/cmd/dimacs/cmd.go @@ -7,6 +7,7 @@ import ( "github.com/spf13/cobra" + "github.com/operator-framework/deppy/pkg/deppy" "github.com/operator-framework/deppy/pkg/deppy/solver" ) @@ -52,20 +53,29 @@ func solve(path string) error { } // build solver - so := solver.NewDeppySolver() + so, err := solver.New() + if err != nil { + return err + } // get solution vars, err := GenerateVariables(dimacs) if err != nil { return fmt.Errorf("error generating variables: %s", err) } - solution, err := so.Solve(vars) + selection, err := so.Solve(vars) if err != nil { fmt.Printf("no solution found: %s\n", err) } else { + selected := map[deppy.Identifier]struct{}{} + for _, variable := range selection { + selected[variable.Identifier()] = struct{}{} + } + fmt.Println("solution found:") for _, variable := range vars { - fmt.Printf("%s = %t\n", variable.Identifier(), solution.IsSelected(variable.Identifier())) + _, ok := selected[variable.Identifier()] + fmt.Printf("%s = %t\n", variable.Identifier(), ok) } } diff --git a/cmd/sudoku/cmd.go b/cmd/sudoku/cmd.go index 5a69a2b..04e920a 100644 --- a/cmd/sudoku/cmd.go +++ b/cmd/sudoku/cmd.go @@ -22,19 +22,22 @@ func NewSudokuCommand() *cobra.Command { func solve() error { // build solver - so := solver.NewDeppySolver() + so, err := solver.New() + if err != nil { + return err + } // get solution vars, err := GenerateVariables() if err != nil { return err } - solution, err := so.Solve(vars) + selection, err := so.Solve(vars) if err != nil { fmt.Println("no solution found") } else { selected := map[deppy.Identifier]struct{}{} - for _, variable := range solution.SelectedVariables() { + for _, variable := range selection { selected[variable.Identifier()] = struct{}{} } for row := 0; row < 9; row++ { diff --git a/internal/solver/bench_test.go b/pkg/deppy/solver/bench_test.go similarity index 100% rename from internal/solver/bench_test.go rename to pkg/deppy/solver/bench_test.go diff --git a/internal/solver/constraints.go b/pkg/deppy/solver/constraints.go similarity index 100% rename from internal/solver/constraints.go rename to pkg/deppy/solver/constraints.go diff --git a/internal/solver/constraints_test.go b/pkg/deppy/solver/constraints_test.go similarity index 100% rename from internal/solver/constraints_test.go rename to pkg/deppy/solver/constraints_test.go diff --git a/internal/solver/doc.go b/pkg/deppy/solver/doc.go similarity index 100% rename from internal/solver/doc.go rename to pkg/deppy/solver/doc.go diff --git a/internal/solver/lit_mapping.go b/pkg/deppy/solver/lit_mapping.go similarity index 100% rename from internal/solver/lit_mapping.go rename to pkg/deppy/solver/lit_mapping.go diff --git a/internal/solver/search.go b/pkg/deppy/solver/search.go similarity index 100% rename from internal/solver/search.go rename to pkg/deppy/solver/search.go diff --git a/internal/solver/search_test.go b/pkg/deppy/solver/search_test.go similarity index 100% rename from internal/solver/search_test.go rename to pkg/deppy/solver/search_test.go diff --git a/internal/solver/solve.go b/pkg/deppy/solver/solve.go similarity index 100% rename from internal/solver/solve.go rename to pkg/deppy/solver/solve.go diff --git a/internal/solver/solve_test.go b/pkg/deppy/solver/solve_test.go similarity index 100% rename from internal/solver/solve_test.go rename to pkg/deppy/solver/solve_test.go diff --git a/internal/solver/tracer.go b/pkg/deppy/solver/tracer.go similarity index 100% rename from internal/solver/tracer.go rename to pkg/deppy/solver/tracer.go diff --git a/internal/solver/variable.go b/pkg/deppy/solver/variable.go similarity index 100% rename from internal/solver/variable.go rename to pkg/deppy/solver/variable.go diff --git a/internal/solver/zz_search_test.go b/pkg/deppy/solver/zz_search_test.go similarity index 100% rename from internal/solver/zz_search_test.go rename to pkg/deppy/solver/zz_search_test.go