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

[revise] Remove Entity and EntitySource #95

Closed
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
2 changes: 1 addition & 1 deletion cmd/dimacs/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func solve(path string) error {
}

// build solver
so, err := solver.NewDeppySolver(NewDimacsEntitySource(dimacs), NewDimacsVariableSource(dimacs))
so, err := solver.NewDeppySolver(NewDimacsVariableSource(dimacs))
if err != nil {
return err
}
Expand Down
11 changes: 4 additions & 7 deletions cmd/dimacs/dimacs_constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,13 @@ func NewDimacsVariableSource(dimacs *Dimacs) *ConstraintGenerator {
}
}

func (d *ConstraintGenerator) GetVariables(ctx context.Context, entitySource input.EntitySource) ([]deppy.Variable, error) {
func (d *ConstraintGenerator) GetVariables(ctx context.Context) ([]deppy.Variable, error) {
varMap := make(map[deppy.Identifier]*input.SimpleVariable, len(d.dimacs.variables))
variables := make([]deppy.Variable, 0, len(d.dimacs.variables))
if err := entitySource.Iterate(ctx, func(entity *input.Entity) error {
variable := input.NewSimpleVariable(entity.Identifier())

for _, id := range d.dimacs.variables {
variable := input.NewSimpleVariable(deppy.IdentifierFromString(id))
variables = append(variables, variable)
varMap[entity.Identifier()] = variable
return nil
}); err != nil {
return nil, err
}

// create constraints out of the clauses
Expand Down
24 changes: 0 additions & 24 deletions cmd/dimacs/dimacs_source.go

This file was deleted.

4 changes: 2 additions & 2 deletions cmd/sudoku/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func NewSudokuCommand() *cobra.Command {

func solve() error {
// build solver
sudoku := NewSudoku()
so, err := solver.NewDeppySolver(sudoku, sudoku)
sudoku := &Sudoku{}
so, err := solver.NewDeppySolver(sudoku)
if err != nil {
return err
}
Expand Down
26 changes: 3 additions & 23 deletions cmd/sudoku/sudoku.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@ import (
"context"
"fmt"
"math/rand"
"strconv"
"time"

"github.com/operator-framework/deppy/pkg/deppy"
"github.com/operator-framework/deppy/pkg/deppy/constraint"
"github.com/operator-framework/deppy/pkg/deppy/input"
)

var _ input.EntitySource = &Sudoku{}
var _ input.VariableSource = &Sudoku{}

// TODO: this could be an empty struct
type Sudoku struct {
*input.CacheEntitySource
variables []deppy.Variable
}

func GetID(row int, col int, num int) deppy.Identifier {
Expand All @@ -26,26 +25,7 @@ func GetID(row int, col int, num int) deppy.Identifier {
return deppy.Identifier(fmt.Sprintf("%03d", n))
}

func NewSudoku() *Sudoku {
var entities = make(map[deppy.Identifier]input.Entity, 9*9*9)
for row := 0; row < 9; row++ {
for col := 0; col < 9; col++ {
for num := 0; num < 9; num++ {
id := GetID(row, col, num)
entities[id] = *input.NewEntity(id, map[string]string{
"row": strconv.Itoa(row),
"col": strconv.Itoa(col),
"num": strconv.Itoa(num),
})
}
}
}
return &Sudoku{
CacheEntitySource: input.NewCacheQuerier(entities),
}
}

func (s Sudoku) GetVariables(ctx context.Context, _ input.EntitySource) ([]deppy.Variable, error) {
func (s Sudoku) GetVariables(ctx context.Context) ([]deppy.Variable, error) {
// adapted from: https://github.com/go-air/gini/blob/871d828a26852598db2b88f436549634ba9533ff/sudoku_test.go#L10
variables := make(map[deppy.Identifier]*input.SimpleVariable, 0)
inorder := make([]deppy.Variable, 0)
Expand Down
58 changes: 0 additions & 58 deletions pkg/deppy/input/cache_entity_source.go

This file was deleted.

21 changes: 0 additions & 21 deletions pkg/deppy/input/entity.go

This file was deleted.

31 changes: 0 additions & 31 deletions pkg/deppy/input/entity_source.go

This file was deleted.

Loading