注册 登录
编程论坛 JAVA论坛

两道算法题,我们老师说没人能写出来

yang158 发布于 2021-06-29 17:09, 1323 次点击
1.前向搜索规划伪代码
ForwardSearching(KB, InitState, GoalState)
Input:KB, state space and action modes;
        InitState, start state;
        GoalState, objective;
Output:an action sequence or failure;

currState <-- {InitState};
plan <-- { };
Respeat
    if currState satisfies GoalState
        return plan;
    applicable <-- {a | a is a ground operator in KB that Precond(a) is true in currState};
    if applicable =  Ø
        return failure;
    a = ChooseAction(applicable);
    currState <-- Effect(a);
    plan <-- plan ∪ a;
    Utill Maximum Iteration.

2.FOLL算法伪代码
FOLLAlg(Target, TrainData)
Input:Target, post - condition predicate;
        TrainData, training samples;
Output:Rules.

PosSamples <-- Positive Samples of TrainData;
NegSamples <-- Negative Samples of TrainData;
Rules <-- { };
While PosSamples is not empty, do
    Clause <-- Target with empty pre - condition;
NewNegSamples <-- NegSamples;
While NewNegSamples is not empty, do
    LiteralCan <-- GetLiteralCandidates(TrainData);
    BestLiteral <-- arg max I ∈ LiteraICan Gain(I, TrainData, Clause);
    Add BestLiteral to the pre - condition of Clause;
    Remove samples from NewNegSamples that satisfy Clause;
Rules <-- Rules + Clause;
Remove samples from PosSamples that satisfy Rules;
Reurn Rules.
0 回复
1