Prolog 人工智能语言中文论坛---打造优质Prolog学习交流园地
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Prolog 人工智能语言中文论坛---打造优质Prolog学习交流园地

一个供Prolog爱好者学习与交流的地方


您没有登录。 请登录注册

问题

3 posters

向下  留言 [第1页/共1页]

1问题 Empty 问题 周三 十一月 21, 2012 5:57 am

xhdengfei



1. 就是做一个滴答声的程序,让他输出foo bar foo bar这样的。但是 it crashes and says that prolog ran for too many inference steps.

下面是程序:
task(do_stuff, stuff).
stuff :- printf(foo), printf(bar), stuff.

怎么解决呢?

我这么写的:
task(do_stuff, stuff).
stuff :- printf(foo),pause(1),printf(bar),pause(1), continue_with(stuff).

2.还有一个问题
我现在有一个判断动作开始和正在进行的函数
start(monitor(P, Action), Succeed, Fail) :- P -> start(Action, Succeed, Fail) ; Fail.
still_running(monitor(P, Action), Completed, Fail) :- P -> still_running(Action, Completed, Fail) ; Fail.

我想再编一个ignore_failure(Action),假动作,进行动作,即使动作失败。

我这么写的:
start(monitor(P, Action), Succeed, Fail) :- P -> start(Action, Succeed, Fail) ; ignore_failure(Action, Succeed, Fail).
still_running(monitor(P, Action), Completed, Fail) :- P -> still_running(Action, Completed, Fail) ; ignore_failure(Action, Succeed, Fail).
ignore_failure(monitor(P, Action),Succeed, Fail) :- P ->run(Action,Succeed, Fail);Succeed.


不知道这么说可不可以理解......程序很大....就提取了一部分,能告诉我写的对错么?

2问题 Empty 回复: 问题 周三 十一月 21, 2012 6:44 am

yauhsien



能多说明一点吗?
1. printf/1, pause/1, continue_with/1分别怎麽写的?


2.
代码:
ignore_failure(monitor(P, Action),Succeed, Fail) :- P ->run(Action,Succeed, Fail);Succeed.
应写为
代码:
ignore_failure(monitor(P, Action),Succeed, Fail) :- P -> run(Action,Succeed, Fail), fail; Fail.
fail/0 就是无条件失败。但不知由 run/3 会另有什麽效果。


xhdengfei 写道:1. 就是做一个滴答声的程序,让他输出foo bar foo bar这样的。但是 it crashes and says that prolog ran for too many inference steps.

下面是程序:
task(do_stuff, stuff).
stuff :- printf(foo), printf(bar), stuff.

怎么解决呢?

我这么写的:
task(do_stuff, stuff).
stuff :- printf(foo),pause(1),printf(bar),pause(1), continue_with(stuff).

2.还有一个问题
我现在有一个判断动作开始和正在进行的函数
start(monitor(P, Action), Succeed, Fail) :- P -> start(Action, Succeed, Fail) ; Fail.
still_running(monitor(P, Action), Completed, Fail) :- P -> still_running(Action, Completed, Fail) ; Fail.

我想再编一个ignore_failure(Action),假动作,进行动作,即使动作失败。

我这么写的:
start(monitor(P, Action), Succeed, Fail) :- P -> start(Action, Succeed, Fail) ; ignore_failure(Action, Succeed, Fail).
still_running(monitor(P, Action), Completed, Fail) :- P -> still_running(Action, Completed, Fail) ; ignore_failure(Action, Succeed, Fail).
ignore_failure(monitor(P, Action),Succeed, Fail) :- P ->run(Action,Succeed, Fail);Succeed.


不知道这么说可不可以理解......程序很大....就提取了一部分,能告诉我写的对错么?

http://yauhsien.wordpress.com

3问题 Empty 回复: 问题 周三 十一月 21, 2012 6:42 pm

xhdengfei



代码:
pause(Time) ==>
    call_at_execution_time((time(Current), EndTime is Current+Time)),
    wait(after_time(EndTime)).
time(current)就是取得当前时间,然后pause就是暂停多长时间。
代码:
continue_with(NewTickRoutine) :-
   current_task(Name),
   change_task(Name, NewTickRoutine).
continue_with(:P) 就是告诉计时器下一个任务是P
printf(P) 就是输出P.

第二个程序:
run(+Sequence,+Succeed, +Fail)
Runs 顺序执行sequence中的action
Runs 同时
Runs Succeed all steps succeed
Runs Fail if a step fails

start(+Action, +Succeed, +Fail)
Initiates execution of Action
Runs Succeed or Fail accordingly
still_running(+Action,+Complete, +Fail)
Checks if Action terminated
If terminated, runs Complete or Fail accordingly
If not, just returns

你写的
代码:
ignore_failure(monitor(P, Action),Succeed, Fail) :- P -> run(Action,Succeed, Fail), fail; Fail.

