From faa39c55964f9f1fc44744eb7edaed1964104a6c Mon Sep 17 00:00:00 2001 From: Mau Magnaguagno Date: Sun, 1 Oct 2023 06:54:00 -0300 Subject: [PATCH] Support unordered tasks --- Hypertension_U.rb | 18 ++++++++++++++++-- UHyper_Compiler.rb | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Hypertension_U.rb b/Hypertension_U.rb index f615807..61633da 100644 --- a/Hypertension_U.rb +++ b/Hypertension_U.rb @@ -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 @@ -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,'-'), @@ -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 \ No newline at end of file diff --git a/UHyper_Compiler.rb b/UHyper_Compiler.rb index 9c2f54d..af342d5 100644 --- a/UHyper_Compiler.rb +++ b/UHyper_Compiler.rb @@ -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)"