"hHMax=hmax()",
            "--heuristic",
            "hCea=cea(cost_type=0)",
            "--heuristic",
            "hLM=lmcount(lmg,admissible=false,pref=true,cost_type=1)",
            "--search",
            "lazy(alt([single(sum([weight(g(),2),weight(hLM,3)])),single(sum([weight(g(),2),weight(hLM,3)]),pref_only=true),single(sum([weight(g(),2),weight(hHMax,3)])),single(sum([weight(g(),2),weight(hHMax,3)]),pref_only=true),single(sum([weight(g(),2),weight(hCg,3)])),single(sum([weight(g(),2),weight(hCg,3)]),pref_only=true),single(sum([weight(g(),2),weight(hCea,3)])),single(sum([weight(g(),2),weight(hCea,3)]),pref_only=true),single(sum([weight(g(),2),weight(hGoalCount,3)])),single(sum([weight(g(),2),weight(hGoalCount,3)]),pref_only=true)],boost=2508),preferred=[hCea,hGoalCount],reopen_closed=false,cost_type=0,bound=BOUND)"
        ]
    ],
    [
        1,
        [
            "--landmarks",
            "lmg=lm_exhaust(reasonable_orders=false,only_causal_landmarks=false,disjunctive_landmarks=true,conjunctive_landmarks=true,no_orders=false,cost_type=1)",
            "--heuristic",
            "hFF=ff(cost_type=2)",
            "--heuristic",
            "hHMax=hmax()",
            "--heuristic",
            "hBlind=blind()",
            "--heuristic",
            "hLM=lmcount(lmg,admissible=true,pref=false,cost_type=1)",
            "--search",
            "lazy(alt([single(sum([g(),weight(hBlind,3)])),single(sum([g(),weight(hBlind,3)]),pref_only=true),single(sum([g(),weight(hFF,3)])),single(sum([g(),weight(hFF,3)]),pref_only=true),single(sum([g(),weight(hLM,3)])),single(sum([g(),weight(hLM,3)]),pref_only=true),single(sum([g(),weight(hHMax,3)])),single(sum([g(),weight(hHMax,3)]),pref_only=true)],boost=3052),preferred=[hFF],reopen_closed=true,cost_type=0,bound=BOUND)"
        ]
    ]
]

if __name__ == '__main__':
    portfolio.run(CONFIGS, optimal=False)
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import portfolio

CONFIGS = [
    (175, [
        "--search",
        "astar(merge_and_shrink(merge_strategy=merge_linear(variable_order=reverse_level),shrink_strategy=shrink_bisimulation(max_states=infinity,threshold=1,greedy=true,group_by_h=false)))"
    ]),
    (432, [
        "--search",
        "astar(merge_and_shrink(merge_strategy=merge_linear(variable_order=reverse_level),shrink_strategy=shrink_bisimulation(max_states=200000,greedy=false,group_by_h=true)))"
    ]),
    (455, [
        "--search",
        "astar(lmcount(lm_merged([lm_rhw(),lm_hm(m=1)]),admissible=true),mpd=true)"
    ]),
    (569, ["--search", "astar(lmcut())"]),
]

portfolio.run(CONFIGS, optimal=True)
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import portfolio

CONFIGS = [
    (175, ["--search",
           "astar(merge_and_shrink(merge_strategy=merge_linear_reverse_level,shrink_strategy=shrink_bisimulation(max_states=infinity,threshold=1,greedy=true,group_by_h=false)))"]),
    (432, ["--search",
           "astar(merge_and_shrink(merge_strategy=merge_linear_reverse_level,shrink_strategy=shrink_bisimulation(max_states=200000,greedy=false,group_by_h=true)))"]),
    (455, ["--search",
           "astar(lmcount(lm_merged([lm_rhw(),lm_hm(m=1)]),admissible=true),mpd=true)"]),
    (569, ["--search",
           "astar(lmcut())"]),
     ]

