Class: DepSelector::DependencyGraph

Inherits:
Object
  • Object
show all
Defined in:
lib/dep_selector/dependency_graph.rb

Constant Summary collapse

DebugOptionFile =
"/tmp/DepSelectorDebugOn"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDependencyGraph

Returns a new instance of DependencyGraph.



33
34
35
# File 'lib/dep_selector/dependency_graph.rb', line 33

def initialize
  @packages = {}
end

Instance Attribute Details

#packagesObject (readonly)

Returns the value of attribute packages.



31
32
33
# File 'lib/dep_selector/dependency_graph.rb', line 31

def packages
  @packages
end

Instance Method Details

#cloneObject

Does a mostly deep copy of this graph, creating new Package, PackageVersion, and Dependency objects in the copy graph. Version and VersionConstraint objects are re-used from the existing graph.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/dep_selector/dependency_graph.rb', line 89

def clone
  copy = self.class.new
  @packages.each do |name, package|
    copy_package = copy.package(name)

    package.versions.each do |package_version|
      copy_pkg_version = copy_package.add_version(package_version.version)
      package_version.dependencies.each do |pkg_vers_dep|
        dep_pkg_name = pkg_vers_dep.package.name
        copy_dependency = DepSelector::Dependency.new(copy.package(dep_pkg_name), pkg_vers_dep.constraint)
        copy_pkg_version.dependencies << copy_dependency
      end
    end
  end
  copy
end

#each_packageObject



41
42
43
44
45
# File 'lib/dep_selector/dependency_graph.rb', line 41

def each_package
  packages.each do |name, pkg|
    yield pkg
  end
end

#gecode_model_varsObject



78
79
80
# File 'lib/dep_selector/dependency_graph.rb', line 78

def gecode_model_vars
  packages.inject({}){|acc, elt| acc[elt.first] = elt.last.gecode_model_var ; acc }
end

#gecode_wrapperObject



47
48
49
50
# File 'lib/dep_selector/dependency_graph.rb', line 47

def gecode_wrapper
  raise "Must invoke generate_gecode_wrapper_constraints before attempting to access gecode_wrapper" unless @gecode_wrapper
  @gecode_wrapper
end

#generate_gecode_wrapper_constraints(packages_to_include_in_solve = nil) ⇒ Object

Note: only invoke this method once all Packages and PackageVersions have been added.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/dep_selector/dependency_graph.rb', line 54

def generate_gecode_wrapper_constraints(packages_to_include_in_solve=nil)
  unless @gecode_wrapper
    packages_in_solve =
      if packages_to_include_in_solve
        packages_to_include_in_solve
      else
        packages.map{ |name, pkg| pkg }
      end

    logId = SecureRandom.uuid
    debugFlag = DebugOptionFile && File::exists?(DebugOptionFile)
    Debug.log.level = Logger::INFO unless debugFlag
    Debug.log.formatter = proc do |severity, datetime, progname, msg|
      "#{logId}: #{msg}\n"
    end

    # In addition to all the packages that the user specified,
    # there is a "ghost" package that contains the solution
    # constraints. See Selector#solve for more information.
    @gecode_wrapper = GecodeWrapper.new(packages_in_solve.size + 1, logId, debugFlag)
    packages_in_solve.each{ |pkg| pkg.generate_gecode_wrapper_constraints }
  end
end

#package(name) ⇒ Object



37
38
39
# File 'lib/dep_selector/dependency_graph.rb', line 37

def package(name)
  packages.has_key?(name) ? packages[name] : (packages[name]=Package.new(self, name))
end

#to_s(incl_densely_packed_versions = false) ⇒ Object



82
83
84
# File 'lib/dep_selector/dependency_graph.rb', line 82

def to_s(incl_densely_packed_versions = false)
  packages.keys.sort.map{|name| packages[name].to_s(incl_densely_packed_versions)}.join("\n")
end