Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚠️ Remove DeppySolver wrapper and export internal solver instead #165

Merged
merged 2 commits into from
Dec 4, 2023
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var BenchmarkInput = func() []deppy.Variable {
nConflict = 3
)

random := rand.New(rand.NewSource(seed))
random := rand.New(rand.NewSource(seed)) //nolint:gosec // G404: Use of weak random number generator (math/rand instead of crypto/rand) is ignored as this is not security-sensitive.

id := func(i int) deppy.Identifier {
return deppy.Identifier(strconv.Itoa(i))
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.
72 changes: 0 additions & 72 deletions pkg/deppy/solver/solver.go

This file was deleted.

176 changes: 0 additions & 176 deletions pkg/deppy/solver/solver_test.go

This file was deleted.

File renamed without changes.
File renamed without changes.