portfolio.run(CONFIGS, optimal=True)

          "--search",
          "lazy_wastar(h,w=3,preferred=h,cost_type=S_COST_TYPE,bound=BOUND)"]),
    # eager_greedy_cea_1
    (84, ["--heuristic", "h=cea(cost_type=H_COST_TYPE)",
          "--search",
          "eager_greedy(h,preferred=h,cost_type=S_COST_TYPE,bound=BOUND)"]),
    # eager_wa3_add_1
    (166, ["--heuristic", "h=add(cost_type=H_COST_TYPE)",
          "--search",
          "eager(single(sum([g(),weight(h,3)])),preferred=h,cost_type=S_COST_TYPE,bound=BOUND)"]),
    # eager_wa3_ff_1
    (87, ["--heuristic", "h=ff(cost_type=H_COST_TYPE)",
          "--search",
          "eager(single(sum([g(),weight(h,3)])),preferred=h,cost_type=S_COST_TYPE,bound=BOUND)"]),
    # lazy_wa3_cg_1
    (73, ["--heuristic", "h=cg(cost_type=H_COST_TYPE)",
         "--search",
         "lazy_wastar(h,w=3,preferred=h,cost_type=S_COST_TYPE,bound=BOUND)"]),
    # eager_wa3_cg_1
    (89, ["--heuristic", "h=cg(cost_type=H_COST_TYPE)",
          "--search",
          "eager(single(sum([g(),weight(h,3)])),preferred=h,cost_type=S_COST_TYPE,bound=BOUND)"]),
     ]

FINAL_CONFIG = [
    "--heuristic", "h=ff(cost_type=H_COST_TYPE)",
    "--search",
    "iterated(eager(single(sum([g(),weight(h,3)])),preferred=h,cost_type=S_COST_TYPE,bound=BOUND),bound=BOUND,repeat_last=true,plan_counter=PLANCOUNTER)"]

portfolio.run(configs=CONFIGS, optimal=False, final_config=FINAL_CONFIG)
            "--heuristic",
            "h=add(cost_type=H_COST_TYPE)",
            "--search",
            "lazy_greedy(h,preferred=h,cost_type=S_COST_TYPE,bound=BOUND)",
        ],
    ),
]


def build_final_config(successful_args):
    # this heavily depends on that in CONFIGS only "simple" configurations are used
    new_args = list(successful_args)
    for pos, arg in enumerate(successful_args):
        if arg == "--search":
            orig_search = successful_args[pos + 1]
            sub_searches = []
            for weight in (5, 3, 2, 1):
                if orig_search.startswith("lazy"):
                    sub_search = "lazy_wastar(h,preferred=h,w=%d,cost_type=S_COST_TYPE)" % weight
                else:
                    sub_search = "eager(single(sum([g(),weight(h,%d)])),preferred=h,cost_type=S_COST_TYPE)" % weight
                sub_searches.append(sub_search)
            sub_search_string = ",".join(sub_searches)
            new_search = "iterated([%s],bound=BOUND,repeat_last=true,plan_counter=PLANCOUNTER)" % sub_search_string
            new_args[pos + 1] = new_search
            break
    return new_args


