#! /usr/bin/env python

from lab.experiment import Experiment 
from downward.experiment import DownwardExperiment 
from lab.reports import Attribute, avg
from lab.environments import MaiaEnvironment
from lab.environments import LocalEnvironment
from downward.checkouts import Translator, Preprocessor, Planner
from downward.reports.absolute import AbsoluteReport
from downward.reports.suite import SuiteReport
from downward.reports.scatter import ScatterPlotReport


import os
import platform

exp_name = os.path.splitext(os.path.basename(os.path.abspath(__file__)))[0]
EXPPATH = os.path.join(os.path.expanduser('~/workspace/masterthesis/project/experiments/learning/data'), exp_name)

def rename_nick_small(run):
    run['config_nick'] = 'small'
    run['config'] = 'small'
    run['id'].append('small')
    return run

def rename_nick_baseline(run):
    run['config_nick'] = 'baseline'
    run['config'] = 'baseline'
    run['id'].append('baseline')
    return run

def rename_nick_high(run):
    run['config'] = 'high'
    run['config'] = 'high'
    run['id'].append('high')
    return run

def commandline_config_small(run):
	return "astar(bootstrap(method=search , initial_heuristic=ff, number_of_rw=100 , rw_length=50, ann_topology=20, eta=0.002, epochs=500))" in run['commandline_config']
def commandline_config_high(run):
	return "astar(bootstrap(method=search , initial_heuristic=ff, number_of_rw=100 , rw_length=50, ann_topology=100, eta=0.002, epochs=500))" in run['commandline_config']

DEFAULT_ATTRIBUTES = [
    'cost',
    'coverage',
    'error',
    'evaluations_until_last_jump',
    'expansions_until_last_jump',
    'generated_until_last_jump',
    'initial_h_value',
    'memory',
    'run_dir',
    #'search_returncode',
    'search_time',
    'total_time',
    'evaluations',
    'expansions',
    'generated',
]

training_set_size = Attribute('training_set_size', absolute=False, min_wins=True, functions=[avg])

attributes=list(DEFAULT_ATTRIBUTES)
attributes.append(training_set_size)


exp = Experiment(EXPPATH)

exp.add_fetcher('data/experiment_search_topology/', parsers=['learning-parser.py'], name='topology-small', filter=[rename_nick_small, commandline_config_small])
exp.add_fetcher('data/experiment_search_topology/', parsers=['learning-parser.py'], name='topology-high', filter=[rename_nick_high, commandline_config_high])
exp.add_fetcher('data/experiment_search_basic', parsers=['learning-parser.py'], name='search_basic', filter=rename_nick_baseline)

FILTER_CONFIGS = [
	'small',
	'baseline',
	'high'
	#'85a613151f58-85a613151f58-c4916925c01e-bootstrap-search',
]


FILTER_DOMAINS = [
    'airport',
#    'airport-adl',
    'barman-opt11-strips',
    'barman-sat11-strips',
    'blocks',
    'depot',
    'driverlog',
    'elevators-opt08-strips',
    'elevators-opt11-strips',
    'elevators-sat08-strips',
    'elevators-sat11-strips',
    'floortile-opt11-strips',
    'floortile-sat11-strips',
    'freecell',
    'grid',
    'gripper',
    'logistics00',
    'logistics98',
    'miconic',
#    'miconic-simpleadl',
    'movie',
    'mprime',
    'mystery',
    'no-mprime',
    'no-mystery',
    'nomystery-opt11-strips',
    'nomystery-sat11-strips',
    'openstacks-opt08-strips',
    'openstacks-opt11-strips',
#    'openstacks-sat08-adl',
    'openstacks-sat08-strips',
    'openstacks-sat11-strips',
    'openstacks-strips',
    'parcprinter-08-strips',
    'parcprinter-opt11-strips',
    'parcprinter-sat11-strips',
    'parking-opt11-strips',
    'parking-sat11-strips',
    'pathways',
    'pathways-noneg',
    'pegsol-08-strips',
    'pegsol-opt11-strips',
    'pegsol-sat11-strips',
    'pipesworld-notankage',
    'pipesworld-tankage',
    'psr-small',
    'rovers',
    'satellite',
    'scanalyzer-08-strips',
    'scanalyzer-opt11-strips',
    'scanalyzer-sat11-strips',
    'schedule',
    'sokoban-opt08-strips',
    'sokoban-opt11-strips',
    'sokoban-sat08-strips',
    'sokoban-sat11-strips',
    'storage',
    'tidybot-opt11-strips',
    'tidybot-sat11-strips',
    'tpp',
    'transport-opt08-strips',
    'transport-opt11-strips',
    'transport-sat08-strips',
    'transport-sat11-strips',
    'trucks-strips',
    'visitall-opt11-strips',
    'visitall-sat11-strips',
    'woodworking-opt08-strips',
    'woodworking-opt11-strips',
    'woodworking-sat08-strips',
    'woodworking-sat11-strips',
    'zenotravel'
]

exp.add_report(AbsoluteReport(resolution='combined', attributes=attributes, filter_config=FILTER_CONFIGS, filter_domain=FILTER_DOMAINS), name='make-report', outfile='report-abs-p.html')
exp.add_report(AbsoluteReport(resolution='combined', attributes=attributes, filter_config=FILTER_CONFIGS, filter_domain=FILTER_DOMAINS, format='tex'), name='make-report-tex', outfile='experiment-compare-samples.tex')

exp()
