puppet 0.24.1 → 0.24.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (266) hide show
  1. data/CHANGELOG +94 -0
  2. data/Rakefile +0 -4
  3. data/bin/puppet +18 -10
  4. data/bin/puppetd +1 -1
  5. data/bin/puppetdoc +14 -4
  6. data/bin/puppetmasterd +1 -1
  7. data/bin/puppetrun +3 -8
  8. data/bin/ralsh +12 -11
  9. data/conf/freebsd/puppetd +1 -1
  10. data/conf/freebsd/puppetmasterd +1 -1
  11. data/conf/gentoo/puppet/puppet.conf +29 -0
  12. data/conf/namespaceauth.conf +20 -0
  13. data/conf/redhat/puppet.spec +4 -1
  14. data/conf/solaris/smf/puppetd.xml +1 -1
  15. data/conf/solaris/smf/puppetmasterd.xml +1 -1
  16. data/conf/suse/puppet.spec +10 -8
  17. data/examples/root/etc/puppet/{puppetmasterd.conf → puppet.conf} +6 -3
  18. data/ext/logcheck/puppet +7 -0
  19. data/ext/puppet-test +28 -5
  20. data/lib/puppet.rb +2 -1
  21. data/lib/puppet/defaults.rb +12 -5
  22. data/lib/puppet/dsl.rb +43 -45
  23. data/lib/puppet/external/{gratr/rdot.rb → dot.rb} +0 -0
  24. data/lib/puppet/external/nagios.rb +50 -0
  25. data/lib/puppet/external/nagios/base.rb +421 -0
  26. data/lib/puppet/external/nagios/parser.rb +816 -0
  27. data/lib/puppet/file_serving/file_base.rb +16 -3
  28. data/lib/puppet/file_serving/metadata.rb +29 -11
  29. data/lib/puppet/indirector/terminus.rb +1 -0
  30. data/lib/puppet/metatype/closure.rb +4 -0
  31. data/lib/puppet/metatype/evaluation.rb +2 -17
  32. data/lib/puppet/metatype/metaparams.rb +1 -1
  33. data/lib/puppet/network.rb +3 -0
  34. data/lib/puppet/network/client.rb +4 -5
  35. data/lib/puppet/network/client/master.rb +10 -7
  36. data/lib/puppet/network/handler/fileserver.rb +22 -45
  37. data/lib/puppet/network/http_pool.rb +3 -0
  38. data/lib/puppet/network/http_server/mongrel.rb +7 -1
  39. data/lib/puppet/network/http_server/webrick.rb +4 -3
  40. data/lib/puppet/network/xmlrpc/client.rb +12 -1
  41. data/lib/puppet/node/catalog.rb +51 -40
  42. data/lib/puppet/parser/ast.rb +27 -49
  43. data/lib/puppet/parser/ast/astarray.rb +5 -24
  44. data/lib/puppet/parser/ast/caseopt.rb +4 -4
  45. data/lib/puppet/parser/ast/casestatement.rb +4 -5
  46. data/lib/puppet/parser/ast/collection.rb +3 -5
  47. data/lib/puppet/parser/ast/collexpr.rb +3 -5
  48. data/lib/puppet/parser/ast/definition.rb +148 -159
  49. data/lib/puppet/parser/ast/else.rb +2 -3
  50. data/lib/puppet/parser/ast/function.rb +3 -10
  51. data/lib/puppet/parser/ast/hostclass.rb +66 -59
  52. data/lib/puppet/parser/ast/ifstatement.rb +4 -5
  53. data/lib/puppet/parser/ast/leaf.rb +6 -6
  54. data/lib/puppet/parser/ast/node.rb +26 -58
  55. data/lib/puppet/parser/ast/resource.rb +5 -7
  56. data/lib/puppet/parser/ast/resource_defaults.rb +2 -4
  57. data/lib/puppet/parser/ast/resource_override.rb +4 -6
  58. data/lib/puppet/parser/ast/resource_reference.rb +2 -4
  59. data/lib/puppet/parser/ast/resourceparam.rb +2 -4
  60. data/lib/puppet/parser/ast/selector.rb +5 -6
  61. data/lib/puppet/parser/ast/tag.rb +2 -4
  62. data/lib/puppet/parser/ast/vardef.rb +3 -4
  63. data/lib/puppet/parser/collector.rb +5 -5
  64. data/lib/puppet/parser/{compile.rb → compiler.rb} +69 -107
  65. data/lib/puppet/parser/functions.rb +3 -3
  66. data/lib/puppet/parser/interpreter.rb +32 -23
  67. data/lib/puppet/parser/lexer.rb +391 -282
  68. data/lib/puppet/parser/parser.rb +5 -4
  69. data/lib/puppet/parser/parser_support.rb +3 -6
  70. data/lib/puppet/parser/resource.rb +24 -36
  71. data/lib/puppet/parser/resource/param.rb +1 -1
  72. data/lib/puppet/parser/resource/reference.rb +7 -3
  73. data/lib/puppet/parser/scope.rb +12 -7
  74. data/lib/puppet/parser/templatewrapper.rb +1 -1
  75. data/lib/puppet/pgraph.rb +9 -98
  76. data/lib/puppet/provider/interface/redhat.rb +65 -65
  77. data/lib/puppet/provider/mount/parsed.rb +1 -1
  78. data/lib/puppet/provider/naginator.rb +55 -0
  79. data/lib/puppet/provider/nameservice/directoryservice.rb +6 -7
  80. data/lib/puppet/provider/package/fink.rb +0 -2
  81. data/lib/puppet/provider/package/gem.rb +9 -5
  82. data/lib/puppet/provider/package/openbsd.rb +1 -1
  83. data/lib/puppet/provider/package/pkgdmg.rb +3 -8
  84. data/lib/puppet/provider/package/portage.rb +4 -4
  85. data/lib/puppet/provider/package/yumhelper.py +8 -6
  86. data/lib/puppet/provider/parsedfile.rb +7 -1
  87. data/lib/puppet/provider/service/debian.rb +2 -0
  88. data/lib/puppet/provider/service/gentoo.rb +4 -0
  89. data/lib/puppet/provider/service/init.rb +1 -1
  90. data/lib/puppet/provider/sshkey/parsed.rb +2 -0
  91. data/lib/puppet/provider/user/useradd.rb +1 -1
  92. data/lib/puppet/rails.rb +4 -0
  93. data/lib/puppet/rails/database/001_add_created_at_to_all_tables.rb +17 -0
  94. data/lib/puppet/rails/fact_value.rb +4 -0
  95. data/lib/puppet/rails/host.rb +1 -2
  96. data/lib/puppet/rails/param_value.rb +4 -0
  97. data/lib/puppet/rails/resource_tag.rb +4 -0
  98. data/lib/puppet/rails/source_file.rb +4 -1
  99. data/lib/puppet/relationship.rb +5 -1
  100. data/lib/puppet/reports/tagmail.rb +12 -1
  101. data/lib/puppet/resource_reference.rb +1 -1
  102. data/lib/puppet/simple_graph.rb +78 -11
  103. data/lib/puppet/sslcertificates.rb +1 -1
  104. data/lib/puppet/sslcertificates/ca.rb +3 -3
  105. data/lib/puppet/transaction.rb +7 -4
  106. data/lib/puppet/transportable.rb +1 -1
  107. data/lib/puppet/type.rb +3 -10
  108. data/lib/puppet/type/cron.rb +18 -0
  109. data/lib/puppet/type/exec.rb +18 -12
  110. data/lib/puppet/type/{pfile.rb → file.rb} +66 -84
  111. data/lib/puppet/type/file/checksum.rb +271 -0
  112. data/lib/puppet/type/{pfile → file}/content.rb +10 -15
  113. data/lib/puppet/type/{pfile → file}/ensure.rb +15 -8
  114. data/lib/puppet/type/{pfile → file}/group.rb +0 -0
  115. data/lib/puppet/type/{pfile → file}/mode.rb +0 -0
  116. data/lib/puppet/type/{pfile → file}/owner.rb +0 -0
  117. data/lib/puppet/type/{pfile → file}/source.rb +34 -48
  118. data/lib/puppet/type/{pfile → file}/target.rb +0 -0
  119. data/lib/puppet/type/{pfile → file}/type.rb +0 -0
  120. data/lib/puppet/type/{pfilebucket.rb → filebucket.rb} +0 -0
  121. data/lib/puppet/type/host.rb +13 -0
  122. data/lib/puppet/type/mailalias.rb +1 -1
  123. data/lib/puppet/type/nagios_command.rb +3 -0
  124. data/lib/puppet/type/nagios_contact.rb +3 -0
  125. data/lib/puppet/type/nagios_contactgroup.rb +3 -0
  126. data/lib/puppet/type/nagios_host.rb +3 -0
  127. data/lib/puppet/type/nagios_hostextinfo.rb +3 -0
  128. data/lib/puppet/type/nagios_hostgroup.rb +3 -0
  129. data/lib/puppet/type/nagios_hostgroupescalation.rb +3 -0
  130. data/lib/puppet/type/nagios_service.rb +3 -0
  131. data/lib/puppet/type/nagios_servicedependency.rb +3 -0
  132. data/lib/puppet/type/nagios_serviceescalation.rb +3 -0
  133. data/lib/puppet/type/nagios_serviceextinfo.rb +3 -0
  134. data/lib/puppet/type/nagios_timeperiod.rb +3 -0
  135. data/lib/puppet/type/package.rb +4 -12
  136. data/lib/puppet/type/service.rb +9 -0
  137. data/lib/puppet/type/sshkey.rb +3 -3
  138. data/lib/puppet/util/autoload.rb +5 -5
  139. data/lib/puppet/util/checksums.rb +51 -13
  140. data/lib/puppet/util/constant_inflector.rb +14 -0
  141. data/lib/puppet/util/filetype.rb +1 -1
  142. data/lib/puppet/util/graph.rb +3 -9
  143. data/lib/puppet/util/nagios_maker.rb +57 -0
  144. data/lib/puppet/util/settings.rb +19 -16
  145. data/lib/puppet/util/tagging.rb +39 -0
  146. data/test/executables/puppetbin.rb +17 -0
  147. data/test/language/ast.rb +8 -58
  148. data/test/language/ast/casestatement.rb +3 -3
  149. data/test/language/ast/resource.rb +6 -7
  150. data/test/language/ast/resource_reference.rb +12 -12
  151. data/test/language/ast/selector.rb +2 -2
  152. data/test/language/ast/variable.rb +2 -2
  153. data/test/language/functions.rb +24 -24
  154. data/test/language/parser.rb +20 -8
  155. data/test/language/resource.rb +5 -42
  156. data/test/language/scope.rb +21 -37
  157. data/test/language/snippets.rb +7 -0
  158. data/test/lib/puppettest.rb +28 -14
  159. data/test/lib/puppettest/parsertesting.rb +10 -10
  160. data/test/lib/puppettest/support/resources.rb +1 -1
  161. data/test/network/client/master.rb +10 -0
  162. data/test/network/handler/fileserver.rb +51 -49
  163. data/test/network/server/webrick.rb +1 -1
  164. data/test/other/dsl.rb +3 -4
  165. data/test/other/transactions.rb +6 -4
  166. data/test/rails/ast.rb +2 -2
  167. data/test/rails/configuration.rb +1 -1
  168. data/test/rails/railsparameter.rb +2 -0
  169. data/test/rails/railsresource.rb +1 -0
  170. data/test/ral/manager/type.rb +4 -4
  171. data/test/ral/providers/cron/crontab.rb +3 -1
  172. data/test/ral/providers/package.rb +1 -1
  173. data/test/ral/{types → type}/basic.rb +2 -2
  174. data/test/ral/{types → type}/cron.rb +0 -0
  175. data/test/ral/{types → type}/exec.rb +42 -2
  176. data/test/ral/{types → type}/file.rb +34 -79
  177. data/test/ral/{types → type}/file/target.rb +0 -0
  178. data/test/ral/{types → type}/filebucket.rb +0 -0
  179. data/test/ral/{types → type}/fileignoresource.rb +0 -0
  180. data/test/ral/{types → type}/filesources.rb +8 -27
  181. data/test/ral/{types → type}/group.rb +0 -0
  182. data/test/ral/{types → type}/host.rb +16 -0
  183. data/test/ral/{types → type}/mailalias.rb +0 -0
  184. data/test/ral/{types → type}/parameter.rb +0 -0
  185. data/test/ral/{types → type}/port.rb +0 -0
  186. data/test/ral/{types → type}/property.rb +0 -0
  187. data/test/ral/{types → type}/resources.rb +0 -0
  188. data/test/ral/{types → type}/service.rb +0 -0
  189. data/test/ral/{types → type}/sshkey.rb +0 -0
  190. data/test/ral/{types → type}/tidy.rb +1 -0
  191. data/test/ral/{types → type}/user.rb +0 -0
  192. data/test/ral/{types → type}/yumrepo.rb +0 -0
  193. data/test/ral/{types → type}/zone.rb +0 -0
  194. data/test/util/autoload.rb +24 -5
  195. metadata +60 -107
  196. data/conf/gentoo/puppet/puppetca.conf +0 -29
  197. data/conf/gentoo/puppet/puppetd.conf +0 -29
  198. data/conf/gentoo/puppet/puppetmasterd.conf +0 -29
  199. data/examples/root/etc/puppet/puppetd.conf +0 -4
  200. data/lib/puppet/external/gratr.rb +0 -33
  201. data/lib/puppet/external/gratr/adjacency_graph.rb +0 -257
  202. data/lib/puppet/external/gratr/base.rb +0 -34
  203. data/lib/puppet/external/gratr/biconnected.rb +0 -116
  204. data/lib/puppet/external/gratr/chinese_postman.rb +0 -123
  205. data/lib/puppet/external/gratr/common.rb +0 -73
  206. data/lib/puppet/external/gratr/comparability.rb +0 -92
  207. data/lib/puppet/external/gratr/digraph.rb +0 -116
  208. data/lib/puppet/external/gratr/digraph_distance.rb +0 -185
  209. data/lib/puppet/external/gratr/dot.rb +0 -90
  210. data/lib/puppet/external/gratr/edge.rb +0 -145
  211. data/lib/puppet/external/gratr/graph.rb +0 -303
  212. data/lib/puppet/external/gratr/graph_api.rb +0 -83
  213. data/lib/puppet/external/gratr/import.rb +0 -44
  214. data/lib/puppet/external/gratr/labels.rb +0 -90
  215. data/lib/puppet/external/gratr/maximum_flow.rb +0 -64
  216. data/lib/puppet/external/gratr/search.rb +0 -409
  217. data/lib/puppet/external/gratr/strong_components.rb +0 -127
  218. data/lib/puppet/external/gratr/undirected_graph.rb +0 -153
  219. data/lib/puppet/rails/external/tagging/acts_as_taggable.rb +0 -62
  220. data/lib/puppet/rails/external/tagging/init.rb +0 -5
  221. data/lib/puppet/rails/external/tagging/tag.rb +0 -50
  222. data/lib/puppet/rails/external/tagging/tagging.rb +0 -12
  223. data/lib/puppet/rails/puppet_class.rb +0 -6
  224. data/lib/puppet/reference/node_source.rb +0 -9
  225. data/lib/puppet/reference/report.rb +0 -21
  226. data/lib/puppet/type/pfile/checksum.rb +0 -326
  227. data/test/language/ast/definition.rb +0 -166
  228. data/test/language/ast/hostclass.rb +0 -184
  229. data/test/language/compile.rb +0 -569
  230. data/test/language/lexer.rb +0 -276
  231. data/test/lib/mocha.rb +0 -19
  232. data/test/lib/mocha/any_instance_method.rb +0 -35
  233. data/test/lib/mocha/auto_verify.rb +0 -113
  234. data/test/lib/mocha/central.rb +0 -35
  235. data/test/lib/mocha/class_method.rb +0 -62
  236. data/test/lib/mocha/deprecation.rb +0 -22
  237. data/test/lib/mocha/exception_raiser.rb +0 -17
  238. data/test/lib/mocha/expectation.rb +0 -378
  239. data/test/lib/mocha/expectation_error.rb +0 -6
  240. data/test/lib/mocha/infinite_range.rb +0 -25
  241. data/test/lib/mocha/inspect.rb +0 -39
  242. data/test/lib/mocha/instance_method.rb +0 -8
  243. data/test/lib/mocha/is_a.rb +0 -9
  244. data/test/lib/mocha/metaclass.rb +0 -7
  245. data/test/lib/mocha/missing_expectation.rb +0 -27
  246. data/test/lib/mocha/mock.rb +0 -207
  247. data/test/lib/mocha/multiple_yields.rb +0 -20
  248. data/test/lib/mocha/no_yields.rb +0 -11
  249. data/test/lib/mocha/object.rb +0 -110
  250. data/test/lib/mocha/parameter_matchers.rb +0 -9
  251. data/test/lib/mocha/parameter_matchers/all_of.rb +0 -39
  252. data/test/lib/mocha/parameter_matchers/any_of.rb +0 -44
  253. data/test/lib/mocha/parameter_matchers/anything.rb +0 -30
  254. data/test/lib/mocha/parameter_matchers/has_entry.rb +0 -39
  255. data/test/lib/mocha/parameter_matchers/has_key.rb +0 -39
  256. data/test/lib/mocha/parameter_matchers/has_value.rb +0 -39
  257. data/test/lib/mocha/parameter_matchers/includes.rb +0 -37
  258. data/test/lib/mocha/pretty_parameters.rb +0 -28
  259. data/test/lib/mocha/return_values.rb +0 -31
  260. data/test/lib/mocha/setup_and_teardown.rb +0 -23
  261. data/test/lib/mocha/single_return_value.rb +0 -24
  262. data/test/lib/mocha/single_yield.rb +0 -18
  263. data/test/lib/mocha/standalone.rb +0 -32
  264. data/test/lib/mocha/stub.rb +0 -18
  265. data/test/lib/mocha/test_case_adapter.rb +0 -49
  266. data/test/lib/mocha/yield_parameters.rb +0 -31