portfolio.run(configs=CONFIGS, optimal=False, final_config_builder=build_final_config)
    ],
    [
        14,
        [
            "--landmarks",
            "lmg=lm_zg(reasonable_orders=true,only_causal_landmarks=false,disjunctive_landmarks=true,conjunctive_landmarks=true,no_orders=false,cost_type=1)",
            "--heuristic", "hCg=cg(cost_type=1)", "--heuristic",
            "hGoalCount=goalcount(cost_type=0)", "--heuristic", "hHMax=hmax()",
            "--heuristic", "hCea=cea(cost_type=0)", "--heuristic",
            "hLM=lmcount(lmg,admissible=false,pref=true,cost_type=1)",
            "--search",
            "lazy(alt([single(sum([weight(g(),2),weight(hLM,3)])),single(sum([weight(g(),2),weight(hLM,3)]),pref_only=true),single(sum([weight(g(),2),weight(hHMax,3)])),single(sum([weight(g(),2),weight(hHMax,3)]),pref_only=true),single(sum([weight(g(),2),weight(hCg,3)])),single(sum([weight(g(),2),weight(hCg,3)]),pref_only=true),single(sum([weight(g(),2),weight(hCea,3)])),single(sum([weight(g(),2),weight(hCea,3)]),pref_only=true),single(sum([weight(g(),2),weight(hGoalCount,3)])),single(sum([weight(g(),2),weight(hGoalCount,3)]),pref_only=true)],boost=2508),preferred=[hCea,hGoalCount],reopen_closed=false,cost_type=0,bound=BOUND)"
        ]
    ],
    [
        1,
        [
            "--landmarks",
            "lmg=lm_exhaust(reasonable_orders=false,only_causal_landmarks=false,disjunctive_landmarks=true,conjunctive_landmarks=true,no_orders=false,cost_type=1)",
            "--heuristic", "hFF=ff(cost_type=2)", "--heuristic",
            "hHMax=hmax()", "--heuristic", "hBlind=blind()", "--heuristic",
            "hLM=lmcount(lmg,admissible=true,pref=false,cost_type=1)",
            "--search",
            "lazy(alt([single(sum([g(),weight(hBlind,3)])),single(sum([g(),weight(hBlind,3)]),pref_only=true),single(sum([g(),weight(hFF,3)])),single(sum([g(),weight(hFF,3)]),pref_only=true),single(sum([g(),weight(hLM,3)])),single(sum([g(),weight(hLM,3)]),pref_only=true),single(sum([g(),weight(hHMax,3)])),single(sum([g(),weight(hHMax,3)]),pref_only=true)],boost=3052),preferred=[hFF],reopen_closed=true,cost_type=0,bound=BOUND)"
        ]
    ]
]

if __name__ == '__main__':
    portfolio.run(CONFIGS, optimal=False)
        "lazy_greedy(h,preferred=h,cost_type=S_COST_TYPE,bound=BOUND)"
    ]),
]


def build_final_config(successful_args):
    # this heavily depends on that in CONFIGS only "simple" configurations are used
    new_args = list(successful_args)
    for pos, arg in enumerate(successful_args):
        if arg == "--search":
            orig_search = successful_args[pos + 1]
            sub_searches = []
            for weight in (5, 3, 2, 1):
                if orig_search.startswith("lazy"):
                    sub_search = \
                        "lazy_wastar(h,preferred=h,w=%d,cost_type=S_COST_TYPE)" % weight
                else:
                    sub_search = \
                        "eager(single(sum([g(),weight(h,%d)])),preferred=h,cost_type=S_COST_TYPE)" % weight
                sub_searches.append(sub_search)
            sub_search_string = ",".join(sub_searches)
            new_search = "iterated([%s],bound=BOUND,repeat_last=true,plan_counter=PLANCOUNTER)" % sub_search_string
            new_args[pos + 1] = new_search
            break
    return new_args


