|
40 / 32 / 7
Регистрация: 24.03.2016
Сообщений: 270
|
|
Переправить семью через реку12.05.2016, 11:47. Показов 2762. Ответов 3
Метки нет (Все метки)
Здравствуйте дорогие друзья. У меня возникла проблема, нужно создать алгоритм на Clips к одной задаче, но вот как и что делать - не знаю. Алгоритм сложный, по-этому за день я не смог разобраться, а сдать лабораторную нужно уже завтра. Помогите пожалуйста, за "спасибо" и "Best answer"
![]() Вот собсно сама задача. Есть документ с примером для другой задачи, похожей (про переправу фермера, лисицы, козы и капусты). Там алгоритм уже реализован. Если нужен будет пример, напишите в ЛС, я скину вам документ. Я понимаю что прошу сделать всё за меня, но я просто не умею писать на клипс, а сроки уже истекли. Спасибо за помощь всем не равнодушным. Буду признателен добрым людям. ![]() Добавлено через 2 минуты То, что успел написать, может оно поможет быстрее сообразить что к чему : Кликните здесь для просмотра всего текста
(defmodule MAIN (export deftemplate status)) (deftemplate MAIN::status (slot search-depth (type INTEGER)(range 1 ?VARIABLE)) (slot parent (type FACT-ADRESS-SYMBOL)(allowed-symbols no-parent)) (slot police-location (type SYMBOL)(allowed-symbols shore-1 shore-2)) (slot father-location (type SYMBOL)(allowed-symbols shore-1 shore-2)) (slot mother-location (type SYMBOL)(allowed-symbols shore-1 shore-2)) (slot zek-location (type SYMBOL)(allowed-symbols shore-1 shore-2)) (slot brother1-location (type SYMBOL)(allowed-symbols shore-1 shore-2)) (slot brother2-location (type SYMBOL)(allowed-symbols shore-1 shore-2)) (slot sister1-location (type SYMBOL)(allowed-symbols shore-1 shore-2)) (slot sister2-location (type SYMBOL)(allowed-symbols shore-1 shore-2)) (slot last-move (type SYMBOL)(allowed-symbols no-move police-with-mother police-with-father police-with-sister police-with-brother father-with-mother father-with-brother police-with-zek mother-with-sister))) (deffacts MAIN::initial-positions (status (search-depth 1) (parent no-parent) (police-location shore-1) (father-location shore-1) (mother-location shore-) (zek-location shore-1) (brother1-location shore-1) (brother2-location shore-1) (sister1-location shore-1) (sister2-location shore-1 ) (last-move no-move))
0
|
|
| 12.05.2016, 11:47 | |
|
Ответы с готовыми решениями:
3
Задача: переправить через реку семью и полицейского с заключенным Нужно переправить через реку Как переправить семью на другой берег реки? |
|
40 / 32 / 7
Регистрация: 24.03.2016
Сообщений: 270
|
|
| 12.05.2016, 12:06 [ТС] | |
|
Нашлась задача про фермера (та которая похожая). Опять же, прошу помощи
0
|
|
|
40 / 32 / 7
Регистрация: 24.03.2016
Сообщений: 270
|
|
| 12.05.2016, 13:10 [ТС] | |
|
Написал перемещения всех персон, с кем-то или в одиночку. Осталось написать самое тяжелое - правила
Всё ещё прошу помощи.Кликните здесь для просмотра всего текста
(defmodule MAIN
(export deftemplate status)) (deftemplate MAIN::status (slot search-depth (type INTEGER) (range 1 ?VARIABLE)) (slot parent (type FACT-ADDRESS SYMBOL) (allowed-symbols no-parent)) (slot police-location (type SYMBOL)(allowed-symbols shore-1 shore-2)) (slot father-location (type SYMBOL)(allowed-symbols shore-1 shore-2)) (slot mother-location (type SYMBOL)(allowed-symbols shore-1 shore-2)) (slot zek-location (type SYMBOL)(allowed-symbols shore-1 shore-2)) (slot brother1-location (type SYMBOL)(allowed-symbols shore-1 shore-2)) (slot brother2-location (type SYMBOL)(allowed-symbols shore-1 shore-2)) (slot sister1-location (type SYMBOL)(allowed-symbols shore-1 shore-2)) (slot sister2-location (type SYMBOL)(allowed-symbols shore-1 shore-2)) (slot last-move (type SYMBOL)(allowed-symbols no-move po-with-mo po-with-fa po-with-sis1 po-with-sis2 po-with-bro1 po-with-bro2 fa-with-mo fa-with-bro1 fa-with-bro2 po-with-zek mo-with-sis1 mo-with-sis2 po-alone mo-alone fa-alone))) (deffacts MAIN::initial-positions (status (search-depth 1) (parent no-parent) (police-location shore-1) (father-location shore-1) (mother-location shore-1) (zek-location shore-1) (brother1-location shore-1) (brother2-location shore-1) (sister1-location shore-1) (sister2-location shore-1 ) (last-move no-move))) (deffacts MAIN::opposites (opposite-of shore-1 shore-2) (opposite-of shore-2 shore-1)) ;;;*********************** ;;;* GENERATE PATH RULES * ;;;*********************** ;;;===================================== ========= (defrule MAIN: olice-move-with-mother?node <- (status (search-depth ?num) (police-location ?fs) (mother-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (police-location ?ns) (mother-location ?ns) (last-move po-with-mo))) ;;;===================================== ========= (defrule MAIN: olice-move-with-father?node <- (status (search-depth ?num) (police-location ?fs) (father-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (police-location ?ns) (father-location ?ns) (last-move po-with-fa))) ;;;===================================== ========= (defrule MAIN: olice-move-with-sister1 ?node <- (status (search-depth ?num) (police-location ?fs) (sister1-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (police-location ?ns) (sister1-location ?ns) (last-move po-with-sis1))) ;;;===================================== ======== (defrule MAIN: olice-move-with-sister2 ?node <- (status (search-depth ?num) (police-location ?fs) (sister2-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (police-location ?ns) (sister2-location ?ns) (last-move po-with-sis2))) ;;;===================================== ========= (defrule MAIN: olice-move-with-brother1 ?node <- (status (search-depth ?num) (police-location ?fs) (brother1-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (police-location ?ns) (brother1-location ?ns) (last-move po-with-bro1))) ;;;===================================== ========= (defrule MAIN: olice-move-with-brother2 ?node <- (status (search-depth ?num) (police-location ?fs) (brother2-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (police-location ?ns) (brother2-location ?ns) (last-move po-with-bro2))) ;;;===================================== ========= (defrule MAIN::father-move-with-mother ?node <- (status (search-depth ?num) (father-location ?fs) (mother-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (father-location ?ns) (mother-location ?ns) (last-move fa-with-mo))) ;;;===================================== ========= (defrule MAIN::father-move-with-brother1 ?node <- (status (search-depth ?num) (father-location ?fs) (brother1-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (father-location ?ns) (brother1-location ?ns) (last-move fa-with-bro1))) ;;;===================================== ========= (defrule MAIN::father-move-with-brother2 ?node <- (status (search-depth ?num) (father-location ?fs) (brother2-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (father-location ?ns) (brother2-location ?ns) (last-move fa-with-bro2))) ;;;===================================== ========= (defrule MAIN: olice-move-with-zek?node <- (status (search-depth ?num) (police-location ?fs) (zek-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (police-location ?ns) (zek-location ?ns) (last-move po-with-zek))) ;;;===================================== ======== (defrule MAIN::mother-move-with-sister1 ?node <- (status (search-depth ?num) (mother-location ?fs) (sister1-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (mother-location ?ns) (sister1-location ?ns) (last-move mo-with-sis1))) ;;;===================================== ======== (defrule MAIN::mother-move-with-sister2 ?node <- (status (search-depth ?num) (mother-location ?fs) (sister2-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (mother-location ?ns) (sister2-location ?ns) (last-move mo-with-sis2))) ;;;===================================== ======== (defrule MAIN: olice-move-alone ?node <- (status (search-depth ?num) (police-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (police-location ?ns) (last-move po-alone))) ;;;===================================== ======== (defrule MAIN::mother-move-alone ?node <- (status (search-depth ?num) (mother-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (mother-location ?ns) (last-move mo-alone))) ;;;===================================== ======== (defrule MAIN::father-move-alone ?node <- (status (search-depth ?num) (father-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (father-location ?ns) (last-move fa-alone)))
0
|
|
|
40 / 32 / 7
Регистрация: 24.03.2016
Сообщений: 270
|
|
| 12.05.2016, 16:33 [ТС] | |
|
В общем, вот что получилось:
Кликните здесь для просмотра всего текста
(defmodule MAIN
(export deftemplate status)) (deftemplate MAIN::status (slot search-depth (type INTEGER) (range 1 ?VARIABLE)) (slot parent (type FACT-ADDRESS SYMBOL) (allowed-symbols no-parent)) (slot police-location (type SYMBOL)(allowed-symbols shore-1 shore-2)) (slot father-location (type SYMBOL)(allowed-symbols shore-1 shore-2)) (slot mother-location (type SYMBOL)(allowed-symbols shore-1 shore-2)) (slot zek-location (type SYMBOL)(allowed-symbols shore-1 shore-2)) (slot brother1-location (type SYMBOL)(allowed-symbols shore-1 shore-2)) (slot brother2-location (type SYMBOL)(allowed-symbols shore-1 shore-2)) (slot sister1-location (type SYMBOL)(allowed-symbols shore-1 shore-2)) (slot sister2-location (type SYMBOL)(allowed-symbols shore-1 shore-2)) (slot last-move (type SYMBOL)(allowed-symbols no-move po-with-mo po-with-fa po-with-sis1 po-with-sis2 po-with-bro1 po-with-bro2 fa-with-mo fa-with-bro1 fa-with-bro2 po-with-zek mo-with-sis1 mo-with-sis2 po-alone mo-alone fa-alone))) (deffacts MAIN::initial-positions (status (search-depth 1) (parent no-parent) (police-location shore-1) (father-location shore-1) (mother-location shore-1) (zek-location shore-1) (brother1-location shore-1) (brother2-location shore-1) (sister1-location shore-1) (sister2-location shore-1) (last-move no-move))) (deffacts MAIN::opposites (opposite-of shore-1 shore-2) (opposite-of shore-2 shore-1)) ;;;*********************** ;;;* GENERATE PATH RULES * ;;;*********************** ;;;===================================== ========= (defrule MAIN: olice-move-with-mother?node <- (status (search-depth ?num) (police-location ?fs) (mother-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (police-location ?ns) (mother-location ?ns) (last-move po-with-mo))) ;;;===================================== ========= (defrule MAIN: olice-move-with-father?node <- (status (search-depth ?num) (police-location ?fs) (father-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (police-location ?ns) (father-location ?ns) (last-move po-with-fa))) ;;;===================================== ========= (defrule MAIN: olice-move-with-sister1 ?node <- (status (search-depth ?num) (police-location ?fs) (sister1-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (police-location ?ns) (sister1-location ?ns) (last-move po-with-sis1))) ;;;===================================== ======== (defrule MAIN: olice-move-with-sister2 ?node <- (status (search-depth ?num) (police-location ?fs) (sister2-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (police-location ?ns) (sister2-location ?ns) (last-move po-with-sis2))) ;;;===================================== ========= (defrule MAIN: olice-move-with-brother1 ?node <- (status (search-depth ?num) (police-location ?fs) (brother1-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (police-location ?ns) (brother1-location ?ns) (last-move po-with-bro1))) ;;;===================================== ========= (defrule MAIN: olice-move-with-brother2 ?node <- (status (search-depth ?num) (police-location ?fs) (brother2-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (police-location ?ns) (brother2-location ?ns) (last-move po-with-bro2))) ;;;===================================== ========= (defrule MAIN::father-move-with-mother ?node <- (status (search-depth ?num) (father-location ?fs) (mother-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (father-location ?ns) (mother-location ?ns) (last-move fa-with-mo))) ;;;===================================== ========= (defrule MAIN::father-move-with-brother1 ?node <- (status (search-depth ?num) (father-location ?fs) (brother1-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (father-location ?ns) (brother1-location ?ns) (last-move fa-with-bro1))) ;;;===================================== ========= (defrule MAIN::father-move-with-brother2 ?node <- (status (search-depth ?num) (father-location ?fs) (brother2-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (father-location ?ns) (brother2-location ?ns) (last-move fa-with-bro2))) ;;;===================================== ========= (defrule MAIN: olice-move-with-zek?node <- (status (search-depth ?num) (police-location ?fs) (zek-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (police-location ?ns) (zek-location ?ns) (last-move po-with-zek))) ;;;===================================== ======== (defrule MAIN::mother-move-with-sister1 ?node <- (status (search-depth ?num) (mother-location ?fs) (sister1-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (mother-location ?ns) (sister1-location ?ns) (last-move mo-with-sis1))) ;;;===================================== ======== (defrule MAIN::mother-move-with-sister2 ?node <- (status (search-depth ?num) (mother-location ?fs) (sister2-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (mother-location ?ns) (sister2-location ?ns) (last-move mo-with-sis2))) ;;;===================================== ======== (defrule MAIN: olice-move-alone ?node <- (status (search-depth ?num) (police-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (police-location ?ns) (last-move po-alone))) ;;;===================================== ======== (defrule MAIN::mother-move-alone ?node <- (status (search-depth ?num) (mother-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (mother-location ?ns) (last-move mo-alone))) ;;;===================================== ======== (defrule MAIN::father-move-alone ?node <- (status (search-depth ?num) (father-location ?fs)) (opposite-of ?fs ?ns) => (duplicate ?node (search-depth =(+ 1 ?num)) (parent ?node) (father-location ?ns) (last-move fa-alone))) ;;;****************************** ;;;* CONSTRAINT VIOLATION RULES * ;;;****************************** (defmodule CONSTRAINTS (import MAIN deftemplate status)) ;;;===================================== ======== (defrule CONSTRAINTS::zek-kill-family (declare (auto-focus TRUE)) ?node <- (status (police-location ?s1) (zek-location ?s2&~?s1) (mother-location ?s2) (father-location ?s2) (brother1-location ?s2) (brother2-location ?s2) (sister1-location ?s2) (sister2-location ?s2)) => (retract ?node)) ;;;===================================== ======== (defrule CONSTRAINTS::mother-kill-brother (declare (auto-focus TRUE)) ?node <- (status (father-location ?s1) (mother-location ?s2&~?s1) (brother1-location ?s2) (brother2-location ?s2)) => (retract ?node)) ;;;===================================== ======== (defrule CONSTRAINTS::father-kill-sister (declare (auto-focus TRUE)) ?node <- (status (mother-location ?s1) (father-location ?s2&~?s1) (sister1-location ?s2) (sister2-location ?s2)) => (retract ?node)) ;;;===================================== ======== (defrule CONSTRAINTS::circular-path (declare (auto-focus TRUE)) (status (search-depth ?sd1) (police-location ?ps) (father-location ?fs) (mother-location ?ms) (zek-location ?zs) (brother1-location ?b1s) (brother2-location ?b2s) (sister1-location ?s1s) (sister2-location ?s2s)) ?node <- (status (search-depth ?sd2& < ?sd1 ?sd2))(police-location ?ps) (father-location ?fs) (mother-location ?ms) (zek-location ?zs) (brother1-location ?b1s) (brother2-location ?b2s) (sister1-location ?s1s) (sister2-location ?s2s)) => (retract ?node)) ;;;********************************* ;;;* FIND AND PRINT SOLUTION RULES * ;;;********************************* (defmodule SOLUTION (import MAIN deftemplate status)) ;;;===================================== ======== (deftemplate SOLUTION::moves (slot id (type FACT-ADDRESS SYMBOL) (allowed-symbols no-parent)) (multislot moves-list (type SYMBOL) (allowed-symbols no-move po-with-mo po-with-fa po-with-sis1 po-with-sis2 po-with-bro1 po-with-bro2 fa-with-mo fa-with-bro1 fa-with-bro2 po-with-zek mo-with-sis1 mo-with-sis2 po-alone mo-alone fa-alone))) ;;;===================================== ======== (defrule SOLUTION::recognize-solution (declare (auto-focus TRUE)) ?node <- (status (parent ?parent) (police-location shore-2) (father-location shore-2) (mother-location shore-2) (zek-location shore-2) (brother1-location shore-2) (brother2-location shore-2) (sister1-location shore-2) (sister2-location shore-2) (last-move ?move)) => (retract ?node) (assert (moves (id ?parent) (moves-list ?move)))) ;;;===================================== ======== (defrule SOLUTION::further-solution ?node <- (status (parent ?parent) (last-move ?move)) ?mv <- (moves (id ?node) (moves-list $?rest)) => (modify ?mv (id ?parent) (moves-list ?move ?rest))) ;;;===================================== ======== (defrule SOLUTION: rint-solution ?mv <- (moves (id no-parent) (moves-list no-move $?m)) => (retract ?mv) (printout t crlf "Solution found: " crlf crlf)) Но видимо где-то я промахнулся в условиях. У меня постоянно полицейский перемещается. Всё ещё жду помощи. ![]() Добавлено через 21 минуту Код выше работает, я нашёл в чём проблема. Мне нужно указать условие, что после передвижения, кто-то должен вернуться на 1 берег, ибо лодка сама назад не прывёт. Помогиите, такая мелочь осталась Уже мозги пухнутДобавлено через 15 минут Как написать условие, что если предыдущее движение было на 2-рой берег, то следующее должно быть обязательно на 1 и наоборот.?
0
|
|
| 12.05.2016, 16:33 | |
|
Помогаю со студенческими работами здесь
4
Переплыть через реку Через какое время катер пересечет реку Перевезти через реку волка, козу и капусту Найти скорость и течения реки и время t, затраченное на переправу через реку Задача про семью Искать еще темы с ответами Или воспользуйтесь поиском по форуму: |
|
Новые блоги и статьи
|
|||
|
Ритм жизни
kumehtar 27.02.2026
Иногда приходится жить в ритме, где дел становится всё больше, а вовлечения в происходящее — всё меньше. Плотный график не даёт вниманию закрепиться ни на одном событии. Утро начинается с быстрых,. . .
|
SDL3 для Web (WebAssembly): Сборка библиотек SDL3 и Box2D из исходников с помощью CMake и Emscripten
8Observer8 27.02.2026
Недавно вышла версия SDL 3. 4. 2 библиотеки SDL3. На странице официальной релиза доступны исходники, готовые DLL (для x86, x64, arm64), а также библиотеки для разработки под Android, MinGW и Visual. . .
|
SDL3 для Web (WebAssembly): Реализация движения на Box2D v3 - трение и коллизии с повёрнутыми стенами
8Observer8 20.02.2026
Содержание блога
Box2D позволяет легко создать главного героя, который не проходит сквозь стены и перемещается с заданным трением о препятствия, которые можно располагать под углом, как верхнее. . .
|
Конвертировать закладки radiotray-ng в m3u-плейлист
damix 19.02.2026
Это можно сделать скриптом для PowerShell. Использование
. \СonvertRadiotrayToM3U. ps1 <path_to_bookmarks. json>
Рядом с файлом bookmarks. json появится файл bookmarks. m3u с результатом.
# Check if. . .
|
|
Семь CDC на одном интерфейсе: 5 U[S]ARTов, 1 CAN и 1 SSI
Eddy_Em 18.02.2026
Постепенно допиливаю свою "многоинтерфейсную плату". Выглядит вот так:
https:/ / www. cyberforum. ru/ blog_attachment. php?attachmentid=11617&stc=1&d=1771445347
Основана на STM32F303RBT6.
На борту пять. . .
|
Камера Toupcam IUA500KMA
Eddy_Em 12.02.2026
Т. к. у всяких "хикроботов" слишком уж мелкий пиксель, для подсмотра в ESPriF они вообще плохо годятся: уже 14 величину можно рассмотреть еле-еле лишь на экспозициях под 3 секунды (а то и больше),. . .
|
И ясному Солнцу
zbw 12.02.2026
И ясному Солнцу,
и светлой Луне.
В мире
покоя нет
и люди
не могут жить в тишине.
А жить им немного лет.
|
«Знание-Сила»
zbw 12.02.2026
«Знание-Сила»
«Время-Деньги»
«Деньги -Пуля»
|