@@ -1,123 +0,0 @@
1
- #--
2
- # Copyright (c) 2006 Shawn Patrick Garbett
3
- #
4
- # Redistribution and use in source and binary forms, with or without modification,
5
- # are permitted provided that the following conditions are met:
6
- #
7
- # * Redistributions of source code must retain the above copyright notice(s),
8
- # this list of conditions and the following disclaimer.
9
- # * Redistributions in binary form must reproduce the above copyright notice,
10
- # this list of conditions and the following disclaimer in the documentation
11
- # and/or other materials provided with the distribution.
12
- # * Neither the name of the Shawn Garbett nor the names of its contributors
13
- # may be used to endorse or promote products derived from this software
14
- # without specific prior written permission.
15
- #
16
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
- # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
- # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
- # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20
- # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
- # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
- # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
- # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
- # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
- #++
27
-
28
-
29
- require 'puppet/external/gratr/digraph_distance'
30
-
31
- module GRATR
32
- module Graph
33
- module ChinesePostman
34
-
35
- # Returns the shortest walk that traverses all arcs at least
36
- # once, returning to the specified start node.
37
- def closed_chinese_postman_tour(start, weight=nil, zero=0)
38
- cost, path, delta = floyd_warshall(weight, zero)
39
- return nil unless cp_valid_least_cost? cost, zero
40
- positive, negative = cp_unbalanced(delta)
41
- f = cp_find_feasible(delta, positive, negative, zero)
42
- while cp_improve(f, positive, negative, cost, zero); end
43
- cp_euler_circuit(start, f, path)
44
- end
45
-
46
- private
47
-
48
- def cp_euler_circuit(start, f, path) # :nodoc:
49
- circuit = [u=v=start]
50
- bridge_taken = Hash.new {|h,k| h[k] = Hash.new}
51
- until v.nil?
52
- if v=f[u].keys.detect {|k| f[u][k] > 0}
53
- f[u][v] -= 1
54
- circuit << (u = path[u][v]) while u != v
55
- else
56
- unless bridge_taken[u][bridge = path[u][start]]
57
- v = vertices.detect {|v1| v1 != bridge && edge?(u,v1) && !bridge_taken[u][v1]} || bridge
58
- bridge_taken[u][v] = true
59
- circuit << v
60
- end
61
- end
62
- u=v
63
- end; circuit
64
- end
65
-
66
- def cp_cancel_cycle(cost, path, f, start, zero) # :nodoc:
67
- u = start; k = nil
68
- begin
69
- v = path[u][start]
70
- k = f[v][u] if cost[u][v] < zero and (k.nil? || k > f[v][u])
71
- end until (u=v) != start
72
- u = start
73
- begin
74
- v = path[u][start]
75
- cost[u][v] < zero ? f[v][u] -= k : f[u][v] += k
76
- end until (u=v) != start
77
- true # This routine always returns true to make cp_improve easier
78
- end
79
-
80
- def cp_improve(f, positive, negative, cost, zero) # :nodoc:
81
- residual = self.class.new
82
- negative.each do |u|
83
- positive.each do |v|
84
- residual.add_edge!(u,v,cost[u][v])
85
- residual.add_edge!(v,u,-cost[u][v]) if f[u][v] != 0
86
- end
87
- end
88
- r_cost, r_path, r_delta = residual.floyd_warshall(nil, zero)
89
- i = residual.vertices.detect {|v| r_cost[v][v] and r_cost[v][v] < zero}
90
- i ? cp_cancel_cycle(r_cost, r_path, f, i) : false
91
- end
92
-
93
- def cp_find_feasible(delta, positive, negative, zero) # :nodoc:
94
- f = Hash.new {|h,k| h[k] = Hash.new}
95
- negative.each do |i|
96
- positive.each do |j|
97
- f[i][j] = -delta[i] < delta[j] ? -delta[i] : delta[j]
98
- delta[i] += f[i][j]
99
- delta[j] -= f[i][j]
100
- end
101
- end; f
102
- end
103
-
104
- def cp_valid_least_cost?(c, zero) # :nodoc:
105
- vertices.each do |i|
106
- vertices.each do |j|
107
- return false unless c[i][j] and c[i][j] >= zero
108
- end
109
- end; true
110
- end
111
-
112
- def cp_unbalanced(delta) # :nodoc:
113
- negative = []; positive = []
114
- vertices.each do |v|
115
- negative << v if delta[v] < 0
116
- positive << v if delta[v] > 0
117
- end; [positive, negative]
118
- end
119
-
120
- end # Chinese Postman
121
- end # Graph
122
- end # GRATR
123
-
@@ -1,73 +0,0 @@
1
- #--
2
- # Copyright (c) 2006 Shawn Patrick Garbett
3
- #
4
- # Redistribution and use in source and binary forms, with or without modification,
5
- # are permitted provided that the following conditions are met:
6
- #
7
- # * Redistributions of source code must retain the above copyright notice(s),
8
- # this list of conditions and the following disclaimer.
9
- # * Redistributions in binary form must reproduce the above copyright notice,
10
- # this list of conditions and the following disclaimer in the documentation
11
- # and/or other materials provided with the distribution.
12
- # * Neither the name of the Shawn Garbett nor the names of its contributors
13
- # may be used to endorse or promote products derived from this software
14
- # without specific prior written permission.
15
- #
16
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
- # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
- # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
- # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20
- # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
- # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
- # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
- # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
- # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
- #++
27
-
28
-
29
- require 'puppet/external/gratr/edge'
30
- require 'puppet/external/gratr/graph'
31
-
32
- module GRATR
33
- # This class defines a cycle graph of size n
34
- # This is easily done by using the base Graph
35
- # class and implemeting the minimum methods needed to
36
- # make it work. This is a good example to look
37
- # at for making one's own graph classes
38
- class Cycle
39
-
40
- def initialize(n) @size = n; end
41
- def directed?() false; end
42
- def vertices() (1..@size).to_a; end
43
- def vertex?(v) v > 0 and v <= @size; end
44
- def edge?(u,v=nil)
45
- u, v = [u.source, v.target] if u.kind_of? GRATR::Edge
46
- vertex?(u) && vertex?(v) && ((v-u == 1) or (u==@size && v=1))
47
- end
48
- def edges() Array.new(@size) {|i| GRATR::UndirectedEdge[i+1, (i+1)==@size ? 1 : i+2]}; end
49
- end
50
-
51
- # This class defines a complete graph of size n
52
- # This is easily done by using the base Graph
53
- # class and implemeting the minimum methods needed to
54
- # make it work. This is a good example to look
55
- # at for making one's own graph classes
56
- class Complete < Cycle
57
- def initialize(n) @size = n; @edges = nil; end
58
- def edges
59
- return @edges if @edges # Cache edges
60
- @edges = []
61
- @size.times do |u|
62
- @size.times {|v| @edges << GRATR::UndirectedEdge[u+1, v+1]}
63
- end; @edges
64
- end
65
- def edge?(u,v=nil)
66
- u, v = [u.source, v.target] if u.kind_of? GRATR::Edge
67
- vertex?(u) && vertex?(v)
68
- end
69
- end # Complete
70
-
71
-
72
-
73
- end # GRATR
@@ -1,92 +0,0 @@
1
- #--
2
- # Copyright (c) 2006 Shawn Patrick Garbett
3
- #
4
- # Redistribution and use in source and binary forms, with or without modification,
5
- # are permitted provided that the following conditions are met:
6
- #
7
- # * Redistributions of source code must retain the above copyright notice(s),
8
- # this list of conditions and the following disclaimer.
9
- # * Redistributions in binary form must reproduce the above copyright notice,
10
- # this list of conditions and the following disclaimer in the documentation
11
- # and/or other materials provided with the distribution.
12
- # * Neither the name of the Shawn Garbett nor the names of its contributors
13
- # may be used to endorse or promote products derived from this software
14
- # without specific prior written permission.
15
- #
16
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
- # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
- # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
- # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20
- # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
- # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
- # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
- # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
- # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
- #++
27
-
28
- module GRATR
29
- module Graph
30
- module Comparability
31
-
32
- # A comparability graph is an UndirectedGraph that has a transitive
33
- # orientation. This returns a boolean that says if this graph
34
- # is a comparability graph.
35
- def comparability?() gamma_decomposition[1]; end
36
-
37
- # Returns an array with two values, the first being a hash of edges
38
- # with a number containing their class assignment, the second valud
39
- # is a boolean which states whether or not the graph is a
40
- # comparability graph
41
- #
42
- # Complexity in time O(d*|E|) where d is the maximum degree of a vertex
43
- # Complexity in space O(|V|+|E|)
44
- def gamma_decomposition
45
- k = 0; comparability=true; classification={}
46
- edges.map {|edge| [edge.source,edge.target]}.each do |e|
47
- if classification[e].nil?
48
- k += 1
49
- classification[e] = k; classification[e.reverse] = -k
50
- comparability &&= gratr_comparability_explore(e, k, classification)
51
- end
52
- end; [classification, comparability]
53
- end
54
-
55
- # Returns one of the possible transitive orientations of
56
- # the UndirectedGraph as a Digraph
57
- def transitive_orientation(digraph_class=Digraph)
58
- raise NotImplementError
59
- end
60
-
61
- private
62
-
63
- # Taken from Figure 5.10, on pg. 130 of Martin Golumbic's, _Algorithmic_Graph_
64
- # _Theory_and_Perfect_Graphs.
65
- def gratr_comparability_explore(edge, k, classification, space='')
66
- ret = gratr_comparability_explore_inner(edge, k, classification, :forward, space)
67
- gratr_comparability_explore_inner(edge.reverse, k, classification, :backward, space) && ret
68
- end
69
-
70
- def gratr_comparability_explore_inner(edge, k, classification, direction,space)
71
- comparability = true
72
- adj_target = adjacent(edge[1])
73
- adjacent(edge[0]).select do |mt|
74
- (classification[[edge[1],mt]] || k).abs < k or
75
- not adj_target.any? {|adj_t| adj_t == mt}
76
- end.each do |m|
77
- e = (direction == :forward) ? [edge[0], m] : [m,edge[0]]
78
- if classification[e].nil?
79
- classification[e] = k
80
- classification[e.reverse] = -k
81
- comparability = gratr_comparability_explore(e, k, classification, ' '+space) && comparability
82
- elsif classification[e] == -k
83
- classification[e] = k
84
- gratr_comparability_explore(e, k, classification, ' '+space)
85
- comparability = false
86
- end
87
- end; comparability
88
- end # gratr_comparability_explore_inner
89
-
90
- end # Comparability
91
- end # Graph
92
- end # GRATR
@@ -1,116 +0,0 @@
1
- #--
2
- # Copyright (c) 2006 Shawn Patrick Garbett
3
- # Copyright (c) 2002,2004,2005 by Horst Duchene
4
- #
5
- # Redistribution and use in source and binary forms, with or without modification,
6
- # are permitted provided that the following conditions are met:
7
- #
8
- # * Redistributions of source code must retain the above copyright notice(s),
9
- # this list of conditions and the following disclaimer.
10
- # * Redistributions in binary form must reproduce the above copyright notice,
11
- # this list of conditions and the following disclaimer in the documentation
12
- # and/or other materials provided with the distribution.
13
- # * Neither the name of the Shawn Garbett nor the names of its contributors
14
- # may be used to endorse or promote products derived from this software
15
- # without specific prior written permission.
16
- #
17
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
- # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
- # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
- # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21
- # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
- # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
- # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
- # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
- # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
- #++
28
-
29
- require 'puppet/external/gratr/edge'
30
- require 'puppet/external/gratr/graph'
31
- require 'puppet/external/gratr/search'
32
- require 'puppet/external/gratr/adjacency_graph'
33
- require 'puppet/external/gratr/strong_components'
34
- require 'puppet/external/gratr/digraph_distance'
35
- require 'puppet/external/gratr/chinese_postman'
36
-
37
- module GRATR
38
- #
39
- # Digraph is a directed graph which is a finite set of vertices
40
- # and a finite set of edges connecting vertices. It cannot contain parallel
41
- # edges going from the same source vertex to the same target. It also
42
- # cannot contain loops, i.e. edges that go have the same vertex for source
43
- # and target.
44
- #
45
- # DirectedPseudoGraph is a class that allows for parallel edges, and a
46
- # DirectedMultiGraph is a class that allows for parallel edges and loops
47
- # as well.
48
- class Digraph
49
- include AdjacencyGraph
50
- include Graph::Search
51
- include Graph::StrongComponents
52
- include Graph::Distance
53
- include Graph::ChinesePostman
54
-
55
- def initialize(*params)
56
- raise ArgumentError if params.any? do |p|
57
- !(p.kind_of? GRATR::Graph or p.kind_of? Array)
58
- end if self.class == GRATR::Digraph
59
- super(*params)
60
- end
61
-
62
- # A directed graph is directed by definition
63
- def directed?() true; end
64
-
65
- # A digraph uses the Edge class for edges
66
- def edge_class() @parallel_edges ? GRATR::MultiEdge : GRATR::Edge; end
67
-
68
- # Reverse all edges in a graph
69
- def reversal
70
- return new(self) unless directed?
71
- result = self.class.new
72
- edges.inject(result) {|a,e| a << e.reverse}
73
- vertices.each { |v| result.add_vertex!(v) unless result.vertex?(v) }
74
- result
75
- end
76
-
77
- # Return true if the Graph is oriented.
78
- def oriented?
79
- e = edges
80
- re = e.map {|x| x.reverse}
81
- not e.any? {|x| re.include?(x)}
82
- end
83
-
84
- # Balanced is when the out edge count is equal to the in edge count
85
- def balanced?(v) out_degree(v) == in_degree(v); end
86
-
87
- # Returns out_degree(v) - in_degree(v)
88
- def delta(v) out_degree(v) - in_degree(v); end
89
-
90
- end
91
-
92
- # DirectedGraph is just an alias for Digraph should one desire
93
- DirectedGraph = Digraph
94
-
95
- # This is a Digraph that allows for parallel edges, but does not
96
- # allow loops
97
- class DirectedPseudoGraph < Digraph
98
- def initialize(*params)
99
- raise ArgumentError if params.any? do |p|
100
- !(p.kind_of? GRATR::Graph or p.kind_of? Array)
101
- end
102
- super(:parallel_edges, *params)
103
- end
104
- end
105
-
106
- # This is a Digraph that allows for parallel edges and loops
107
- class DirectedMultiGraph < Digraph
108
- def initialize(*params)
109
- raise ArgumentError if params.any? do |p|
110
- !(p.kind_of? GRATR::Graph or p.kind_of? Array)
111
- end
112
- super(:parallel_edges, :loops, *params)
113
- end
114
- end
115
-
116
- end
@@ -1,185 +0,0 @@
1
- #--
2
- # Copyright (c) 2006 Shawn Patrick Garbett
3
- #
4
- # Redistribution and use in source and binary forms, with or without modification,
5
- # are permitted provided that the following conditions are met:
6
- #
7
- # * Redistributions of source code must retain the above copyright notice(s),
8
- # this list of conditions and the following disclaimer.
9
- # * Redistributions in binary form must reproduce the above copyright notice,
10
- # this list of conditions and the following disclaimer in the documentation
11
- # and/or other materials provided with the distribution.
12
- # * Neither the name of the Shawn Garbett nor the names of its contributors
13
- # may be used to endorse or promote products derived from this software
14
- # without specific prior written permission.
15
- #
16
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
- # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
- # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
- # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20
- # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
- # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
- # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
- # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
- # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
- #++
27
-
28
- module GRATR
29
- module Graph
30
- module Distance
31
-
32
- # Shortest path from Jorgen Band-Jensen and Gregory Gutin,
33
- # _DIGRAPHS:_Theory,_Algorithms_and_Applications, pg 53-54
34
- #
35
- # Requires that the graph be acyclic. If the graph is not
36
- # acyclic, then see dijkstras_algorithm or bellman_ford_moore
37
- # for possible solutions.
38
- #
39
- # start is the starting vertex
40
- # weight can be a Proc, or anything else is accessed using the [] for the
41
- # the label or it defaults to using
42
- # the value stored in the label for the Edge. If it is a Proc it will
43
- # pass the edge to the proc and use the resulting value.
44
- # zero is used for math system with a different definition of zero
45
- #
46
- # Returns a hash with the key being a vertex and the value being the
47
- # distance. A missing vertex from the hash is an infinite distance
48
- #
49
- # Complexity O(n+m)
50
- def shortest_path(start, weight=nil, zero=0)
51
- dist = {start => zero}; path = {}
52
- topsort(start) do |vi|
53
- next if vi == start
54
- dist[vi],path[vi] = adjacent(vi, :direction => :in).map do |vj|
55
- [dist[vj] + cost(vj,vi,weight), vj]
56
- end.min {|a,b| a[0] <=> b[0]}
57
- end;
58
- dist.keys.size == vertices.size ? [dist,path] : nil
59
- end # shortest_path
60
-
61
- # Algorithm from Jorgen Band-Jensen and Gregory Gutin,
62
- # _DIGRAPHS:_Theory,_Algorithms_and_Applications, pg 53-54
63
- #
64
- # Finds the distances from a given vertex s in a weighted digraph
65
- # to the rest of the vertices, provided all the weights of arcs
66
- # are non-negative. If negative arcs exist in the graph, two
67
- # basic options exist, 1) modify all weights to be positive by
68
- # using an offset, or 2) use the bellman_ford_moore algorithm.
69
- # Also if the graph is acyclic, use the shortest_path algorithm.
70
- #
71
- # weight can be a Proc, or anything else is accessed using the [] for the
72
- # the label or it defaults to using
73
- # the value stored in the label for the Edge. If it is a Proc it will
74
- # pass the edge to the proc and use the resulting value.
75
- #
76
- # zero is used for math system with a different definition of zero
77
- #
78
- # Returns a hash with the key being a vertex and the value being the
79
- # distance. A missing vertex from the hash is an infinite distance
80
- #
81
- # O(n*log(n) + m) complexity
82
- def dijkstras_algorithm(s, weight = nil, zero = 0)
83
- q = vertices; distance = { s => zero }; path = {}
84
- while not q.empty?
85
- v = (q & distance.keys).inject(nil) {|a,k| (!a.nil?) && (distance[a] < distance[k]) ? a : k}
86
- q.delete(v)
87
- (q & adjacent(v)).each do |u|
88
- c = cost(v,u,weight)
89
- if distance[u].nil? or distance[u] > (c+distance[v])
90
- distance[u] = c + distance[v]
91
- path[u] = v
92
- end
93
- end
94
- end; [distance, path]
95
- end # dijkstras_algorithm
96
-
97
- # Algorithm from Jorgen Band-Jensen and Gregory Gutin,
98
- # _DIGRAPHS:_Theory,_Algorithms_and_Applications, pg 56-58
99
- #
100
- # Finds the distances from a given vertex s in a weighted digraph
101
- # to the rest of the vertices, provided the graph has no negative cycle.
102
- # If no negative weights exist, then dijkstras_algorithm is more
103
- # efficient in time and space. Also if the graph is acyclic, use the
104
- # shortest_path algorithm.
105
- #
106
- # weight can be a Proc, or anything else is accessed using the [] for the
107
- # the label or it defaults to using
108
- # the value stored in the label for the Edge. If it is a Proc it will
109
- # pass the edge to the proc and use the resulting value.
110
- #
111
- # zero is used for math system with a different definition of zero
112
- #
113
- # Returns a hash with the key being a vertex and the value being the
114
- # distance. A missing vertex from the hash is an infinite distance
115
- #
116
- # O(nm) complexity
117
- def bellman_ford_moore(start, weight = nil, zero = 0)
118
- distance = { start => zero }; path = {}
119
- 2.upto(vertices.size) do
120
- edges.each do |e|
121
- u,v = e[0],e[1]
122
- unless distance[u].nil?
123
- c = cost(u, v, weight)+distance[u]
124
- if distance[v].nil? or c < distance[v]
125
- distance[v] = c
126
- path[v] = u
127
- end
128
- end
129
- end
130
- end; [distance, path]
131
- end # bellman_ford_moore
132
-
133
- # This uses the Floyd-Warshall algorithm to efficiently find
134
- # and record shortest paths at the same time as establishing
135
- # the costs for all vertices in a graph.
136
- # See, S.Skiena, "The Algorithm Design Manual",
137
- # Springer Verlag, 1998 for more details.
138
- #
139
- # Returns a pair of matrices and a hash of delta values.
140
- # The matrices will be indexed by two vertices and are
141
- # implemented as a Hash of Hashes. The first matrix is the cost, the second
142
- # matrix is the shortest path spanning tree. The delta (difference of number
143
- # of in edges and out edges) is indexed by vertex.
144
- #
145
- # weight specifies how an edge weight is determined, if it's a
146
- # Proc the Edge is passed to it, if it's nil it will just use
147
- # the value in the label for the Edge, otherwise the weight is
148
- # determined by applying the [] operator to the value in the
149
- # label for the Edge
150
- #
151
- # zero defines the zero value in the math system used. Defaults
152
- # of course, to 0. This allows for no assumptions to be made
153
- # about the math system and fully functional duck typing.
154
- #
155
- # O(n^3) complexity in time.
156
- def floyd_warshall(weight=nil, zero=0)
157
- c = Hash.new {|h,k| h[k] = Hash.new}
158
- path = Hash.new {|h,k| h[k] = Hash.new}
159
- delta = Hash.new {|h,k| h[k] = 0}
160
- edges.each do |e|
161
- delta[e.source] += 1
162
- delta[e.target] -= 1
163
- path[e.source][e.target] = e.target
164
- c[e.source][e.target] = cost(e, weight)
165
- end
166
- vertices.each do |k|
167
- vertices.each do |i|
168
- if c[i][k]
169
- vertices.each do |j|
170
- if c[k][j] &&
171
- (c[i][j].nil? or c[i][j] > (c[i][k] + c[k][j]))
172
- path[i][j] = path[i][k]
173
- c[i][j] = c[i][k] + c[k][j]
174
- return nil if i == j and c[i][j] < zero
175
- end
176
- end
177
- end
178
- end
179
- end
180
- [c, path, delta]
181
- end # floyd_warshall
182
-
183
- end # Distance
184
- end # Graph
185
- end # GRATR