判断非P的时候fail,会不会使当action失败的时候返回否?

我写了两个监视动作的程序,并且会call fail 当动作失败:
代码:
start(monitor(P, Action), Succeed, Fail) :- P -> start(Action, Succeed, Fail) ; Fail.
still_running(monitor(P, Action), Completed, Fail) :- P -> still_running(Action, Completed, Fail) ; Fail.

我现在想写一个类似的 fake action,但是比之前的更简单.Write the start and still_running rules for a fake action, ignore_failure(Action), that runs Action, but continues on even if Action fails.

这样说明可以么




yauhsien 写道:能多说明一点吗?
1. printf/1, pause/1, continue_with/1分别怎麽写的?


2.
代码:
ignore_failure(monitor(P, Action),Succeed, Fail) :- P ->run(Action,Succeed, Fail);Succeed.
应写为
代码:
ignore_failure(monitor(P, Action),Succeed, Fail) :- P -> run(Action,Succeed, Fail), fail; Fail.
fail/0 就是无条件失败。但不知由 run/3 会另有什麽效果。


xhdengfei 写道:1. 就是做一个滴答声的程序,让他输出foo bar foo bar这样的。但是 it crashes and says that prolog ran for too many inference steps.

下面是程序:
task(do_stuff, stuff).
stuff :- printf(foo), printf(bar), stuff.

怎么解决呢?

我这么写的:
task(do_stuff, stuff).
stuff :- printf(foo),pause(1),printf(bar),pause(1), continue_with(stuff).

2.还有一个问题
我现在有一个判断动作开始和正在进行的函数
start(monitor(P, Action), Succeed, Fail) :- P -> start(Action, Succeed, Fail) ; Fail.
still_running(monitor(P, Action), Completed, Fail) :- P -> still_running(Action, Completed, Fail) ; Fail.

我想再编一个ignore_failure(Action),假动作,进行动作,即使动作失败。

我这么写的:
start(monitor(P, Action), Succeed, Fail) :- P -> start(Action, Succeed, Fail) ; ignore_failure(Action, Succeed, Fail).
still_running(monitor(P, Action), Completed, Fail) :- P -> still_running(Action, Completed, Fail) ; ignore_failure(Action, Succeed, Fail).
ignore_failure(monitor(P, Action),Succeed, Fail) :- P ->run(Action,Succeed, Fail);Succeed.


不知道这么说可不可以理解......程序很大....就提取了一部分,能告诉我写的对错么?
代码:
代码:

4问题 Empty 回复: 问题 周四 十一月 22, 2012 12:02 am

yauhsien



差不多理解。

应该是
代码:
ignore_failure(monitor(P,Action), Succeed, _Fail) :-
    P -> ignore_failure(Action, Succeed, Succeed); Succeed.
这样是 _Fail 动作拿进来就丢掉,全用Succeed取代。

另有个问题, start/3 和 still_running/3 这样写,第一个参数是否都是
代码:
monitor(true,monitor(true,monitor(true, ... monitor(false,nothing) ... )))

xhdengfei 写道:我现在想写一个类似的 fake action,但是比之前的更简单.Write the start and still_running rules for a fake action, ignore_failure(Action), that runs Action, but continues on even if Action fails.

这样说明可以么

http://yauhsien.wordpress.com

5问题 Empty 回复: 问题 周六 十一月 24, 2012 3:49 am

xhdengfei



不好意思,最近没有上网,刚看见。

下面是monitor的代码:

代码:
%% monitor(:Condition,
%[Tasks, ...])
% Achieve tasks, but fail if
% Condition is ever false during % them.
monitor(Condition, TaskList,InState, OutState,InPlan,[ monitor(Condition, Plan) | InPlan ]) :-
  plan_list(TaskList, InState, OutState, [], ReversedPlan),
  reverse(ReversedPlan, Plan).

这个Instate就是起始状态,Outstate就是截止状态,InPlan就是action list.

真的抱歉,这样可以了么



yauhsien 写道:差不多理解。

应该是
代码:
ignore_failure(monitor(P,Action), Succeed, _Fail) :-
    P -> ignore_failure(Action, Succeed, Succeed); Succeed.
这样是 _Fail 动作拿进来就丢掉,全用Succeed取代。

另有个问题, start/3 和 still_running/3 这样写,第一个参数是否都是
代码:
monitor(true,monitor(true,monitor(true, ... monitor(false,nothing) ... )))

xhdengfei 写道:我现在想写一个类似的 fake action,但是比之前的更简单.Write the start and still_running rules for a fake action, ignore_failure(Action), that runs Action, but continues on even if Action fails.

这样说明可以么

6问题 Empty 回复: 问题 周日 十一月 25, 2012 1:48 am

yauhsien



粗略的看了,我觉得monitor/6中用到reverse/2这里就是瓶颈。

xhdengfei 写道:不好意思,最近没有上网,刚看见。

