davegimo

david_planner

Mar 8th, 2020
173
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!doctype html>
  2.  
  3. <html lang="en">
  4. <head>
  5.   <meta charset="utf-8">
  6.  
  7.   <title>David</title>
  8.   <meta name="description" content="The HTML5 Herald">
  9.   <meta name="author" content="SitePoint">
  10.  
  11.   <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  12. </head>
  13.  
  14. <body>
  15.  
  16.  
  17. <p>ciao</p>
  18.  
  19.  
  20.  
  21. </body>
  22.  
  23.  
  24.  
  25.  
  26. <script>
  27.  
  28.    
  29.  
  30.  
  31.  
  32.  
  33.  
  34. var domText = "(define (domain myDomain)\
  35. (:requirements :strips :equality :typing)\
  36. (:types \
  37. Service - Thing\
  38. Capability\
  39. Object - Thing\
  40. Location\
  41. Boolean\
  42. )\
  43. (:predicates \
  44. (provides ?srv - Service ?c - Capability) \
  45. (heated ?o - Object ?b - Boolean)\
  46. (processed ?o - Object ?b - Boolean)\
  47. (cooled ?o - Object ?b - Boolean)\
  48. (movable ?o - Object ?b - Boolean)\
  49. (at ?t - Thing ?l - Location)\
  50. (carries ?s - Service ?o - Object)\
  51. )\
  52. (:action cool\
  53. :parameters (?srv - Service ?o - Object ?l - Location)\
  54. :precondition (and (provides ?srv cooling) (at ?srv ?l) (at ?o ?l) (processed ?o true) )\
  55. :effect (and (cooled ?o true) (not(cooled ?o false)) (increase (total-cost) 1))\
  56. )\
  57. (:action convert\
  58. :parameters (?srv - Service ?o - Object ?l - Location)\
  59. :precondition (and (provides ?srv converting) (at ?srv ?l) (at ?o ?l) )\
  60. :effect (and (heated ?o true) (processed ?o true) (cooled ?o true) (not(heated ?o false)) (not(processed ?o false)) (not(cooled ?o false)) (increase (total-cost) 5))\
  61. )\
  62. (:action heat\
  63. :parameters (?srv - Service ?o - Object ?l - Location)\
  64. :precondition (and (provides ?srv heating) (at ?srv ?l) (at ?o ?l) )\
  65. :effect (and (heated ?o true) (not(heated ?o false)) (increase (total-cost) 1))\
  66. )\
  67. (:action process\
  68. :parameters (?srv - Service ?o - Object ?l - Location)\
  69. :precondition (and (provides ?srv processing) (at ?srv ?l) (at ?o ?l) (heated ?o true) )\
  70. :effect (and (processed ?o true) (not(processed ?o false)) (increase (total-cost) 1))\
  71. )\
  72. (:action unload\
  73. :parameters (?srv - Service ?o - Object ?l - Location)\
  74. :precondition (and (provides ?srv unloading) (at ?srv ?l) (carries ?srv ?o) )\
  75. :effect (and (at ?o ?l) (not(carries ?srv ?o)) (increase (total-cost) 1))\
  76. )\
  77. (:action load\
  78. :parameters (?srv - Service ?o - Object ?l - Location)\
  79. :precondition (and (provides ?srv loading) (at ?srv ?l) (at ?o ?l) (movable ?o true) (not(carries ?srv ?o)) )\
  80. :effect (and (carries ?srv ?o) (not(at ?o ?l)) (increase (total-cost) 1))\
  81. )\
  82. (:action move\
  83. :parameters (?srv - Service ?from - Location ?to - Location)\
  84. :precondition (and (provides ?srv movement) (at ?srv ?from) )\
  85. :effect (and (at ?srv ?to) (not(at ?srv ?from)) (increase (total-cost) 1))\
  86. )\
  87. (:functions (total-cost))\
  88. )"
  89.  
  90.  
  91. var probText= "(define (problem myProblem)\n" +
  92. "(:domain myDomain)\n" +
  93. "(:objects \n" +
  94. "o1 - Object\n" +
  95. "o2 - Object\n" +
  96. "l00 - Location\n" +
  97. "l01 - Location\n" +
  98. "l02 - Location\n" +
  99. "l03 - Location\n" +
  100. "l04 - Location\n" +
  101. "l05 - Location\n" +
  102. "l06 - Location\n" +
  103. "l10 - Location\n" +
  104. "l11 - Location\n" +
  105. "l12 - Location\n" +
  106. "l13 - Location\n" +
  107. "l14 - Location\n" +
  108. "l15 - Location\n" +
  109. "l16 - Location\n" +
  110. "l20 - Location\n" +
  111. "l21 - Location\n" +
  112. "l22 - Location\n" +
  113. "l23 - Location\n" +
  114. "l24 - Location\n" +
  115. "l25 - Location\n" +
  116. "l26 - Location\n" +
  117. "l30 - Location\n" +
  118. "l31 - Location\n" +
  119. "l32 - Location\n" +
  120. "l33 - Location\n" +
  121. "l34 - Location\n" +
  122. "l35 - Location\n" +
  123. "l36 - Location\n" +
  124. "true - Boolean\n" +
  125. "false - Boolean\n" +
  126. "cooling - Capability\n" +
  127. "converting - Capability\n" +
  128. "heating - Capability\n" +
  129. "processing - Capability\n" +
  130. "unloading - Capability\n" +
  131. "loading - Capability\n" +
  132. "movement - Capability\n" +
  133. "clr1 - Service\n" +
  134. "cnv1 - Service\n" +
  135. "htr1 - Service\n" +
  136. "prc1 - Service\n" +
  137. "rb - Service\n" +
  138. "rb2 - Service\n" +
  139. ")\n" +
  140. "(:init\n" +
  141. "(provides clr1 cooling)\n" +
  142. "(provides cnv1 converting)\n" +
  143. "(provides htr1 heating)\n" +
  144. "(provides prc1 processing)\n" +
  145. "(provides rb unloading)\n" +
  146. "(provides rb loading)\n" +
  147. "(provides rb movement)\n" +
  148. "(provides rb2 unloading)\n" +
  149. "(provides rb2 loading)\n" +
  150. "(provides rb2 movement)\n" +
  151. "(at o1 l00)\n" +
  152. "(at o2 l00)\n" +
  153. "(movable o1 true)\n" +
  154. "(movable o2 true)\n" +
  155. "(at clr1 l01)\n" +
  156. "(at cnv1 l03)\n" +
  157. "(at htr1 l21)\n" +
  158. "(at prc1 l23)\n" +
  159. "(at rb l01)\n" +
  160. "(at rb2 l36)\n" +
  161. "(carries rb2 o2)\n" +
  162. "(= (total-cost) 0)\n" +
  163. ")\n" +
  164. "(:goal \n" +
  165. "(and \n" +
  166. "(at o1 l36)\n" +
  167. "(at o2 l36)\n" +
  168. "(cooled o1 true)\n" +
  169. "(cooled o2 true)\n" +
  170. ")\n" +
  171. ")\n" +
  172. "(:metric minimize (total-cost))\n" +
  173. ")"
  174.  
  175.  
  176.  
  177.  
  178.     $.ajax( {url: "http://solver.planning.domains/solve-and-validate",
  179.     type: "POST",
  180.     contentType: 'application/json',
  181.     data: JSON.stringify({"domain": domText,
  182.                             "problem": probText})})
  183.         .done(function (res) {
  184.         if (res['status'] === 'ok') {
  185.             window.alert('Plan found!');
  186.         } else {
  187.             window.alert('Planning failed.');
  188.         }
  189.         console.log(res);
  190.         }
  191.     );
  192.    
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.     function readTextFile(file)
  200. {
  201.     var rawFile = new XMLHttpRequest();
  202.     rawFile.open("GET", file, false);
  203.     rawFile.onreadystatechange = function ()
  204.     {
  205.         if(rawFile.readyState === 4)
  206.         {
  207.             if(rawFile.status === 200 || rawFile.status == 0)
  208.             {
  209.                 var allText = rawFile.responseText;
  210.                 alert(allText);
  211.             }
  212.         }
  213.     }
  214.     rawFile.send(null);
  215. }
  216.  
  217.  
  218. </script>
  219. </html>
RAW Paste Data