本文整理汇总了C#中Domain.GroundAllActions方法的典型用法代码示例。如果您正苦于以下问题:C# Domain.GroundAllActions方法的具体用法?C# Domain.GroundAllActions怎么用?C# Domain.GroundAllActions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Domain
的用法示例。
在下文中一共展示了Domain.GroundAllActions方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RadnomSolve
public List<Action> RadnomSolve(Problem p, Domain d)
{
State sStart = p.GetInitialBelief().ChooseState(true);
List<Action> lActions = d.GroundAllActions(sStart.Predicates, false);
int iRnd = RandomGenerator.Next(lActions.Count);
List<Action> lPlan = new List<Action>();
lPlan.Add(lActions[iRnd]);
return lPlan;
}
示例2: ManualSolve
public List<Action> ManualSolve(Problem p, Domain d)
{
State sStart = p.GetInitialBelief().ChooseState(true);
State sCurrent = null, sNext = null;
Dictionary<State, Action> dMapStateToGeneratingAction = new Dictionary<State, Action>();
dMapStateToGeneratingAction[sStart] = null;
Dictionary<State, State> dParents = new Dictionary<State, State>();
dParents[sStart] = null;
int cProcessed = 0;
List<string> lActionNames = new List<string>();
sCurrent = sStart;
while (!p.IsGoalState(sCurrent))
{
List<Action> lActions = d.GroundAllActions(sCurrent.Predicates, false);
Debug.WriteLine("Available actions:");
for (int i = 0; i < lActions.Count; i++)
{
Debug.WriteLine(i + ") " + lActions[i].Name);
}
Debug.Write("Choose action number: ");
int iAction = int.Parse(Console.ReadLine());
Action a = lActions[iAction];
sNext = sCurrent.Apply(a);
foreach (Predicate pNew in sNext.Predicates)
if (!sCurrent.Predicates.Contains(pNew))
Debug.WriteLine(pNew);
if (!dParents.Keys.Contains(sNext))
{
dParents[sNext] = sCurrent;
dMapStateToGeneratingAction[sNext] = a;
}
sCurrent = sNext;
cProcessed++;
}
return GeneratePlan(sCurrent, null, dParents, dMapStateToGeneratingAction);
}
示例3: ObserveAll
private State ObserveAll(State s, List<Action> lActions, Domain d)
{
State sCurrent = s;
List<Action> l = d.GroundAllActions(s.Predicates, false);
foreach (Action a in l)
{
if (a.Name.Contains("observe"))
{
sCurrent = sCurrent.Apply(a);
lActions.Add(a);
}
}
return sCurrent;
}
示例4: SolveII
public List<Action> SolveII(Problem p, Domain d)
{
State sStart = p.GetInitialBelief().ChooseState(true);
List<State> lOpenList = new List<State>();
lOpenList.Add(sStart);
State sCurrent = null, sNext = null;
Dictionary<State, Action> dMapStateToGeneratingAction = new Dictionary<State, Action>();
dMapStateToGeneratingAction[sStart] = null;
Dictionary<State, State> dParents = new Dictionary<State, State>();
Dictionary<State, int> dDepth = new Dictionary<State, int>();
dDepth[sStart] = 0;
dParents[sStart] = null;
int cProcessed = 0;
List<string> lActionNames = new List<string>();
while (lOpenList.Count > 0)
{
sCurrent = lOpenList[0];
lOpenList.RemoveAt(0);
List<Action> lActions = d.GroundAllActions(sCurrent.Predicates, false);
foreach (Action a in lActions)
{
sNext = sCurrent.Apply(a);
bool bGiven = false;
foreach (Predicate pGiven in sNext.Predicates)
{
if (pGiven.Name.ToLower().Contains("given"))
bGiven = true;
}
if (!lActionNames.Contains(a.Name))
lActionNames.Add(a.Name);
if (sNext != null && p.IsGoalState(sNext))
return GeneratePlan(sCurrent, a, dParents, dMapStateToGeneratingAction);
if (!dParents.Keys.Contains(sNext))
{
dDepth[sNext] = dDepth[sCurrent] + 1;
dParents[sNext] = sCurrent;
dMapStateToGeneratingAction[sNext] = a;
lOpenList.Add(sNext);
}
}
cProcessed++;
if (cProcessed % 10 == 0)
Debug.WriteLine(cProcessed + ") " + dDepth[sCurrent] + "," + lOpenList.Count);
}
return null;
}
示例5: IdentifyLandmarks
public void IdentifyLandmarks(Problem p, Domain d)
{
//State s0 = p.GetInitialBelief().ChooseState(true);
Console.WriteLine("Started identifying landmarks");
HashSet<Predicate> lInitialState = new HashSet<Predicate>(p.Known);
lInitialState = CompleteNegations(lInitialState, d);
List<Formula> lLandmarks = new List<Formula>();
Queue<Formula> qOpenLandmarks = new Queue<Formula>();
Console.WriteLine("Grounding actions");
List<Action> lGrounded = d.GroundAllActions(p);
Console.WriteLine("Removing disjunctions, conditional effects, and filtering impossible actions");
List<Action> lNoDisjunctions = RemoveDisjunctions(lGrounded);//remove disjunctions before grounding?
List<Action> lSimple = RemoveConditions(lNoDisjunctions);
lSimple = FilterImpossible(lSimple, lInitialState, d);
//lSimple = RemoveNegativePreconditions(lSimple);//need to remove this! enables many illegal actions - must work with complete positive and negative specification
Dictionary<Predicate, List<Action>> dPreconditionToAction = new Dictionary<Predicate, List<Action>>();
Dictionary<Predicate, List<Action>> dEffectToAction = new Dictionary<Predicate, List<Action>>();
ClassifyActions(lSimple, dPreconditionToAction, dEffectToAction);
Console.WriteLine("Processing landmarks");
foreach (Predicate pLandmark in p.Goal.GetAllPredicates())
{
lLandmarks.Add(new PredicateFormula(pLandmark));
qOpenLandmarks.Enqueue(new PredicateFormula(pLandmark));
}
Dictionary<Predicate, List<Formula>> dLandmarksForPredicate = new Dictionary<Predicate, List<Formula>>();
int cProcessed = 0;
while (qOpenLandmarks.Count > 0)
{
Formula fCurrent = qOpenLandmarks.Dequeue();
List<Action> lFiltered = new List<Action>(), lPotentialLandmarkAchievers = new List<Action>();
FilterActions(lSimple, fCurrent, lFiltered, lPotentialLandmarkAchievers, dPreconditionToAction, dEffectToAction, lInitialState);
HashSet<Predicate> lAllReachable = ReachablePredicates(lInitialState, lFiltered);
Dictionary<Predicate, List<Action>> dLandmarkAchievers = GetLandmarkAchievers(fCurrent, lAllReachable, lPotentialLandmarkAchievers);
List<Formula> lNewLandmarks = RegressLandmark(fCurrent, dLandmarkAchievers, lInitialState);
foreach (Formula fNew in lNewLandmarks)
{
bool bAlreadyFound = false;
foreach (Predicate pLandmark in fNew.GetAllPredicates())
{
if (!dLandmarksForPredicate.ContainsKey(pLandmark))
dLandmarksForPredicate[pLandmark] = new List<Formula>();
else
{
foreach (Formula fExisting in dLandmarksForPredicate[pLandmark])
{
if (fExisting.Size <= fNew.Size)
bAlreadyFound = true;
}
}
dLandmarksForPredicate[pLandmark].Add(fNew);
}
if (!bAlreadyFound)
{
qOpenLandmarks.Enqueue(fNew);
lLandmarks.Add(fNew);
}
}
cProcessed++;
if (cProcessed % 10 == 0)
Console.WriteLine("Processed " + cProcessed + " found " + lLandmarks.Count + " in queue " + qOpenLandmarks.Count);
}
StreamWriter sw = new StreamWriter("D:\\" + d.Name + ".Landmarks.txt");
foreach (Formula f in lLandmarks)
sw.WriteLine(f);
sw.Close();
}