sfplanner 0.2.1 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/sfplanner/planner.rb +89 -55
- data/lib/sfplanner/sas.rb +1 -1
- data/lib/sfplanner.rb +1 -1
- data/sfplanner.gemspec +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a2eab4c19fa0c0efedbebf24516f1c91b188424
|
4
|
+
data.tar.gz: fe703c00974a0509c02ce115520d090cbc1cbe35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52d152d8d60cf313e83b2803479ad3eedbb55a7d5399f1c6249d77751a8492bc243dd64604d8936e62da9f5f4b8e36565f57f023dd6910d3d90c9ad17cb75e7b
|
7
|
+
data.tar.gz: 32293097e185f5b77ea5ccfaedda5a05952ec9dcc723cb1dd1ae6c444e8dec0311aec86f889fbb45fb8d9ec0390b1d667cea168aa256573fd16766b27a6ba33b
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
data/lib/sfplanner/planner.rb
CHANGED
@@ -194,23 +194,35 @@ module Sfp
|
|
194
194
|
end
|
195
195
|
|
196
196
|
def solve_classical_task(params={})
|
197
|
-
|
197
|
+
benchmarks = {}
|
198
|
+
benchmarks[:solve_sas] = Benchmark.measure {
|
199
|
+
@plan, @sas_task = self.solve_sas(@parser, params)
|
200
|
+
}
|
198
201
|
|
199
202
|
return @plan if params[:sas_plan]
|
200
203
|
|
201
204
|
return to_bsig(params) if params[:bsig]
|
202
205
|
|
203
|
-
plan =
|
206
|
+
plan = nil
|
207
|
+
benchmarks[:get_parallel_plan] = Benchmark.measure {
|
208
|
+
plan = (params[:parallel] ? self.get_parallel_plan : self.get_sequential_plan)
|
209
|
+
}
|
204
210
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
211
|
+
output = nil
|
212
|
+
|
213
|
+
benchmarks[:to_json] = Benchmark.measure {
|
214
|
+
if params[:dot]
|
215
|
+
output = to_dot(plan)
|
216
|
+
elsif params[:json]
|
217
|
+
output = JSON.generate(plan)
|
218
|
+
elsif params[:pretty_json]
|
219
|
+
output = JSON.pretty_generate(plan)
|
220
|
+
else
|
221
|
+
output = plan
|
222
|
+
end
|
223
|
+
}
|
224
|
+
|
225
|
+
output
|
214
226
|
end
|
215
227
|
|
216
228
|
def bsig_template
|
@@ -347,27 +359,34 @@ module Sfp
|
|
347
359
|
def solve_sas(parser, p={})
|
348
360
|
return nil if parser.nil?
|
349
361
|
|
350
|
-
tmp_dir =
|
362
|
+
tmp_dir = "/tmp/nuri_#{(Time.now.to_f * 1000000).to_i}"
|
351
363
|
begin
|
352
|
-
|
364
|
+
benchmarks = {}
|
365
|
+
|
366
|
+
benchmarks['compile step 1'] = Benchmark.measure do
|
353
367
|
parser.compile_step_1
|
368
|
+
end
|
369
|
+
|
370
|
+
benchmarks['sas_post_processor'] = Benchmark.measure do
|
354
371
|
p[:sas_post_processor].sas_post_processor(parser) if p[:sas_post_processor]
|
372
|
+
end
|
373
|
+
|
374
|
+
benchmarks['compile step 2'] = Benchmark.measure do
|
355
375
|
parser.compile_step_2
|
356
376
|
end
|
357
377
|
|
358
378
|
while File.exist?(tmp_dir)
|
359
|
-
tmp_dir =
|
379
|
+
tmp_dir = "/tmp/nuri_#{(rand * 100000).to_i.abs}"
|
360
380
|
end
|
361
381
|
Dir.mkdir(tmp_dir)
|
362
382
|
|
363
|
-
benchmarks
|
364
|
-
benchmarks['compile time'] = compile_time
|
383
|
+
benchmarks.merge!(parser.benchmarks)
|
365
384
|
|
366
|
-
sas_file = tmp_dir
|
367
|
-
plan_file = tmp_dir
|
385
|
+
sas_file = "#{tmp_dir}/problem.sas"
|
386
|
+
plan_file = "#{tmp_dir}/out.plan"
|
368
387
|
benchmarks['generating sas'] = Benchmark.measure do
|
369
388
|
File.open(sas_file, 'w') do |f|
|
370
|
-
f.write
|
389
|
+
f.write parser.sas
|
371
390
|
f.flush
|
372
391
|
end
|
373
392
|
end
|
@@ -377,12 +396,24 @@ module Sfp
|
|
377
396
|
planner.solve
|
378
397
|
end
|
379
398
|
|
399
|
+
File.open("#{tmp_dir}/#{TranslatorBenchmarkFile}", 'w') do |f|
|
400
|
+
data = {}
|
401
|
+
benchmarks.each do |label,bm|
|
402
|
+
data[label] = {
|
403
|
+
:user => (bm.utime + bm.cutime).round(3),
|
404
|
+
:sys => (bm.stime + bm.cstime).round(3),
|
405
|
+
:real => bm.real.round(3),
|
406
|
+
}
|
407
|
+
end
|
408
|
+
f.write(JSON.pretty_generate(data))
|
409
|
+
end
|
410
|
+
|
380
411
|
plan = (File.exist?(plan_file) ? File.read(plan_file) : nil)
|
381
|
-
plan = plan_preprocessing(plan)
|
412
|
+
#plan = plan_preprocessing(plan)
|
382
413
|
|
383
|
-
if plan
|
414
|
+
if not plan.nil?
|
384
415
|
plan = extract_sas_plan(plan, parser)
|
385
|
-
sas_task =
|
416
|
+
sas_task = Sfp::Sas::Task.new(sas_file)
|
386
417
|
sas_task.sas_plan = plan
|
387
418
|
|
388
419
|
tmp = []
|
@@ -395,11 +426,10 @@ module Sfp
|
|
395
426
|
end
|
396
427
|
sas_task.goal_operator_name = goal_op
|
397
428
|
plan = tmp
|
398
|
-
end
|
399
429
|
|
400
|
-
|
430
|
+
return plan, sas_task
|
431
|
+
end
|
401
432
|
|
402
|
-
return plan, sas_task
|
403
433
|
rescue Exception => exp
|
404
434
|
raise exp
|
405
435
|
ensure
|
@@ -416,12 +446,11 @@ module Sfp
|
|
416
446
|
planner = nil
|
417
447
|
|
418
448
|
if os == 'linux' and machine[0,3] == 'x86'
|
419
|
-
planner = File.expand_path(File.dirname(__FILE__)
|
449
|
+
planner = File.expand_path("#{File.dirname(__FILE__)}/../../bin/solver/linux-x86")
|
420
450
|
elsif os == 'linux' and machine[0,3] == 'arm'
|
421
|
-
planner = File.expand_path(File.dirname(__FILE__)
|
422
|
-
#Sfp::Planner::Config.set_max_memory(512)
|
451
|
+
planner = File.expand_path("#{File.dirname(__FILE__)}/../../bin/solver/linux-arm")
|
423
452
|
elsif os == 'macos' or os == 'darwin'
|
424
|
-
planner = File.expand_path(File.dirname(__FILE__)
|
453
|
+
planner = File.expand_path("#{File.dirname(__FILE__)}/../../bin/solver/macos")
|
425
454
|
end
|
426
455
|
|
427
456
|
raise UnsupportedPlatformException, "#{os} is not supported" if planner.nil?
|
@@ -489,30 +518,23 @@ module Sfp
|
|
489
518
|
params = Sfp::Planner.parameters(heuristic)
|
490
519
|
timeout = Sfp::Planner::Config.timeout if timeout.nil?
|
491
520
|
|
492
|
-
|
493
|
-
command = case os
|
521
|
+
case `uname -s `.downcase.strip
|
494
522
|
when 'linux'
|
495
|
-
then "cd #{dir}
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
523
|
+
then "cd #{dir} && \
|
524
|
+
ulimit -Sv #{Sfp::Planner::Config.max_memory} && \
|
525
|
+
#{planner}/preprocess < #{sas_file} 2>/dev/null 1>/dev/null && \
|
526
|
+
if [ -f 'output' ]; then \
|
527
|
+
timeout #{timeout} nice #{planner}/downward #{params} \
|
528
|
+
--plan-file #{plan_file} < output 1>>search.log 2>>search.log; fi"
|
501
529
|
when 'macos', 'darwin'
|
502
|
-
then "cd #{dir}
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
530
|
+
then "cd #{dir} && \
|
531
|
+
ulimit -Sv #{Sfp::Planner::Config.max_memory} && \
|
532
|
+
#{planner}/preprocess < #{sas_file} 1>/dev/null 2>/dev/null && \
|
533
|
+
if [ -f 'output' ]; then \
|
534
|
+
nice #{planner}/downward #{params} \
|
535
|
+
--plan-file #{plan_file} < output 1>>search.log 2>>search.log; fi"
|
508
536
|
else nil
|
509
537
|
end
|
510
|
-
|
511
|
-
#if not command.nil? and (os == 'linux' or os == 'macos' or os == 'darwin')
|
512
|
-
# command = "#{command}" #1> /dev/null 2>/dev/null"
|
513
|
-
#end
|
514
|
-
|
515
|
-
command
|
516
538
|
end
|
517
539
|
|
518
540
|
def self.get_search_command(dir, plan_file, heuristic, timeout=nil)
|
@@ -717,10 +739,23 @@ module Sfp
|
|
717
739
|
@timeout = (ENV['SFPLANNER_TIMEOUT'] ? ENV['SFPLANNER_TIMEOUT'].to_i : Sfp::Planner::Config.timeout)
|
718
740
|
end
|
719
741
|
|
742
|
+
def pids(dir='')
|
743
|
+
`ps ax | grep -v grep | grep downward | grep sfplanner | grep '#{dir}' | awk '{print $1" "}'`.to_s.strip.split("\n")
|
744
|
+
end
|
745
|
+
|
720
746
|
def solve
|
747
|
+
def kill(dir='')
|
748
|
+
system "kill -9 #{pids(dir).join(' ')} 1>/dev/null 2>/dev/null"
|
749
|
+
end
|
750
|
+
|
721
751
|
### run preprocessing
|
722
752
|
return false if not do_preprocess
|
723
753
|
|
754
|
+
['HUP', 'KILL', 'INT'].each { |name,id|
|
755
|
+
dir = @dir
|
756
|
+
Signal.trap(name) { kill(dir) }
|
757
|
+
}
|
758
|
+
|
724
759
|
### save current working dir
|
725
760
|
home = Dir.pwd
|
726
761
|
|
@@ -737,19 +772,15 @@ module Sfp
|
|
737
772
|
files << plan_file
|
738
773
|
end
|
739
774
|
|
740
|
-
def processes(dir)
|
741
|
-
`ps ax | grep -v grep | grep downward | grep sfplanner | grep '#{dir}' | awk '{print $1" "}'`.to_s.strip.split("\n")
|
742
|
-
end
|
743
|
-
|
744
775
|
loop do
|
745
|
-
list =
|
776
|
+
list = pids(@dir)
|
746
777
|
break if list.length <= 0
|
747
778
|
finished = files.select { |f| File.exist?(f) }
|
748
779
|
break if finished.length > 0
|
749
780
|
sleep 0.2
|
750
781
|
end
|
751
782
|
|
752
|
-
|
783
|
+
kill(@dir)
|
753
784
|
|
754
785
|
### select best plan
|
755
786
|
selected = nil
|
@@ -774,6 +805,9 @@ module Sfp
|
|
774
805
|
Dir.chdir home
|
775
806
|
false
|
776
807
|
end
|
808
|
+
|
809
|
+
ensure
|
810
|
+
kill(@dir)
|
777
811
|
end
|
778
812
|
|
779
813
|
def do_preprocess
|
data/lib/sfplanner/sas.rb
CHANGED
data/lib/sfplanner.rb
CHANGED
data/sfplanner.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sfplanner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Herry
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sfp
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.3.
|
19
|
+
version: 0.3.20
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.3.
|
26
|
+
version: 0.3.20
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
95
|
version: '0'
|
96
96
|
requirements: []
|
97
97
|
rubyforge_project: sfplanner
|
98
|
-
rubygems_version: 2.
|
98
|
+
rubygems_version: 2.0.14
|
99
99
|
signing_key:
|
100
100
|
specification_version: 4
|
101
101
|
summary: SFPlanner
|