portfolio.run(configs=CONFIGS,
              optimal=False,
              final_config_builder=build_final_config)
    (85, [u'--heuristic', u'hCea=cea(cost_type=2)', u'--search', u'lazy(alt([single(sum([g(),weight(hCea, 5)])),single(sum([g(),weight(hCea, 5)]),pref_only=true)], boost=1000),preferred=[hCea],reopen_closed=false,cost_type=2,bound=BOUND)']),
    # optical-telegraphs
    (85, [u'--heuristic', u'hCg=cg(cost_type=1)', u'--heuristic', u'hFF=ff(cost_type=1)', u'--search', u'lazy(alt([single(sum([g(),weight(hFF,10)])),single(sum([g(),weight(hFF,10)]),pref_only=true),single(sum([g(),weight(hCg, 10)])),single(sum([g(),weight(hCg,10)]),pref_only=true)],boost=100),preferred=[hCg],reopen_closed=false,cost_type=1,bound=BOUND)']),
    # pathways
    (85, [u'--landmarks', u'lmg=lm_hm(only_causal_landmarks=false,disjunctive_landmarks=true,conjunctive_landmarks=false,no_orders=true,m=1,lm_cost_type=0,cost_type=2)', u'--heuristic', u'hLM,hFF=lm_ff_syn(lmg,admissible=true)', u'--search', u'lazy(alt([single(hLM),single(hLM,pref_only=true),single(hFF),single(hFF,pref_only=true)], boost=5000),preferred=[hLM],reopen_closed=false,cost_type=0,bound=BOUND)']),
    # philosophers
    (85, [u'--heuristic', u'hCg=cg(cost_type=2)', u'--search', u'lazy(alt([single(sum([g(),weight(hCg, 10)])),single(sum([g(),weight(hCg, 10)]),pref_only=true)], boost=0),preferred=[hCg],reopen_closed=false,cost_type=2,bound=BOUND)']),
    # pipesworld-notankage
    (85, [u'--landmarks', u'lmg=lm_merged([lm_rhw(),lm_hm(m=1)],only_causal_landmarks=false,disjunctive_landmarks=false,conjunctive_landmarks=true,no_orders=false)', u'--heuristic', u'hFF=ff(cost_type=0)', u'--heuristic', u'hLM=lmcount(lmg,admissible=true)', u'--search', u'lazy(alt([single(sum([g(),weight(hFF, 10)])),single(sum([g(),weight(hFF, 10)]),pref_only=true),single(sum([g(),weight(hLM, 10)])),single(sum([g(),weight(hLM, 10)]),pref_only=true)], boost=500),preferred=[hFF],reopen_closed=false,cost_type=2,bound=BOUND)']),
    # pipesworld-tankage
    (85, [u'--heuristic', u'hFF=ff(cost_type=1)', u'--search', u'lazy(alt([single(sum([g(),weight(hFF, 7)])),single(sum([g(),weight(hFF, 7)]),pref_only=true)], boost=5000),preferred=[hFF],reopen_closed=false,cost_type=1,bound=BOUND)']),
    # psr-large
    (85, [u'--heuristic', u'hAdd=add(cost_type=0)', u'--search', u'lazy(alt([single(hAdd),single(hAdd,pref_only=true)], boost=0),preferred=[hAdd],reopen_closed=true,cost_type=0,bound=BOUND)']),
    # rovers
    (85, [u'--landmarks', u'lmg=lm_hm(only_causal_landmarks=false,disjunctive_landmarks=true,conjunctive_landmarks=true,no_orders=false,m=1,lm_cost_type=2,cost_type=0)', u'--heuristic', u'hLM,hFF=lm_ff_syn(lmg,admissible=true)', u'--search', u'lazy(alt([tiebreaking([sum([g(),weight(hLM, 10)]),hLM]),tiebreaking([sum([g(),weight(hLM, 10)]),hLM],pref_only=true),tiebreaking([sum([g(),weight(hFF, 10)]),hFF]),tiebreaking([sum([g(),weight(hFF, 10)]),hFF],pref_only=true)], boost=200),preferred=[hLM],reopen_closed=true,cost_type=2,bound=BOUND)']),
    # satellite
    (85, [u'--heuristic', u'hCg=cg(cost_type=2)', u'--search', u'lazy(alt([single(hCg),single(hCg,pref_only=true)], boost=0),preferred=[hCg],reopen_closed=true,cost_type=2,bound=BOUND)']),
    # schedule
    (85, [u'--landmarks', u'lmg=lm_hm(only_causal_landmarks=false,disjunctive_landmarks=true,conjunctive_landmarks=false,no_orders=true,m=1,lm_cost_type=1,cost_type=0)', u'--heuristic', u'hLM,hFF=lm_ff_syn(lmg,admissible=true)', u'--search', u'lazy(alt([single(hLM),single(hLM,pref_only=true),single(hFF),single(hFF,pref_only=true)], boost=1000),preferred=[hLM,hFF],reopen_closed=false,cost_type=1,bound=BOUND)']),
    # storage
    (85, [u'--landmarks', u'lmg=lm_hm(only_causal_landmarks=false,disjunctive_landmarks=true,conjunctive_landmarks=false,no_orders=true,m=1)', u'--heuristic', u'hCg=cg(cost_type=1)', u'--heuristic', u'hLM=lmcount(lmg,admissible=true)', u'--search', u'lazy(alt([single(hLM),single(hLM,pref_only=true),single(hCg),single(hCg,pref_only=true)], boost=0),preferred=[hCg],reopen_closed=false,cost_type=1,bound=BOUND)']),
    # tpp
    (85, [u'--landmarks', u'lmg=lm_hm(only_causal_landmarks=false,disjunctive_landmarks=true,conjunctive_landmarks=false,no_orders=true,m=1,lm_cost_type=0,cost_type=2)', u'--heuristic', u'hLM,hFF=lm_ff_syn(lmg,admissible=true)', u'--search', u'lazy(alt([single(sum([g(),weight(hLM, 10)])),single(sum([g(),weight(hLM, 10)]),pref_only=true),single(sum([g(),weight(hFF, 10)])),single(sum([g(),weight(hFF, 10)]),pref_only=true)], boost=500),preferred=[hLM],reopen_closed=false,cost_type=0,bound=BOUND)']),
    # trucks-strips
    (85, [u'--heuristic', u'hFF=ff(cost_type=1)', u'--search', u'lazy(alt([single(sum([weight(g(), 2),weight(hFF, 3)])),single(sum([weight(g(), 2),weight(hFF, 3)]),pref_only=true)], boost=5000),preferred=[hFF],reopen_closed=true,cost_type=1,bound=BOUND)']),
    # zenotravel
    (85, [u'--heuristic', u'hCg=cg(cost_type=1)', u'--search', u'lazy(tiebreaking([sum([g(),weight(hCg, 2)]),hCg]),preferred=[],reopen_closed=true,cost_type=1,bound=BOUND)'])
]

