mirror of
https://github.com/mudler/luet.git
synced 2025-08-31 06:35:12 +00:00
Cleanup
This commit is contained in:
@@ -84,7 +84,6 @@ func (p *DefaultPackage) Encode() (string, error) {
|
||||
crc32q := crc32.MakeTable(0xD5828281)
|
||||
ID := fmt.Sprintf("%08x\n", crc32.Checksum([]byte(enc), crc32q))
|
||||
Database[ID] = base64.StdEncoding.EncodeToString(res)
|
||||
fmt.Println("Package Encoded:", p.Name+" => "+ID)
|
||||
return ID, nil
|
||||
}
|
||||
|
||||
@@ -144,17 +143,9 @@ func (p *DefaultPackage) BuildFormula() ([]bf.Formula, error) {
|
||||
}
|
||||
|
||||
A := bf.Var(encodedA)
|
||||
|
||||
var formulas []bf.Formula
|
||||
|
||||
if p.IsSet {
|
||||
//formulas = append(formulas, A)
|
||||
//f = bf.And(f, bf.Var(encodedA))
|
||||
} else {
|
||||
//f = bf.And(f, bf.Not(bf.Var(encodedA)))
|
||||
}
|
||||
|
||||
//formulas = append(formulas, A)
|
||||
|
||||
for _, required := range p.PackageRequires {
|
||||
encodedB, err := required.IsFlagged(true).Encode()
|
||||
if err != nil {
|
||||
@@ -185,17 +176,6 @@ func (p *DefaultPackage) BuildFormula() ([]bf.Formula, error) {
|
||||
return nil, err
|
||||
}
|
||||
formulas = append(formulas, f...)
|
||||
//if required.Flagged() {
|
||||
// f, err := required.BuildFormula()
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// formulas = append(formulas, bf.Not(bf.And(f...)))
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
//return []bf.Formula{bf.And(formulas...)}, nil
|
||||
return formulas, nil
|
||||
//return []bf.Formula{bf.Implies(A, bf.And(formulas...))}, nil
|
||||
}
|
||||
|
@@ -27,25 +27,12 @@ type PackageAssert struct {
|
||||
func DecodeModel(model map[string]bool) ([]PackageAssert, error) {
|
||||
ass := make([]PackageAssert, 0)
|
||||
for k, v := range model {
|
||||
if a, err := pkg.DecodePackage(k); err == nil {
|
||||
|
||||
// fmt.Println("Flagged", v, a.Flagged())
|
||||
// if v {
|
||||
// fmt.Println("To flag", a)
|
||||
// }
|
||||
// if a.Flagged() && !v {
|
||||
// a.IsFlagged(false)
|
||||
// } else if !a.Flagged() && v {
|
||||
// fmt.Println("To flag ", a)
|
||||
// a.IsFlagged(true)
|
||||
// }
|
||||
|
||||
//if a.State == common.STATE_CURRENT {
|
||||
ass = append(ass, PackageAssert{Package: a, Value: v})
|
||||
//} // Else, there was a state transition between Initial state and current run
|
||||
} else {
|
||||
a, err := pkg.DecodePackage(k)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
}
|
||||
ass = append(ass, PackageAssert{Package: a, Value: v})
|
||||
}
|
||||
return ass, nil
|
||||
}
|
||||
|
@@ -17,7 +17,6 @@ package solver
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/crillab/gophersat/bf"
|
||||
pkg "gitlab.com/mudler/luet/pkg/package"
|
||||
@@ -29,14 +28,12 @@ type PackageSolver interface {
|
||||
BuildFormula() (bf.Formula, error)
|
||||
Solve() ([]PackageAssert, error)
|
||||
Apply() (map[string]bool, bf.Formula, error)
|
||||
SetSteps(int)
|
||||
SetWorld(p []pkg.Package)
|
||||
}
|
||||
type Solver struct {
|
||||
Wanted []pkg.Package
|
||||
Installed []pkg.Package
|
||||
World []pkg.Package
|
||||
Steps int
|
||||
}
|
||||
|
||||
func NewSolver(pcoll []pkg.Package, init []pkg.Package, w []pkg.Package) PackageSolver {
|
||||
@@ -52,10 +49,6 @@ func NewSolver(pcoll []pkg.Package, init []pkg.Package, w []pkg.Package) Package
|
||||
return &Solver{Wanted: pcoll, Installed: init, World: w}
|
||||
}
|
||||
|
||||
func (s *Solver) SetSteps(st int) {
|
||||
s.Steps = st
|
||||
}
|
||||
|
||||
func (s *Solver) SetWorld(p []pkg.Package) {
|
||||
s.World = p
|
||||
}
|
||||
@@ -99,7 +92,6 @@ func (s *Solver) BuildFormula() (bf.Formula, error) {
|
||||
}
|
||||
|
||||
}
|
||||
//return bf.And(r), nil
|
||||
return bf.And(formulas...), nil
|
||||
}
|
||||
|
||||
@@ -114,28 +106,9 @@ func (s *Solver) solve(f bf.Formula) (map[string]bool, bf.Formula, error) {
|
||||
|
||||
func (s *Solver) Apply() (map[string]bool, bf.Formula, error) {
|
||||
f, err := s.BuildFormula()
|
||||
fmt.Println("Steps", s.Steps, f)
|
||||
if err != nil {
|
||||
return map[string]bool{}, nil, err
|
||||
}
|
||||
|
||||
// if s.Steps != 0 {
|
||||
// for i := s.Steps; i >= 0; i-- {
|
||||
// f, err = s.BuildFormula()
|
||||
// if err != nil {
|
||||
// return map[string]bool{}, nil, err
|
||||
// }
|
||||
// model, _, err := s.solve(f)
|
||||
// if err != nil {
|
||||
// return map[string]bool{}, nil, err
|
||||
// }
|
||||
// fmt.Println("Step ", i, model)
|
||||
|
||||
// ass := DecodeModel(model)
|
||||
// s.Installed = append(s.Installed, ass...)
|
||||
// }
|
||||
// }
|
||||
|
||||
return s.solve(f)
|
||||
}
|
||||
|
||||
@@ -145,14 +118,5 @@ func (s *Solver) Solve() ([]PackageAssert, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// for _, wanted := range s.Wanted {
|
||||
// encodedW, err := wanted.Encode()
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// model[encodedW] = true
|
||||
// fmt.Println("adding wanted", model)
|
||||
|
||||
// }
|
||||
return DecodeModel(model)
|
||||
}
|
||||
|
@@ -33,7 +33,6 @@ var _ = Describe("Solver", func() {
|
||||
C := pkg.NewPackage("C", "", []*pkg.DefaultPackage{}, []*pkg.DefaultPackage{})
|
||||
|
||||
s := NewSolver([]pkg.Package{A}, []pkg.Package{C}, []pkg.Package{A, B, C}) // XXX: goes fatal with odd numbers of cnf ?
|
||||
s.SetSteps(1)
|
||||
solution, err := s.Solve()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(solution).To(ContainElement(PackageAssert{Package: A.IsFlagged(true), Value: true}))
|
||||
|
Reference in New Issue
Block a user