Class: DepSelector::GecodeWrapper
- Inherits:
-
Object
- Object
- DepSelector::GecodeWrapper
- Defined in:
- lib/dep_selector/gecode_wrapper.rb
Constant Summary collapse
- DontCareConstraint =
-1
- NoMatchConstraint =
-2
- DumpStatistics =
true
Instance Attribute Summary collapse
-
#debug_logs_on ⇒ Object
readonly
Returns the value of attribute debug_logs_on.
-
#gecode_problem ⇒ Object
readonly
Returns the value of attribute gecode_problem.
Class Method Summary collapse
Instance Method Summary collapse
- #add_package(min, max, current_version) ⇒ Object
- #add_version_constraint(package_id, version, dependent_package_id, min_dependent_version, max_dependent_version) ⇒ Object
- #check_package_id(package_id, param_name) ⇒ Object
- #dump ⇒ Object
- #dump_package_var(package_id) ⇒ Object
- #get_package_max(package_id) ⇒ Object
- #get_package_min(package_id) ⇒ Object
- #get_package_version(package_id) ⇒ Object
-
#initialize(problem_or_package_count, debug = false) ⇒ GecodeWrapper
constructor
This insures that we properly deallocate the c++ class at the heart of dep_gecode.
- #is_package_disabled?(package_id) ⇒ Boolean
- #mark_preferred_to_be_at_latest(package_id, weight) ⇒ Object
- #mark_required(package_id) ⇒ Object
- #package_count ⇒ Object
- #package_disabled_count ⇒ Object
- #size ⇒ Object
- #solve ⇒ Object
Constructor Details
#initialize(problem_or_package_count, debug = false) ⇒ GecodeWrapper
This insures that we properly deallocate the c++ class at the heart of dep_gecode. modeled after www.mikeperham.com/2010/02/24/the-trouble-with-ruby-finalizers/
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dep_selector/gecode_wrapper.rb', line 34 def initialize(problem_or_package_count, debug=false) if (problem_or_package_count.is_a?(Numeric)) logId = UUIDTools::UUID.random_create().to_str() @debug_logs_on = debug @gecode_problem = Dep_gecode.VersionProblemCreate(problem_or_package_count, DumpStatistics, debug, logId) else @gecode_problem = problem_or_package_count end ObjectSpace.define_finalizer(self, self.class.finalize(@gecode_problem)) end |
Instance Attribute Details
#debug_logs_on ⇒ Object (readonly)
Returns the value of attribute debug_logs_on.
27 28 29 |
# File 'lib/dep_selector/gecode_wrapper.rb', line 27 def debug_logs_on @debug_logs_on end |
#gecode_problem ⇒ Object (readonly)
Returns the value of attribute gecode_problem.
26 27 28 |
# File 'lib/dep_selector/gecode_wrapper.rb', line 26 def gecode_problem @gecode_problem end |
Class Method Details
.finalize(gecode_problem) ⇒ Object
44 45 46 |
# File 'lib/dep_selector/gecode_wrapper.rb', line 44 def self.finalize(gecode_problem) proc { Dep_gecode.VersionProblemDestroy(gecode_problem) } end |
Instance Method Details
#add_package(min, max, current_version) ⇒ Object
60 61 62 63 |
# File 'lib/dep_selector/gecode_wrapper.rb', line 60 def add_package(min, max, current_version) raise "Gecode internal failure" if gecode_problem.nil? Dep_gecode.AddPackage(gecode_problem, min, max, current_version) end |
#add_version_constraint(package_id, version, dependent_package_id, min_dependent_version, max_dependent_version) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/dep_selector/gecode_wrapper.rb', line 65 def add_version_constraint(package_id, version, dependent_package_id, min_dependent_version, max_dependent_version) raise "Gecode internal failure" if gecode_problem.nil? check_package_id(package_id, "package_id") check_package_id(dependent_package_id, "dependent_package_id") # Valid package versions are between -1 and its max (-1 means # don't care, meaning it doesn't need to be assigned). To # indicate constraints that match no versions, -2 is used, since # it's not a valid assignment of the variable; thus, any branch # that assigns -2 will fail. # # This mechanism is also used when a dependent package has no # versions, which only happens if the dependency's package is # auto-vivified when creating the parent PackageVersion's # dependency but with no corresponding set of PackageVersions # (i.e. it's an invalid deendency, because it does not exist in # the dependency graph). Again, we won't abort immediately, but # we'll add a constraint to the package that makes exploring # that portion of the solution space unsatisfiable. Thus it is # impossible to find solutions dependent on non-existent # packages. min = min_dependent_version || NoMatchConstraint max = max_dependent_version || NoMatchConstraint Dep_gecode.AddVersionConstraint(gecode_problem, package_id, version, dependent_package_id, min, max) # if the package was constrained to no versions, hint to the # solver that in the event of failure, it should prefer to # indicate constraints on dependent_package_id as the culprit if min == NoMatchConstraint && max == NoMatchConstraint Dep_gecode.MarkPackageSuspicious(gecode_problem, dependent_package_id) end end |
#check_package_id(package_id, param_name) ⇒ Object
48 49 50 |
# File 'lib/dep_selector/gecode_wrapper.rb', line 48 def check_package_id(package_id, param_name) raise "Gecode #{param_name} is out of range #{package_id}" unless (package_id >= 0 && package_id < self.size()) end |
#dump ⇒ Object
119 120 121 122 |
# File 'lib/dep_selector/gecode_wrapper.rb', line 119 def dump() raise "Gecode internal failure" if gecode_problem.nil? Dep_gecode.VersionProblemDump(gecode_problem) end |
#dump_package_var(package_id) ⇒ Object
123 124 125 126 127 |
# File 'lib/dep_selector/gecode_wrapper.rb', line 123 def dump_package_var(package_id) raise "Gecode internal failure" if gecode_problem.nil? check_package_id(package_id, "package_id") Dep_gecode.VersionProblemPrintPackageVar(gecode_problem, package_id) end |
#get_package_max(package_id) ⇒ Object
109 110 111 112 113 |
# File 'lib/dep_selector/gecode_wrapper.rb', line 109 def get_package_max(package_id) raise "Gecode internal failure" if gecode_problem.nil? check_package_id(package_id, "package_id") Dep_gecode.GetPackageMax(gecode_problem, package_id) end |
#get_package_min(package_id) ⇒ Object
114 115 116 117 118 |
# File 'lib/dep_selector/gecode_wrapper.rb', line 114 def get_package_min(package_id) raise "Gecode internal failure" if gecode_problem.nil? check_package_id(package_id, "package_id") Dep_gecode.GetPackageMin(gecode_problem, package_id) end |
#get_package_version(package_id) ⇒ Object
98 99 100 101 102 |
# File 'lib/dep_selector/gecode_wrapper.rb', line 98 def get_package_version(package_id) raise "Gecode internal failure" if gecode_problem.nil? check_package_id(package_id, "package_id") Dep_gecode.GetPackageVersion(gecode_problem, package_id) end |
#is_package_disabled?(package_id) ⇒ Boolean
103 104 105 106 107 |
# File 'lib/dep_selector/gecode_wrapper.rb', line 103 def is_package_disabled?(package_id) raise "Gecode internal failure" if gecode_problem.nil? check_package_id(package_id, "package_id") Dep_gecode.GetPackageDisabledState(gecode_problem, package_id); end |
#mark_preferred_to_be_at_latest(package_id, weight) ⇒ Object
140 141 142 143 144 |
# File 'lib/dep_selector/gecode_wrapper.rb', line 140 def mark_preferred_to_be_at_latest(package_id, weight) raise "Gecode internal failure (mark_preferred_to_be_at_latest)" if gecode_problem.nil? check_package_id(package_id, "package_id") Dep_gecode.MarkPackagePreferredToBeAtLatest(gecode_problem, package_id, weight); end |
#mark_required(package_id) ⇒ Object
134 135 136 137 138 |
# File 'lib/dep_selector/gecode_wrapper.rb', line 134 def mark_required(package_id) raise "Gecode internal failure (mark_required)" if gecode_problem.nil? check_package_id(package_id, "package_id") Dep_gecode.MarkPackageRequired(gecode_problem, package_id); end |
#package_count ⇒ Object
56 57 58 59 |
# File 'lib/dep_selector/gecode_wrapper.rb', line 56 def package_count() raise "Gecode internal failure" if gecode_problem.nil? Dep_gecode.VersionProblemPackageCount(gecode_problem) end |
#package_disabled_count ⇒ Object
129 130 131 132 |
# File 'lib/dep_selector/gecode_wrapper.rb', line 129 def package_disabled_count raise "Gecode internal failure (package disabled count)" if gecode_problem.nil? Dep_gecode.GetDisabledVariableCount(gecode_problem) end |
#size ⇒ Object
52 53 54 55 |
# File 'lib/dep_selector/gecode_wrapper.rb', line 52 def size() raise "Gecode internal failure" if gecode_problem.nil? Dep_gecode.VersionProblemSize(gecode_problem) end |
#solve ⇒ Object
146 147 148 149 150 151 152 153 |
# File 'lib/dep_selector/gecode_wrapper.rb', line 146 def solve() raise "Gecode internal failure (solve)" if gecode_problem.nil? solution = GecodeWrapper.new(Dep_gecode.Solve(gecode_problem), debug_logs_on) raise "Gecode internal failure (no solution found)" if (solution.nil?) raise Exceptions::NoSolutionFound.new(solution) if solution.package_disabled_count > 0 solution end |