下面是monitor的代码:

代码:
%% monitor(:Condition,
%[Tasks, ...])
% Achieve tasks, but fail if
% Condition is ever false during % them.
monitor(Condition, TaskList,InState, OutState,InPlan,[ monitor(Condition, Plan) | InPlan ]) :-
  plan_list(TaskList, InState, OutState, [], ReversedPlan),
  reverse(ReversedPlan, Plan).

这个Instate就是起始状态,Outstate就是截止状态,InPlan就是action list.

真的抱歉,这样可以了么

http://yauhsien.wordpress.com

7问题 Empty 回复: 问题 周日 十一月 25, 2012 3:18 am

xhdengfei



你有QQ么,QQ说怎么样~


yauhsien 写道:粗略的看了,我觉得monitor/6中用到reverse/2这里就是瓶颈。

xhdengfei 写道:不好意思,最近没有上网,刚看见。

下面是monitor的代码:

代码:
%% monitor(:Condition,
%[Tasks, ...])
% Achieve tasks, but fail if
% Condition is ever false during % them.
monitor(Condition, TaskList,InState, OutState,InPlan,[ monitor(Condition, Plan) | InPlan ]) :-
  plan_list(TaskList, InState, OutState, [], ReversedPlan),
  reverse(ReversedPlan, Plan).

这个Instate就是起始状态,Outstate就是截止状态,InPlan就是action list.

真的抱歉,这样可以了么

8问题 Empty 回复: 问题 周日 十一月 25, 2012 2:20 pm

yauhsien



抱欠我在墙外,没有QQ。
moniter/6看似不符合moniter/2,可能不是因为这个原因

xhdengfei 写道:你有QQ么,QQ说怎么样~


yauhsien 写道:粗略的看了,我觉得monitor/6中用到reverse/2这里就是瓶颈。

xhdengfei 写道:不好意思,最近没有上网,刚看见。

下面是monitor的代码:

代码:
%% monitor(:Condition,
%[Tasks, ...])
% Achieve tasks, but fail if
% Condition is ever false during % them.
monitor(Condition, TaskList,InState, OutState,InPlan,[ monitor(Condition, Plan) | InPlan ]) :-
  plan_list(TaskList, InState, OutState, [], ReversedPlan),
  reverse(ReversedPlan, Plan).

这个Instate就是起始状态,Outstate就是截止状态,InPlan就是action list.

真的抱歉,这样可以了么

http://yauhsien.wordpress.com

9问题 Empty 回复: 问题 周一 十一月 26, 2012 2:02 am

xhdengfei



就这样交了,我觉得我写的差不多

yauhsien 写道:抱欠我在墙外,没有QQ。
moniter/6看似不符合moniter/2,可能不是因为这个原因

xhdengfei 写道:你有QQ么,QQ说怎么样~


yauhsien 写道:粗略的看了,我觉得monitor/6中用到reverse/2这里就是瓶颈。

xhdengfei 写道:不好意思,最近没有上网,刚看见。

下面是monitor的代码:

代码:
%% monitor(:Condition,
%[Tasks, ...])
% Achieve tasks, but fail if
% Condition is ever false during % them.
monitor(Condition, TaskList,InState, OutState,InPlan,[ monitor(Condition, Plan) | InPlan ]) :-
  plan_list(TaskList, InState, OutState, [], ReversedPlan),
  reverse(ReversedPlan, Plan).

这个Instate就是起始状态,Outstate就是截止状态,InPlan就是action list.

真的抱歉,这样可以了么

10问题 Empty 回复: 问题 周一 十一月 26, 2012 2:09 pm

yauhsien



xhdengfei 写道:就这样交了,我觉得我写的差不多

你这是作业呀?

http://yauhsien.wordpress.com

11问题 Empty 回复: 问题 周二 十一月 27, 2012 6:19 pm

xhdengfei



恩。。。。不会做。。。

yauhsien 写道:
xhdengfei 写道:就这样交了,我觉得我写的差不多

你这是作业呀?

12问题 Empty 回复: 问题 周三 十一月 28, 2012 5:22 am

yauhsien



看起来规模像是真实运作的系统。

xhdengfei 写道:恩。。。。不会做。。。

yauhsien 写道:
xhdengfei 写道:就这样交了,我觉得我写的差不多

你这是作业呀?

http://yauhsien.wordpress.com

13问题 Empty 回复: 问题 周三 十一月 28, 2012 6:40 am

Mercury Liao


Admin

表示作业很有深度,哈哈。

yauhsien 写道:看起来规模像是真实运作的系统。

xhdengfei 写道:恩。。。。不会做。。。

yauhsien 写道:
xhdengfei 写道:就这样交了,我觉得我写的差不多

你这是作业呀?

http://prolog.longluntan.net

返回页首  留言 [第1页/共1页]

您在这个论坛的权限:
不能在这个论坛回复主题