Exemplo n.º 1
0
 def GetThingAvailablePre(self):
     dThingAvailable = {};
     for precondition in self.lPreconditions:
         tIncrease = precondition.GetThingAvailable(bGreaterThan = True);
         if tIncrease != None:
             dThingAvailable[tIncrease[0]]= tIncrease[1];
     data.print_obj(dThingAvailable);
def _get_config (_sConfig):
	global map_Config

	sValue = map_Config.get (_sConfig, None)
	if None == sValue:
		print "Dict:";
		data.print_obj(map_Config);
		print "[ERROR] '" + _sConfig + "' not found in config."
		data.print_obj(map_Config);
		assert False, "[ERROR] '" + _sConfig + "' not found in config."
		#return ''
	return sValue
 def CheckConnections(self):
     if self.iIndex in [6281]:
         return;
     for conn in self.lConnections:
         if self.deptree.dIndexToWord[conn.iTo] != conn.sTo:
             print "Index:", self.iIndex;
             print "Dep:"
             data.print_obj(self.deptree.dIndexToWord);
             print "Conn:";
             data.print_obj(conn);
         assert(self.deptree.dIndexToWord[conn.iFrom] == conn.sFrom);
         assert(self.deptree.dIndexToWord[conn.iTo] == conn.sTo);
def GenTrainingSamples(sAugmentedGoldSubgoalsFile, sTrainingFile):
    lGold = data.file_to_obj(sAugmentedGoldSubgoalsFile);
    iSubgoalIndex = 0;
    lSamples = [];
    for iIndex, dGold in enumerate(lGold[:min(len(lGold), MAXNUMPROBLEMS)]):
        # skip the ones without the right answer
        print "Running on:", dGold['file'], iIndex, "out of", len(lGold);
        data.print_obj(dGold['subgoals']);
        if ('success' in dGold) and (not dGold['success']):
            continue;
        if len(dGold['subgoals']) < 2:
            print "Skipping:", dGold['file'], 'because no subgoals';
            # if there's no read "sub"-goals, then just skip this one
            continue;
        GenSamplesOneProblem(dGold, lSamples);

    return lSamples;
def GetSubgoalsForAll(bValidate, bRebuildObjectives):
    sDomainFile = '../subgoal_learning/data/domain-no-stone-iron-tools-simple-furnace.v120.pddl';
    sProblemPath = '../subgoal_learning/data/problems/no-stone-iron-tools-and-extra-resources-rand2/'
    sFFPath = '/home/nkushman/hierarchical_planning/ff/metric-ff-recompiled-2011-11-24-2';
    sMainPath = '/home/nkushman/hierarchical_planning/model/subgoal_learning/lhla_v4 /home/nkushman/hierarchical_planning/model/subgoal_learning/run_compute_end_state.cfg';
    sNumSubgoalsFile = 'thing-available_max5.gold_num_subgoals';
    dDeps = data.file_to_obj_with_comments('dep.json');
    if bRebuildObjectives:
        GetAllObjectives(sDomainFile, sProblemPath);
    lObjectives = data.file_to_obj('objectives.json');
    setObjectives = set();
    lOutput = [];
    for iIndex, tObjective in enumerate(lObjectives):
        dCurOutput = {'file':tObjective[0], 'thing':tObjective[1], 'num':tObjective[2]}
        if iIndex < 0:
            print "Skipping:", iIndex, tObjective;
            continue;
        sys.stdout.flush();
        print "****Objective:", iIndex, tObjective;
        lSubgoals = GenSubgoals(dDeps, tObjective[1], tObjective[2]);
        lSubgoalsToValidate = TransformToValidateFormat(lSubgoals);
        print "Plan:";
        data.print_obj(lSubgoalsToValidate);
        sTempProblemPath = 'tmp-no-shovel/test.' + tObjective[0] + '.subgoals';
        if bValidate:
            bSuccess = SubgoalValidator.TestSubgoals(sDomainFile, sProblemPath + tObjective[0], lSubgoalsToValidate,
                                                     sFFPath, sMainPath, sTempProblemPath, bOptimize = False);
            dCurOutput['success'] = bSuccess;
            print "Success:", bSuccess;
        # include them all
        for dSubgoal in lSubgoals:
            setObjectives.add(FormatSubgoal(dSubgoal));

        dCurOutput['subgoals'] = lSubgoals;
        dCurOutput['subgoals-formatted'] = lSubgoalsToValidate;
        dCurOutput['index'] = iIndex;
        lOutput.append(dCurOutput);
        #data.print_obj(lSubgoals);
    data.obj_to_file(lOutput, 'subgoals_gold.json');
    dIndexToPred, dPredToIndex = GenerateIndexesFromPredDict('pred_gold.txt', setObjectives);
    WriteConnectionsFile(dDeps, dPredToIndex, dIndexToPred, 'pred_gold_connections.txt');
    WriteNumSubgoalsFile(lOutput, sNumSubgoalsFile);
def Run3():
    dDeps = data.file_to_obj_with_comments('dep.json');
    lSubgoals = GenSubgoals(dDeps, "fish", 1);
    data.print_obj(lSubgoals);