Я пытаюсь написать генератор историй в Clingo.
Я пытаюсь сказать: «Новые персонажи могут родиться, если их породят существующие персонажи». Я определяю новые символы как entity(<int\>)
, и это лучший способ представления сущностей, который я мог придумать. Я не могу жестко закодировать это, так как в истории может быть создано различное количество сущностей.
My code
is :
% Create instances of time, only 3 for testing
time(0..2).
% Arrow of time flows forward
next_t(T, T+1) :- time(T), time(T+1).
% Entity 1 exists at time 0.
entity(1, 0).
% If an entity ever existed, that ID is taken and cannot be assigned to
% other entities
entity_id(ID) :- entity(ID, _).
% If an entity exists, he can give birth to a new entity
% The ID of the new entity will be 1 more than ID of all current entities.
birth(X, Y, T) :- entity(Y, T), X = #max{X1+1:entity_id(X1)}, time(T).
% At each time instant, only 1 entity can be born, as only 1 event can happen per time instant.
% This also should prevent infinite entities to be created.
:- birth(X1, _, T), birth(Y1, _, T), X1!=Y1.
% In case of a birth, create a new entiti the next time instant.
entity(X, T1) :- birth(X, _, T), next(T, T1).
#show entity_id/1.
#show entity/2.
#show birth/3 .
Однако вывод:
entity_id(1) entity(1,0) birth(2,1,0)
entity(2, 1)
никогда не создается, равно как и entity(3, 2)
или entity(4, 3)
.
Что я делаю не так? Есть лучший способ сделать это?
next
отличается отnext_t
. Исправив это, вы получите ошибку, для которой вам нужно отметить, что вы пытаетесь взять #max набора, сгенерировать что-то, что увеличивает максимальный идентификатор этого набора, что затем делает предыдущий оператор недействительным как максимум, который мы найденное уже не является максимальным. Чтобы получить желаемый результат, вы можете сделать, например.birth(Y+1, Y, T) :- entity(Y, T), time(T).
, но этого может быть недостаточно для вашей более крупной цели. - person vukk   schedule 11.07.2018operation undefined: (1*X1+1)
, а затем зависание, что очень тупо. Я использую clingo 5.2, более поздние версии clingo лучше отображают сообщения об ошибках? Кажется, что генерация сложна в моделях clingo/stable. Мне придется изменить модель извне и создать стабильную модель на основе этого для каждого временного шага. - person Sid Datta   schedule 11.07.2018