Как дополнить предикат fact, чтобы он выводил множество решений? isa(hotel,object).…
- User
Как дополнить предикат fact, чтобы он выводил множество решений? isa(hotel,object). isa(room,object). isa(customer,object). isa(accommodation,action). isa(booking,action). isa(reception,personnel). isa(service,object). isa(food,service). isa(residence,action). isa(staff,personnel). isa(pet_residence,residence). isa(equipment,service). isa(additional_service,service). isa(document,object).
has(hotel,room). has(hotel,reception). has(hotel,staff). has(room,customer). has(room,residence). has(room,equipment). has(room,additional_service). has(customer,accommodation). has(customer,booking). has(reception,accommodation). has(reception,service). has(reception,document). has(service,food). has(service,additional_service). has(staff,accommodation). has(pet_residence,customer). has(pet_residence,person). has(document,customer). has(document,staff).
help_number(hotel,111). help_number(room,111). help_number(customer,222). help_number(accommodation,111). help_number(booking,111). help_number(reception,222). help_number(service,222). help_number(food,333). help_number(residence,111). help_number(staff,222). help_number(pet_residence,444). help_number(equipment,555). help_number(additional_service,555). help_number(document,555).
fact(Fact) :- Fact,!. fact(Fact) :- Fact=(Rel, Arg1, Arg2), has(Arg1,SuperArg), SuperFact=(Rel, SuperArg, Arg2), fact(SuperFact).
- Assistant
fact(Fact) :- Fact=(Rel, Arg1, Arg2), has(Arg2,SuperArg), SuperFact=(Rel, Arg1, SuperArg), fact(SuperFact).
- User
Как дополнить предикат fact, чтобы он выводил множество решений при помощи n1 и fail? isa(hotel,object). isa(room,object). isa(customer,object). isa(accommodation,action). isa(booking,action). isa(reception,personnel). isa(service,object). isa(food,service). isa(residence,action). isa(staff,personnel). isa(pet_residence,residence). isa(equipment,service). isa(additional_service,service). isa(document,object).
has(hotel,room). has(hotel,reception). has(hotel,staff). has(room,customer). has(room,residence). has(room,equipment). has(room,additional_service). has(customer,accommodation). has(customer,booking). has(reception,accommodation). has(reception,service). has(reception,document). has(service,food). has(service,additional_service). has(staff,accommodation). has(pet_residence,customer). has(pet_residence,person). has(document,customer). has(document,staff).
help_number(hotel,111). help_number(room,111). help_number(customer,222). help_number(accommodation,111). help_number(booking,111). help_number(reception,222). help_number(service,222). help_number(food,333). help_number(residence,111). help_number(staff,222). help_number(pet_residence,444). help_number(equipment,555). help_number(additional_service,555). help_number(document,555).
fact(Fact) :- Fact,!. fact(Fact) :- Fact=(Rel, Arg1, Arg2), has(Arg1,SuperArg), SuperFact=(Rel, SuperArg, Arg2), fact(SuperFact).
- Assistant
fact(Fact) :- Fact=(Rel, Arg1, Arg2), has(Arg1,SuperArg), SuperFact=(Rel, SuperArg, Arg2), fact(SuperFact), write(SuperFact), nl, fail.
fact(Fact) :- Fact=(Rel, Arg1, Arg2), has(Arg2,SuperArg), SuperFact=(Rel, Arg1, SuperArg), fact(SuperFact), write(SuperFact), nl, fail.
fact(_). % предикат завершится успешно, после того как будет просмотрено всё множество решений и финальный fail вызовет завершение со статусом ошибки, это нужно для корректного вывода результата из программы
- User
приведи пример
- Assistant
После добавления предикатов n1 и fail программа будет выводить все множества решений с помощью комбинации н1 и fail.
Например, если я вызову предикат fact((X, Y, Z)), программа выведет все возможные комбинации отношений между объектами. Например:
(rel, hotel, room) (rel, hotel, reception) (rel, hotel, staff) (rel, room, customer) (rel, room, residence) (rel, room, equipment) (rel, room, additional_service) (rel, customer, accommodation) (rel, customer, booking) (rel, reception, accommodation) (rel, reception, service) (rel, reception, document) (rel, service, food) (rel, service, additional_service) (rel, staff, accommodation) (rel, pet_residence, customer) (rel, pet_residence, person) (rel, document, customer) (rel, document, staff)При этом, после завершения всех решений, программа вернет ошибку, так как последний предикат fail завершится неудачей.