Class: Bundler::PubGrub::PartialSolution

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/vendor/pub_grub/lib/pub_grub/partial_solution.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePartialSolution

Returns a new instance of PartialSolution.



8
9
10
11
12
13
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/partial_solution.rb', line 8

def initialize
  reset!

  @attempted_solutions = 1
  @backtracking = false
end

Instance Attribute Details

#assignmentsObject (readonly)

Returns the value of attribute assignments.



5
6
7
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/partial_solution.rb', line 5

def assignments
  @assignments
end

#attempted_solutionsObject (readonly)

Returns the value of attribute attempted_solutions.



6
7
8
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/partial_solution.rb', line 6

def attempted_solutions
  @attempted_solutions
end

#decisionsObject (readonly)

Returns the value of attribute decisions.



5
6
7
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/partial_solution.rb', line 5

def decisions
  @decisions
end

Instance Method Details

#backtrack(previous_level) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/partial_solution.rb', line 62

def backtrack(previous_level)
  @backtracking = true

  new_assignments = assignments.select do |assignment|
    assignment.decision_level <= previous_level
  end

  new_decisions = Hash[decisions.first(previous_level)]

  reset!

  @decisions = new_decisions

  new_assignments.each do |assignment|
    add_assignment(assignment)
  end
end

#decide(package, version) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/partial_solution.rb', line 53

def decide(package, version)
  @attempted_solutions += 1 if @backtracking
  @backtracking = false;

  decisions[package] = version
  assignment = Assignment.decision(package, version, decision_level, assignments.length)
  add_assignment(assignment)
end

#decision_levelObject



15
16
17
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/partial_solution.rb', line 15

def decision_level
  @decisions.length
end

#derive(term, cause) ⇒ Object



31
32
33
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/partial_solution.rb', line 31

def derive(term, cause)
  add_assignment(Assignment.new(term, cause, decision_level, assignments.length))
end

#relation(term) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/partial_solution.rb', line 19

def relation(term)
  package = term.package
  return :overlap if !@terms.key?(package)

  @relation_cache[package][term] ||=
    @terms[package].relation(term)
end

#satisfier(term) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/partial_solution.rb', line 35

def satisfier(term)
  assignment =
    @assignments_by[term.package].bsearch do |assignment_by|
      @cumulative_assignments[assignment_by].satisfies?(term)
    end

  assignment || raise("#{term} unsatisfied")
end

#satisfies?(term) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/partial_solution.rb', line 27

def satisfies?(term)
  relation(term) == :subset
end

#unsatisfiedObject

A list of unsatisfied terms



45
46
47
48
49
50
51
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/partial_solution.rb', line 45

def unsatisfied
  @required.keys.reject do |package|
    @decisions.key?(package)
  end.map do |package|
    @terms[package]
  end
end