portfolio.run(configs=CONFIGS, optimal=False, timeout=1800)
        "eager_greedy(h,preferred=h,cost_type=S_COST_TYPE,bound=BOUND)"
    ]),
    # eager_wa3_add_1
    (166, [
        "--heuristic", "h=add(cost_type=H_COST_TYPE)", "--search",
        "eager(single(sum([g(),weight(h,3)])),preferred=h,cost_type=S_COST_TYPE,bound=BOUND)"
    ]),
    # eager_wa3_ff_1
    (87, [
        "--heuristic", "h=ff(cost_type=H_COST_TYPE)", "--search",
        "eager(single(sum([g(),weight(h,3)])),preferred=h,cost_type=S_COST_TYPE,bound=BOUND)"
    ]),
    # lazy_wa3_cg_1
    (73, [
        "--heuristic", "h=cg(cost_type=H_COST_TYPE)", "--search",
        "lazy_wastar(h,w=3,preferred=h,cost_type=S_COST_TYPE,bound=BOUND)"
    ]),
    # eager_wa3_cg_1
    (89, [
        "--heuristic", "h=cg(cost_type=H_COST_TYPE)", "--search",
        "eager(single(sum([g(),weight(h,3)])),preferred=h,cost_type=S_COST_TYPE,bound=BOUND)"
    ]),
]

FINAL_CONFIG = [
    "--heuristic", "h=ff(cost_type=H_COST_TYPE)", "--search",
    "iterated(eager(single(sum([g(),weight(h,3)])),preferred=h,cost_type=S_COST_TYPE,bound=BOUND),bound=BOUND,repeat_last=true,plan_counter=PLANCOUNTER)"
]

portfolio.run(configs=CONFIGS, optimal=False, final_config=FINAL_CONFIG)