Skip to content

Commit

Permalink
Export internal solver
Browse files Browse the repository at this point in the history
Signed-off-by: Mikalai Radchuk <mradchuk@redhat.com>
  • Loading branch information
m1kola committed Dec 4, 2023
1 parent aaf08d6 commit f6d68ad
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 6 deletions.
16 changes: 13 additions & 3 deletions cmd/dimacs/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/spf13/cobra"

"github.com/operator-framework/deppy/pkg/deppy"
"github.com/operator-framework/deppy/pkg/deppy/solver"
)

Expand Down Expand Up @@ -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)
}
}

Expand Down
9 changes: 6 additions & 3 deletions cmd/sudoku/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++ {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit f6d68ad

Please sign in to comment.