vcs 0.2.148 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +6 -0
- data/NEWS +9 -0
- data/README +82 -0
- data/Rakefile +7 -72
- data/SPEC.dyn.yml +10 -0
- data/SPEC.gemspec +14 -0
- data/SPEC.yml +39 -0
- data/bin/vcs +18 -16
- data/lib/vcs/changelog.rb +164 -0
- data/lib/vcs/conflict.rb +21 -0
- data/{src → lib/vcs}/cvs.rb +1 -1
- data/{src → lib/vcs}/diff.rb +2 -2
- data/lib/vcs/diffstat.rb +28 -0
- data/lib/vcs/edit.rb +16 -0
- data/{src → lib/vcs}/last_changed_date.rb +3 -5
- data/{src → lib/vcs}/mail.rb +4 -4
- data/lib/vcs/message.rb +79 -0
- data/{src → lib/vcs}/mycommit.rb +15 -15
- data/{src → lib/vcs}/news.rb +6 -6
- data/{src → lib/vcs}/prcs.rb +1 -1
- data/{src → lib/vcs}/revision.rb +3 -4
- data/lib/vcs/script.rb +19 -0
- data/{src → lib/vcs}/status.rb +1 -1
- data/{src → lib/vcs}/svn.rb +3 -5
- data/lib/vcs/url.rb +16 -0
- data/lib/vcs/vcs.rb +279 -0
- metadata +52 -150
- data/TODO +0 -19
- data/doc/jamis.rb +0 -564
- data/ruby_ex/abstract.rb +0 -254
- data/ruby_ex/abstract_node.rb +0 -85
- data/ruby_ex/algorithms/simulated_annealing.rb +0 -140
- data/ruby_ex/array_each_pair.rb +0 -18
- data/ruby_ex/ask.rb +0 -101
- data/ruby_ex/attributed_class.rb +0 -302
- data/ruby_ex/cache.rb +0 -373
- data/ruby_ex/checkout.rb +0 -12
- data/ruby_ex/choose.rb +0 -271
- data/ruby_ex/commands.rb +0 -18
- data/ruby_ex/commands/command.rb +0 -401
- data/ruby_ex/commands/datas.rb +0 -16
- data/ruby_ex/commands/datas/data.rb +0 -33
- data/ruby_ex/commands/datas/factory.rb +0 -66
- data/ruby_ex/commands/factory.rb +0 -66
- data/ruby_ex/commands/helpers.rb +0 -67
- data/ruby_ex/commands/pipe.rb +0 -64
- data/ruby_ex/commands/runners.rb +0 -17
- data/ruby_ex/commands/runners/exec.rb +0 -49
- data/ruby_ex/commands/runners/fork.rb +0 -97
- data/ruby_ex/commands/runners/runner.rb +0 -107
- data/ruby_ex/commands/seq.rb +0 -27
- data/ruby_ex/config_file.rb +0 -96
- data/ruby_ex/const_regexp.rb +0 -59
- data/ruby_ex/daemon.rb +0 -134
- data/ruby_ex/diff.rb +0 -667
- data/ruby_ex/dlogger.rb +0 -62
- data/ruby_ex/drb/dispatcher.rb +0 -252
- data/ruby_ex/drb/dispatcher_server_test.rb +0 -29
- data/ruby_ex/drb/drb_observable.rb +0 -97
- data/ruby_ex/drb/drb_observable_pool.rb +0 -27
- data/ruby_ex/drb/drb_service.rb +0 -43
- data/ruby_ex/drb/drb_undumped_attributes.rb +0 -55
- data/ruby_ex/drb/drb_undumped_indexed_object.rb +0 -54
- data/ruby_ex/drb/insecure_protected_methods.rb +0 -103
- data/ruby_ex/drb/session_client_test.rb +0 -40
- data/ruby_ex/drb/session_manager.rb +0 -246
- data/ruby_ex/drb/session_server.rb +0 -53
- data/ruby_ex/dtime.rb +0 -143
- data/ruby_ex/dumpable_proc.rb +0 -63
- data/ruby_ex/exception.rb +0 -32
- data/ruby_ex/filetype.rb +0 -229
- data/ruby_ex/fileutils_ex.rb +0 -44
- data/ruby_ex/fold.rb +0 -58
- data/ruby_ex/generate_id.rb +0 -44
- data/ruby_ex/hookable.rb +0 -262
- data/ruby_ex/hooker.rb +0 -54
- data/ruby_ex/inactive_timeout.rb +0 -137
- data/ruby_ex/indexed_node.rb +0 -66
- data/ruby_ex/io_marshal.rb +0 -100
- data/ruby_ex/ioo.rb +0 -194
- data/ruby_ex/labeled_node.rb +0 -63
- data/ruby_ex/logger_observer.rb +0 -23
- data/ruby_ex/md5sum.rb +0 -66
- data/ruby_ex/mktemp.rb +0 -208
- data/ruby_ex/module/attr_once.rb +0 -36
- data/ruby_ex/module/autoload_tree.rb +0 -75
- data/ruby_ex/module/hierarchy.rb +0 -335
- data/ruby_ex/module/instance_method_visibility.rb +0 -73
- data/ruby_ex/module_ex.rb +0 -11
- data/ruby_ex/node.rb +0 -80
- data/ruby_ex/object_monitor.rb +0 -145
- data/ruby_ex/object_monitor_activity.rb +0 -33
- data/ruby_ex/observable.rb +0 -140
- data/ruby_ex/observable_pool.rb +0 -293
- data/ruby_ex/orderedhash.rb +0 -252
- data/ruby_ex/pathname_ex.rb +0 -152
- data/ruby_ex/pp_hierarchy.rb +0 -29
- data/ruby_ex/pseudo_cache.rb +0 -190
- data/ruby_ex/queue.rb +0 -56
- data/ruby_ex/random_generators.rb +0 -25
- data/ruby_ex/random_generators/random_generator.rb +0 -31
- data/ruby_ex/random_generators/ruby.rb +0 -23
- data/ruby_ex/safe_eval.rb +0 -348
- data/ruby_ex/sendmail.rb +0 -215
- data/ruby_ex/service_manager.rb +0 -121
- data/ruby_ex/session/administrable.rb +0 -120
- data/ruby_ex/session/client.rb +0 -153
- data/ruby_ex/session/const.rb +0 -18
- data/ruby_ex/session/dispatcher.rb +0 -184
- data/ruby_ex/session/error.rb +0 -21
- data/ruby_ex/session/fetchable.rb +0 -57
- data/ruby_ex/session/fetcher.rb +0 -62
- data/ruby_ex/session/hookable.rb +0 -26
- data/ruby_ex/session/profile.rb +0 -110
- data/ruby_ex/session/server.rb +0 -582
- data/ruby_ex/session/test/administrable_test.rb +0 -337
- data/ruby_ex/session/test/basic_test.rb +0 -523
- data/ruby_ex/session/test/dispatcher_test.rb +0 -409
- data/ruby_ex/session/test/fetchable_test.rb +0 -119
- data/ruby_ex/session/test/sub_server_test.rb +0 -188
- data/ruby_ex/shuffle.rb +0 -30
- data/ruby_ex/spring.rb +0 -136
- data/ruby_ex/spring_set.rb +0 -137
- data/ruby_ex/string_ex.rb +0 -28
- data/ruby_ex/symtbl.rb +0 -106
- data/ruby_ex/synflow.rb +0 -474
- data/ruby_ex/test/unit/ui/yaml/testrunner.rb +0 -164
- data/ruby_ex/thread_mutex.rb +0 -10
- data/ruby_ex/timeout_ex.rb +0 -81
- data/ruby_ex/top_down.rb +0 -73
- data/ruby_ex/trace.rb +0 -26
- data/ruby_ex/uri/druby.rb +0 -81
- data/ruby_ex/uri/file.rb +0 -65
- data/ruby_ex/uri/ftp_ex.rb +0 -37
- data/ruby_ex/uri/http_ex.rb +0 -43
- data/ruby_ex/uri/ssh.rb +0 -92
- data/ruby_ex/uri/svn.rb +0 -118
- data/ruby_ex/uri_ex.rb +0 -45
- data/ruby_ex/verbose_object.rb +0 -30
- data/ruby_ex/version.rb +0 -66
- data/ruby_ex/yaml/basenode_ext.rb +0 -63
- data/ruby_ex/yaml/chop_header.rb +0 -23
- data/ruby_ex/yaml/transform.rb +0 -449
- data/ruby_ex/yaml/yregexpath.rb +0 -76
- data/src/ask.rb +0 -101
- data/src/changelog.rb +0 -117
- data/src/conflict.rb +0 -20
- data/src/diffstat.rb +0 -42
- data/src/message.rb +0 -64
- data/src/reply-mail.rb +0 -14
- data/src/tools.rb +0 -22
- data/src/vcs.rb +0 -176
data/ruby_ex/abstract.rb
DELETED
@@ -1,254 +0,0 @@
|
|
1
|
-
# Copyright: Copyright (c) 2004 Nicolas Despres. All rights reserved.
|
2
|
-
# Author: Nicolas Despres <polrop@lrde.epita.fr>.
|
3
|
-
# License: Gnu General Public License.
|
4
|
-
|
5
|
-
# $LastChangedBy: ertai $
|
6
|
-
# $Id: abstract.rb 210 2005-05-05 19:59:45Z ertai $
|
7
|
-
|
8
|
-
|
9
|
-
#FIXME: find a way to be thread safe.
|
10
|
-
|
11
|
-
|
12
|
-
require 'module/instance_method_visibility'
|
13
|
-
|
14
|
-
|
15
|
-
module Concrete; end
|
16
|
-
|
17
|
-
|
18
|
-
# When this module is included into a class, this class can't be instantiate
|
19
|
-
# any more until the Concrete module is included too. This module cannot be
|
20
|
-
# included if the Concrete module has been included before in one of the
|
21
|
-
# class' superclass.
|
22
|
-
module Abstract
|
23
|
-
|
24
|
-
def self.included(klass)
|
25
|
-
super
|
26
|
-
if klass.include?(Concrete)
|
27
|
-
raise(TypeError, "#{klass} - cannot make abstract a concrete class")
|
28
|
-
end
|
29
|
-
klass.module_eval do
|
30
|
-
class << self
|
31
|
-
unless private_method_defined?(:concrete_new)
|
32
|
-
alias_method :concrete_new, :new
|
33
|
-
visibility = instance_method_visibility('new')
|
34
|
-
def new(*args, &block)
|
35
|
-
raise(TypeError, "cannot instantiate an abstract class #{name}")
|
36
|
-
end
|
37
|
-
send(visibility, :new)
|
38
|
-
private :concrete_new
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
end # module Abstract
|
45
|
-
|
46
|
-
|
47
|
-
# Include this module in an abstract class to make it concrete and so, to be
|
48
|
-
# able to instantiate it again. This module can be included if and only if the
|
49
|
-
# Abstract module has been included before in one of the class' superclass.
|
50
|
-
module Concrete
|
51
|
-
|
52
|
-
def self.included(klass)
|
53
|
-
super
|
54
|
-
unless klass.include?(Abstract)
|
55
|
-
raise(TypeError, "#{klass} - not an abstract class")
|
56
|
-
end
|
57
|
-
klass.module_eval do
|
58
|
-
class << self
|
59
|
-
visibility = instance_method_visibility('new')
|
60
|
-
def new(*args, &block)
|
61
|
-
concrete_new(*args, &block)
|
62
|
-
end
|
63
|
-
send(visibility, :new)
|
64
|
-
end
|
65
|
-
|
66
|
-
def is_a?(klass)
|
67
|
-
klass == Abstract ? false : super(klass)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
end # module Concrete
|
73
|
-
|
74
|
-
|
75
|
-
class Class
|
76
|
-
|
77
|
-
def abstract
|
78
|
-
include Abstract
|
79
|
-
end
|
80
|
-
|
81
|
-
def concrete
|
82
|
-
include Concrete
|
83
|
-
end
|
84
|
-
|
85
|
-
def abstract?
|
86
|
-
include?(Abstract) ? (not include?(Concrete)) : false;
|
87
|
-
end
|
88
|
-
|
89
|
-
end # class Class
|
90
|
-
|
91
|
-
|
92
|
-
if (not defined? ABSTRACT_TESTED) and (defined? TEST_MODE or __FILE__ == $0)
|
93
|
-
ABSTRACT_TESTED = true
|
94
|
-
|
95
|
-
|
96
|
-
require 'test/unit/ui/yaml/testrunner'
|
97
|
-
require 'singleton'
|
98
|
-
|
99
|
-
|
100
|
-
class AbstractTest < Test::Unit::TestCase
|
101
|
-
|
102
|
-
class R; end
|
103
|
-
|
104
|
-
class A
|
105
|
-
include Abstract
|
106
|
-
|
107
|
-
attr_reader :initialized
|
108
|
-
|
109
|
-
def initialize(toto=nil)
|
110
|
-
@initialized = true
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|
114
|
-
|
115
|
-
class B < A; end
|
116
|
-
|
117
|
-
def test_abstract
|
118
|
-
assert_nothing_raised { R.new }
|
119
|
-
assert(A.include?(Abstract))
|
120
|
-
assert_raises(TypeError) { A.new }
|
121
|
-
assert_raises(TypeError) { B.new }
|
122
|
-
assert_raises(TypeError) do
|
123
|
-
AbstractTest.module_eval %q{
|
124
|
-
class D
|
125
|
-
include Concrete
|
126
|
-
include Abstract
|
127
|
-
end
|
128
|
-
}
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
class C < A
|
133
|
-
include Concrete
|
134
|
-
|
135
|
-
attr_reader :toto
|
136
|
-
|
137
|
-
def initialize(toto=nil)
|
138
|
-
super
|
139
|
-
@toto = toto
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
class CC < C; end
|
144
|
-
|
145
|
-
def test_concrete
|
146
|
-
assert_raises(TypeError) do
|
147
|
-
AbstractTest.module_eval %q{ class D; include Concrete; end }
|
148
|
-
end
|
149
|
-
assert(C.new.initialized)
|
150
|
-
assert_nil(C.new.toto)
|
151
|
-
assert_equal('toto', C.new('toto').toto)
|
152
|
-
assert(CC.new.initialized)
|
153
|
-
assert_equal(SC.instance, SC.instance)
|
154
|
-
assert_equal(SCC.instance, SCC.instance)
|
155
|
-
assert_not_equal(SC.instance, SCC.instance)
|
156
|
-
end
|
157
|
-
|
158
|
-
class SA
|
159
|
-
include Singleton
|
160
|
-
include Abstract
|
161
|
-
|
162
|
-
attr_reader :initialized
|
163
|
-
|
164
|
-
def initialize(toto=nil)
|
165
|
-
@initialized = true
|
166
|
-
end
|
167
|
-
|
168
|
-
end
|
169
|
-
|
170
|
-
class SB < SA; end
|
171
|
-
|
172
|
-
def test_abstract_singleton
|
173
|
-
assert(SA.include?(Abstract))
|
174
|
-
assert_raises(NoMethodError) { SA.new }
|
175
|
-
assert_raises(TypeError) { SA.instance }
|
176
|
-
assert_raises(NoMethodError) { SB.new }
|
177
|
-
assert_raises(TypeError) { SB.instance }
|
178
|
-
assert_raises(TypeError) do
|
179
|
-
AbstractTest.module_eval %q{
|
180
|
-
class SD; include Concrete; include Abstract; end
|
181
|
-
}
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
class SC < SA
|
186
|
-
include Concrete
|
187
|
-
|
188
|
-
end
|
189
|
-
|
190
|
-
class SCC < SC; end
|
191
|
-
|
192
|
-
def test_concrete_singleton
|
193
|
-
assert_raises(TypeError) do
|
194
|
-
AbstractTest.module_eval %q{ class SD; include Concrete; end }
|
195
|
-
end
|
196
|
-
assert_raises(NoMethodError) { SC.new }
|
197
|
-
assert(SC.instance.initialized)
|
198
|
-
assert(SCC.instance.initialized)
|
199
|
-
assert_equal(SC.instance, SC.instance)
|
200
|
-
assert_equal(SCC.instance, SCC.instance)
|
201
|
-
assert_not_equal(SC.instance, SCC.instance)
|
202
|
-
end
|
203
|
-
|
204
|
-
class IsA; include Abstract; end
|
205
|
-
class IsB < IsA; include Concrete; end
|
206
|
-
|
207
|
-
def test_is_a
|
208
|
-
assert(! IsB.new.is_a?(Abstract))
|
209
|
-
assert(IsB.new.is_a?(IsA))
|
210
|
-
assert(IsB.include?(Abstract))
|
211
|
-
end
|
212
|
-
|
213
|
-
def test_abstract?
|
214
|
-
assert(IsA.abstract?)
|
215
|
-
assert(! IsB.abstract?)
|
216
|
-
end
|
217
|
-
|
218
|
-
class AArg
|
219
|
-
include Abstract
|
220
|
-
|
221
|
-
attr_reader :arg
|
222
|
-
|
223
|
-
def initialize(arg)
|
224
|
-
@arg = arg
|
225
|
-
end
|
226
|
-
|
227
|
-
end
|
228
|
-
|
229
|
-
class CArg < AArg
|
230
|
-
include Concrete
|
231
|
-
end
|
232
|
-
|
233
|
-
def test_arg
|
234
|
-
assert_nothing_raised { CArg.new('toto') }
|
235
|
-
assert_raises(ArgumentError) { CArg.new }
|
236
|
-
end
|
237
|
-
|
238
|
-
class AA_; include Abstract; end
|
239
|
-
class BB_ < AA_; include Abstract; end
|
240
|
-
class CC_ < BB_; include Concrete; end
|
241
|
-
class DD_ < CC_; include Concrete; end
|
242
|
-
|
243
|
-
def test_double_abstract
|
244
|
-
assert_raises(TypeError) { AA_.new }
|
245
|
-
assert_raises(TypeError) { BB_.new }
|
246
|
-
assert_nothing_raised { CC_.new }
|
247
|
-
assert_nothing_raised { DD_.new }
|
248
|
-
end
|
249
|
-
|
250
|
-
end # class AbstractTest
|
251
|
-
|
252
|
-
|
253
|
-
end
|
254
|
-
|
data/ruby_ex/abstract_node.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
# Copyright: Copyright (c) 2004 Nicolas Despres. All rights reserved.
|
2
|
-
# Author: Nicolas Despres <polrop@lrde.epita.fr>.
|
3
|
-
# License: Gnu General Public License.
|
4
|
-
|
5
|
-
# $LastChangedBy: ertai $
|
6
|
-
# $Id: abstract_node.rb 186 2005-04-03 00:07:45Z ertai $
|
7
|
-
|
8
|
-
|
9
|
-
require 'abstract'
|
10
|
-
require 'array_each_pair'
|
11
|
-
|
12
|
-
class AbstractNode
|
13
|
-
include Abstract
|
14
|
-
|
15
|
-
def initialize(data=nil, *sub_nodes)
|
16
|
-
@data = data
|
17
|
-
self.each_node { |sub_node| check_sub_node_type(sub_node) }
|
18
|
-
end
|
19
|
-
|
20
|
-
attr_reader :data, :sub_nodes
|
21
|
-
|
22
|
-
def [](index)
|
23
|
-
@sub_nodes[index]
|
24
|
-
end
|
25
|
-
|
26
|
-
def []=(index, sub_node)
|
27
|
-
check_sub_node_type(sub_node)
|
28
|
-
@sub_nodes[index] = sub_node
|
29
|
-
end
|
30
|
-
|
31
|
-
def merge!(sub_nodes)
|
32
|
-
sub_nodes.each { |index, sub_node| self[index] = sub_node }
|
33
|
-
end
|
34
|
-
|
35
|
-
def each_pair(&block)
|
36
|
-
@sub_nodes.each_pair { |index, sub_node| block[index, sub_node] }
|
37
|
-
end
|
38
|
-
|
39
|
-
def each_node(&block)
|
40
|
-
@sub_nodes.each_pair { |index, sub_node| block[sub_node] }
|
41
|
-
end
|
42
|
-
|
43
|
-
alias :each :each_node
|
44
|
-
|
45
|
-
def each_index(&block)
|
46
|
-
@sub_nodes.each_pair { |index, sub_node| block[index] }
|
47
|
-
end
|
48
|
-
|
49
|
-
def delete(index)
|
50
|
-
@sub_nodes.delete(index)
|
51
|
-
end
|
52
|
-
|
53
|
-
def nb_sub_nodes
|
54
|
-
@sub_nodes.size
|
55
|
-
end
|
56
|
-
|
57
|
-
alias size nb_sub_nodes
|
58
|
-
alias length nb_sub_nodes
|
59
|
-
|
60
|
-
def leaf?
|
61
|
-
@sub_nodes.empty?
|
62
|
-
end
|
63
|
-
|
64
|
-
def pre_depth_first(index=nil, &block)
|
65
|
-
block[index, self]
|
66
|
-
@sub_nodes.each_pair do |index, sub_node|
|
67
|
-
sub_node.pre_depth_first(index, &block)
|
68
|
-
end
|
69
|
-
nil
|
70
|
-
end
|
71
|
-
|
72
|
-
# FIXME: implement me
|
73
|
-
# def breadth_first(&block)
|
74
|
-
# end
|
75
|
-
|
76
|
-
protected
|
77
|
-
def check_sub_node_type(sub_node)
|
78
|
-
unless sub_node.is_a?(self.class)
|
79
|
-
raise(TypeError, "`#{sub_node}' - must be a #{self.class}")
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
end # class AbstractNode
|
84
|
-
|
85
|
-
|
@@ -1,140 +0,0 @@
|
|
1
|
-
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
2
|
-
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
3
|
-
# License:: GNU General Public License (GPL).
|
4
|
-
# Revision:: $Id$
|
5
|
-
|
6
|
-
require 'string_ex'
|
7
|
-
|
8
|
-
module Algorithms
|
9
|
-
|
10
|
-
class SimulatedAnnealing
|
11
|
-
|
12
|
-
# Example:
|
13
|
-
#
|
14
|
-
# obj = MySimulatedAnnealingObject.new
|
15
|
-
#
|
16
|
-
# SimulatedAnnealing.new(
|
17
|
-
# :support => obj,
|
18
|
-
# :global_thresold => 200,
|
19
|
-
# :step_multiplicator => 0.63,
|
20
|
-
# :initial_temperature => 10,
|
21
|
-
# :initial_cost => obj.cost,
|
22
|
-
# :iteration_modulus => 500, # display status once a 500
|
23
|
-
# :step_modulus => 5000 # change the temperature once a 5000
|
24
|
-
# )
|
25
|
-
#
|
26
|
-
def initialize ( opts )
|
27
|
-
@support = opts[:support]
|
28
|
-
@global_thresold = opts[:global_thresold]
|
29
|
-
@step_multiplicator = opts[:step_multiplicator]
|
30
|
-
@temperature = opts[:initial_temperature]
|
31
|
-
@cur_cost = opts[:initial_cost]
|
32
|
-
@output = opts[:output] || STDOUT
|
33
|
-
@iteration_modulus = opts[:iteration_modulus] || 1
|
34
|
-
@step_modulus = opts[:step_modulus] || 1
|
35
|
-
@progression = ' '
|
36
|
-
@diff_cost = 0
|
37
|
-
@iteration = 0
|
38
|
-
@probability_threshold = 0
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
def run
|
43
|
-
@output.puts '---'
|
44
|
-
while @cur_cost > @global_thresold
|
45
|
-
# puts "Iteration(#{it}) #{@cur_cost}"
|
46
|
-
@transition = @support.choose_transition()
|
47
|
-
@diff_cost = @support.transition_cost(@cur_cost, @transition)
|
48
|
-
|
49
|
-
@iteration += 1
|
50
|
-
if (@iteration % @step_modulus).zero?
|
51
|
-
@temperature *= @step_multiplicator
|
52
|
-
end
|
53
|
-
|
54
|
-
if @diff_cost > 0
|
55
|
-
@probability_threshold = Math.exp(- @diff_cost.to_f / @temperature)
|
56
|
-
@proba = choose_probability()
|
57
|
-
if @proba < @probability_threshold
|
58
|
-
progression '+'
|
59
|
-
else
|
60
|
-
progression ' '
|
61
|
-
next
|
62
|
-
end
|
63
|
-
else
|
64
|
-
@probability_threshold = 1
|
65
|
-
@proba = 1
|
66
|
-
progression((@diff_cost.zero?)? '=' : '-')
|
67
|
-
end
|
68
|
-
|
69
|
-
@support.apply_transition(@transition)
|
70
|
-
@cur_cost += @diff_cost
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
|
75
|
-
def disp ( output=@output )
|
76
|
-
args = [ @progression, @diff_cost.abs, @temperature,
|
77
|
-
@proba, @probability_threshold, @cur_cost ]
|
78
|
-
fmt = '- { diff: %s%-7d, temp: %-4f, ' +
|
79
|
-
'prob: %-7f, thres: %-7f, cost: %-5s }'
|
80
|
-
output.puts fmt % args
|
81
|
-
end
|
82
|
-
|
83
|
-
|
84
|
-
def summary
|
85
|
-
@output.puts %Q[
|
86
|
-
|---
|
87
|
-
|Found a mininum: #@cur_cost
|
88
|
-
|Temperature at the end: #@temperature
|
89
|
-
|Nb iterations: #@iteration
|
90
|
-
].head_cut!
|
91
|
-
end
|
92
|
-
|
93
|
-
|
94
|
-
def progression ( x )
|
95
|
-
@progression = x
|
96
|
-
disp if (@iteration % @iteration_modulus).zero?
|
97
|
-
end
|
98
|
-
|
99
|
-
|
100
|
-
def choose_probability
|
101
|
-
rand()
|
102
|
-
end
|
103
|
-
|
104
|
-
|
105
|
-
module Support
|
106
|
-
|
107
|
-
def included ( aModule )
|
108
|
-
|
109
|
-
aModule.module_eval do
|
110
|
-
|
111
|
-
#
|
112
|
-
# Return a transition which can be applied by apply_transition.
|
113
|
-
#
|
114
|
-
def choose_transition
|
115
|
-
raise NotImplementedError
|
116
|
-
end
|
117
|
-
|
118
|
-
#
|
119
|
-
# Return a cost difference
|
120
|
-
#
|
121
|
-
def transition_cost ( current_cost, transition )
|
122
|
-
raise NotImplementedError
|
123
|
-
end
|
124
|
-
|
125
|
-
#
|
126
|
-
# Apply the given transition to your current object.
|
127
|
-
#
|
128
|
-
def apply_transition ( transition )
|
129
|
-
raise NotImplementedError
|
130
|
-
end
|
131
|
-
|
132
|
-
end
|
133
|
-
|
134
|
-
end
|
135
|
-
|
136
|
-
end # module Support
|
137
|
-
|
138
|
-
end # class SimulatedAnnealing
|
139
|
-
|
140
|
-
end # module Algorithms
|