Skip to content

Commit

Permalink
Support unordered tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Maumagnaguagno committed Oct 1, 2023
1 parent e4b2fd3 commit faa39c5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions Hypertension_U.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def execute(current_task, probability, tasks, level, plan)
# Problem
#-----------------------------------------------

def problem(state, tasks, debug = false, max_plans = -1, min_prob = 0)
def problem(state, tasks, debug = false, max_plans = -1, min_prob = 0, ordered = true)
@nostack = false
@debug = debug
@state = state
Expand All @@ -118,7 +118,7 @@ def problem(state, tasks, debug = false, max_plans = -1, min_prob = 0)
print_data(tasks)
puts 'Planning'.center(50,'-')
t = Time.now.to_f
planning(tasks)
ordered ? planning(tasks) : task_permutations(state, tasks)
puts "Time: #{Time.now.to_f - t}s", "Plans found: #{@plans.size}"
if @plans.each_with_index {|(probability,valuation,*plan),i|
puts "Plan #{i.succ}".center(50,'-'),
Expand All @@ -136,4 +136,18 @@ def problem(state, tasks, debug = false, max_plans = -1, min_prob = 0)
rescue
puts $!, $@
end

#-----------------------------------------------
# Task permutations
#-----------------------------------------------

def task_permutations(state, tasks)
# All permutations are considered
tasks.permutation {|task_list|
@state = state
task_list = Marshal.load(Marshal.dump(task_list))
planning(task_list)
return if @plans.size == @max_plans
}
end
end
2 changes: 1 addition & 1 deletion UHyper_Compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def compile_problem(domain_name, problem_name, operators, methods, predicates, s
# Tasks
problem_str << "\n },\n # Tasks\n [" <<
tasks.map! {|task,*terms| "\n ['#{task}'#{terms.map! {|o| o.instance_of?(String) ? o.match?(/^-?\d/) ? ", '#{o.to_f}'" : ', _' << o : ', ' << evaluate(o, namespace)}.join}]"}.join(',') <<
"\n ],\n # Debug\n ARGV.first == 'debug',\n # Maximum plans found\n ARGV[1] ? ARGV[1].to_i : -1,\n # Minimum probability for plans\n ARGV[2] ? ARGV[2].to_f : 0"
"\n ],\n # Debug\n ARGV.first == 'debug',\n # Maximum plans found\n ARGV[1] ? ARGV[1].to_i : -1,\n # Minimum probability for plans\n ARGV[2] ? ARGV[2].to_f : 0#{",\n # Ordered\n false" unless ordered}"
tasks.unshift(ordered) unless tasks.empty?
problem_str.gsub!(/\b-\b/,'_')
domain_filename ? "# Generated by Hype\nrequire_relative '#{domain_filename}'\n\n#{problem_str}\n)" : "#{problem_str}\n)"
Expand Down

0 comments on commit faa39c5

Please sign in to comment.