home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / KAPA2.ZIP / EXAMPLES.ZIP / AUTOSIM.KAL next >
Encoding:
Text File  |  1990-05-18  |  18.5 KB  |  569 lines

  1. @KAPPA_APPLICATION_COMMENT
  2. /*
  3. This is the Autosim demonstration application for KAPPA.
  4. 5/17/90
  5.  
  6.  
  7.  
  8.  
  9. */
  10.  
  11.  
  12.  
  13. /*********************************************************/
  14. /*            ALL FUNCTIONS ARE SAVED BELOW             **/
  15. /*********************************************************/
  16.  
  17.        /*************************************
  18.         ****  FUNCTION: MakeNoise
  19.         *************************************/
  20. MakeFunction( MakeNoise, [],
  21.     Beep(  ) );
  22.  
  23.        /*************************************
  24.         ****  FUNCTION: RunExam1
  25.         *************************************/
  26. MakeFunction( RunExam1, [],
  27.     {
  28.     MarysCar:Battery = Low;
  29.     Assert( MarysCar, Battery );
  30.     ForwardChain( LowBatt, CarRules );
  31.     } );
  32.  
  33.        /*************************************
  34.         ****  FUNCTION: Clear
  35.         *************************************/
  36. MakeFunction( Clear, [],
  37.     SendMessage( MarysCar, INIT ) );
  38.  
  39.  
  40.  
  41. /*********************************************************/
  42. /**       ALL CLASSES ARE SAVED BELOW             **/
  43. /*********************************************************/
  44.  
  45.        /*************************************
  46.         ****  CLASS: Image
  47.         *************************************/
  48. Image:Width = 150;
  49. Image:Height = 120;
  50. Image:WinType = Make_ImageWindow;
  51. Image:Visible = FALSE;
  52. Image:ShowBorder = TRUE;
  53. Image:Transparent = FALSE;
  54.  
  55.        /*************************************
  56.         ****  CLASS: SlotView
  57.         *************************************/
  58.  
  59.        /*************************************
  60.         ****  CLASS: OutputView
  61.         *************************************/
  62.  
  63.        /*************************************
  64.         ****  CLASS: Meter
  65.         *************************************/
  66. Meter:Draw = Draw_HMeter;
  67. Meter:Update = Update_HMeter;
  68.  
  69.        /*************************************
  70.         ****  CLASS: StateBox
  71.         *************************************/
  72. SetSlotOption( StateBox:AllowableValues, MULTIPLE );
  73. StateBox:Draw = Draw_RectLight;
  74. StateBox:Update = Update_RectLight;
  75.  
  76.        /*************************************
  77.         ****  CLASS: InputOutputView
  78.         *************************************/
  79.  
  80.        /*************************************
  81.         ****  CLASS: Slider
  82.         *************************************/
  83. Slider:Width = 200;
  84. Slider:Height = 75;
  85. Slider:WinType = Make_SliderWindow;
  86. Slider:Draw = Draw_Slider;
  87. Slider:Update = Update_Slider;
  88.  
  89.        /*************************************
  90.         ****  CLASS: Edit
  91.         *************************************/
  92. Edit:ShowBorder = FALSE;
  93. Edit:Width = 100;
  94. Edit:Height = 25;
  95. Edit:WinType = Make_EditWindow;
  96. Edit:Update = Update_Edit;
  97.  
  98.        /*************************************
  99.         ****  CLASS: Transcript
  100.         *************************************/
  101. Transcript:ProportionalFont = TRUE;
  102. Transcript:WinType = Make_TransWindow;
  103.  
  104.        /*************************************
  105.         ****  CLASS: Button
  106.         *************************************/
  107. Button:ShowBorder = FALSE;
  108. Button:Width = 100;
  109. Button:Height = 25;
  110. Button:WinType = Make_ButtonWindow;
  111. Button:Draw = Draw_Bitmap;
  112.  
  113.        /*************************************
  114.         ****  CLASS: Bitmap
  115.         *************************************/
  116. Bitmap:FitToScreen = FALSE;
  117. Bitmap:Draw = Draw_Bitmap;
  118.  
  119.        /*************************************
  120.         ****  CLASS: Drawing
  121.         *************************************/
  122. Drawing:XLeft = 0;
  123. Drawing:YTop = 100;
  124. Drawing:XRight = 100;
  125. Drawing:YBottom = 0;
  126. Drawing:Draw = Draw_Drawing;
  127. Drawing:Print = Print_Drawing;
  128.  
  129.        /*************************************
  130.         ****  CLASS: Text
  131.         *************************************/
  132. Text:Justification = CENTER;
  133. Text:ShowBorder = FALSE;
  134. Text:Width = 100;
  135. Text:Height = 25;
  136. Text:WinType = Make_StaticWindow;
  137.  
  138.        /*************************************
  139.         ****  CLASS: LinePlot
  140.         *************************************/
  141. LinePlot:AutoScale = FALSE;
  142. LinePlot:Grid = FALSE;
  143. LinePlot:Draw = Draw_LinePlot;
  144. LinePlot:Update = Update_LinePlot;
  145. LinePlot:Print = Print_LinePlot;
  146.  
  147.        /*************************************
  148.         ****  CLASS: Autos
  149.         *************************************/
  150. MakeClass( Autos, Root );
  151.  
  152. /************** METHOD: ResetVal   ***************/
  153. MakeMethod( Autos, ResetVal, [],
  154.     ResetValue( Self, ElectricalSystem ) And ResetValue( Self,
  155.                                                          Status )
  156.       And ResetValue( Self, Battery ) );
  157.  
  158. /************** METHOD: ManualInit   ***************/
  159. MakeMethod( Autos, ManualInit, [],
  160.     {
  161.     ResetValue( Self:Battery );
  162.     ResetValue( Self:Colors );
  163.     ResetValue( Self:Distance );
  164.     ResetValue( Self:Drivers );
  165.     ResetValue( Self:ElectricalSystem );
  166.     ResetValue( Self:Engine );
  167.     ResetValue( Self:EngineTurnover );
  168.     ResetValue( Self:Gallons );
  169.     ResetValue( Self:GasSystem );
  170.     ResetValue( Self:Ignition );
  171.     ResetValue( Self:IgnitionKey );
  172.     ResetValue( Self:LightAppearance );
  173.     ResetValue( Self:LightSwitch );
  174.     ResetValue( Self:ModelYear );
  175.     ResetValue( Self:Owner );
  176.     ResetValue( Self:Registered );
  177.     ResetValue( Self:SparkPlug );
  178.     ResetValue( Self:SparkPlugCondition );
  179.     ResetValue( Self:Speed );
  180.     ResetValue( Self:Status );
  181.     ResetValue( Self:Tank );
  182.     ResetValue( Self:Timing );
  183.     ResetValue( Self:Passengers );
  184.     PostMessage( "Initialization is complete." );
  185.     } );
  186.  
  187. /************** METHOD: INIT   ***************/
  188. MakeMethod( Autos, INIT, [],
  189.     {
  190.     GetSlotList( Self, Global:TempList );
  191.     EnumList( Global:TempList, SlotName, ResetValue( Self:SlotName ) );
  192.     PostMessage( "Initialization is complete" );
  193.     } );
  194. MakeSlot( Autos:Gallons );
  195. MakeSlot( Autos:Distance );
  196. MakeSlot( Autos:Tank );
  197. MakeSlot( Autos:Status );
  198. SetSlotOption( Autos:Status,  ALLOWABLE_VALUES, Running, Stopped );
  199. MakeSlot( Autos:EngineTurnover );
  200. MakeSlot( Autos:Engine );
  201. MakeSlot( Autos:SparkPlug );
  202. MakeSlot( Autos:Ignition );
  203. MakeSlot( Autos:Passengers );
  204. MakeSlot( Autos:Speed );
  205. SetSlotOption( Autos:Speed, VALUE_TYPE, NUMBER );
  206. SetSlotOption( Autos:Speed,  MINIMUM_VALUE, 0 );
  207. SetSlotOption( Autos:Speed,  MAXIMUM_VALUE, 75 );
  208. Autos:Speed = 55;
  209. MakeSlot( Autos:Drivers );
  210. SetSlotOption( Autos:Drivers, MULTIPLE );
  211. MakeSlot( Autos:ModelYear );
  212. MakeSlot( Autos:Registered );
  213. MakeSlot( Autos:NumberofDoors );
  214. MakeSlot( Autos:Colors );
  215. SetSlotOption( Autos:Colors, MULTIPLE );
  216. MakeSlot( Autos:Owner );
  217. MakeSlot( Autos:Battery );
  218. SetSlotOption( Autos:Battery,  ALLOWABLE_VALUES, Low, Charged );
  219. MakeSlot( Autos:SparkPlugCondition );
  220. SetSlotOption( Autos:SparkPlugCondition,  ALLOWABLE_VALUES, Good, Bad );
  221. MakeSlot( Autos:Timing );
  222. SetSlotOption( Autos:Timing,  ALLOWABLE_VALUES, InSynch, OutOfSynch );
  223. MakeSlot( Autos:ElectricalSystem );
  224. SetSlotOption( Autos:ElectricalSystem,  ALLOWABLE_VALUES, Good, Bad );
  225. MakeSlot( Autos:LightSwitch );
  226. SetSlotOption( Autos:LightSwitch,  ALLOWABLE_VALUES, On, Off );
  227. Autos:LightSwitch = ON;
  228. MakeSlot( Autos:LightAppearance );
  229. SetSlotOption( Autos:LightAppearance,  ALLOWABLE_VALUES, Dim, Bright );
  230. MakeSlot( Autos:IgnitionKey );
  231. SetSlotOption( Autos:IgnitionKey,  ALLOWABLE_VALUES, On, Off );
  232. MakeSlot( Autos:GasSystem );
  233. SetSlotOption( Autos:GasSystem,  ALLOWABLE_VALUES, Good, Bad );
  234.  
  235.        /*************************************
  236.         ****  CLASS: Sedans
  237.         *************************************/
  238. MakeClass( Sedans, Autos );
  239.  
  240.        /*************************************
  241.         ****  CLASS: StationWagons
  242.         *************************************/
  243. MakeClass( StationWagons, Autos );
  244. MakeSlot( StationWagons:LengthOfCargo );
  245.  
  246.        /*************************************
  247.         ****  CLASS: People
  248.         *************************************/
  249. MakeClass( People, Root );
  250. MakeSlot( People:Age );
  251. MakeSlot( People:Height );
  252. SetSlotOption( People:Height, VALUE_TYPE, NUMBER );
  253. MakeSlot( People:Weight );
  254. SetSlotOption( People:Weight, VALUE_TYPE, NUMBER );
  255. MakeSlot( People:Licensed );
  256. SetSlotOption( People:Licensed, VALUE_TYPE, BOOLEAN );
  257. MakeSlot( People:House );
  258. SetSlotOption( People:House, VALUE_TYPE, BOOLEAN );
  259. MakeSlot( People:Income );
  260. MakeSlot( People:Friends );
  261. SetSlotOption( People:Friends, MULTIPLE );
  262.  
  263.  
  264.  
  265. /*********************************************************/
  266. /**       ALL INSTANCES ARE SAVED BELOW            **/
  267. /*********************************************************/
  268. MakeSlot( Global:CarRules );
  269. SetSlotOption( Global:CarRules, MULTIPLE );
  270. SetValue( Global:CarRules, BadElecSys, GoodElecSys, BadEngineSys, BrightLights, NoLights, BriskTurnover, NoTurnover, DimLights, GoodEngSys, SluggishTurnover );
  271. MakeSlot( Global:PeopleRules );
  272. SetSlotOption( Global:PeopleRules, MULTIPLE );
  273. SetValue( Global:PeopleRules, CalculateAge );
  274. MakeSlot( Global:List );
  275. SetSlotOption( Global:List, MULTIPLE );
  276. SetValue( Global:List, Gallons, Distance, Tank, Status, EngineTurnover, Engine, SparkPlug, Ignition, Passengers, Speed, Drivers, ModelYear, Registered, NumberofDoors, Colors, Owner, Battery, SparkPlugCondition, Timing, ElectricalSystem, LightSwitch, LightAppearance, IgnitionKey, GasSystem );
  277. MakeSlot( Global:TempList );
  278. SetSlotOption( Global:TempList, MULTIPLE );
  279. SetValue( Global:TempList, Gallons, Distance, Tank, Status, EngineTurnover, Engine, SparkPlug, Ignition, Passengers, Speed, Drivers, ModelYear, Registered, NumberofDoors, Colors, Owner, Battery, SparkPlugCondition, Timing, ElectricalSystem, LightSwitch, LightAppearance, IgnitionKey, GasSystem );
  280.  
  281.        /*************************************
  282.         ****  INSTANCE: TomsCar
  283.         *************************************/
  284. MakeInstance( TomsCar, Sedans );
  285. TomsCar:Battery = Low;
  286. TomsCar:Speed = 65;
  287. SetValue( TomsCar:Drivers, Mary );
  288.  
  289.        /*************************************
  290.         ****  INSTANCE: MarysCar
  291.         *************************************/
  292. MakeInstance( MarysCar, Sedans );
  293.  
  294. /************** METHOD: InitMarysCar   ***************/
  295. MakeMethod( MarysCar, InitMarysCar, [],
  296.     ResetValue( MarysCar:ElectricalSystem ) And ResetValue( MarysCar:Status )
  297.       And ResetValue( MarysCar:Battery ) And ResetValue( MarysCar:Speed ) );
  298. SetSlotOption( MarysCar:Battery,  IMAGE, StateBox1 );
  299. SetSlotOption( MarysCar:Speed,  IMAGE, Slider1, Meter1 );
  300.  
  301.        /*************************************
  302.         ****  INSTANCE: DicksCar
  303.         *************************************/
  304. MakeInstance( DicksCar, StationWagons );
  305.  
  306.        /*************************************
  307.         ****  INSTANCE: Mary
  308.         *************************************/
  309. MakeInstance( Mary, People );
  310. Mary:Income = 50000;
  311. Mary:House = FALSE;
  312.  
  313.        /*************************************
  314.         ****  INSTANCE: Dick
  315.         *************************************/
  316. MakeInstance( Dick, People );
  317.  
  318.        /*************************************
  319.         ****  INSTANCE: Tom
  320.         *************************************/
  321. MakeInstance( Tom, People );
  322.  
  323.        /*************************************
  324.         ****  INSTANCE: Text1
  325.         *************************************/
  326. MakeInstance( Text1, Text );
  327. Text1:X = 208;
  328. Text1:Y = 10;
  329. Text1:Width = 58;
  330. Text1:Height = 44;
  331. Text1:Visible = TRUE;
  332. Text1:Title = "The Autosim Example";
  333. Text1:ShowBorder = TRUE;
  334. Text1:Justification = CENTER;
  335.  ResetImage (  Text1  );  
  336.  
  337.        /*************************************
  338.         ****  INSTANCE: Bitmap3
  339.         *************************************/
  340. MakeInstance( Bitmap3, Bitmap );
  341. Bitmap3:X = 280;
  342. Bitmap3:Y = 1;
  343. Bitmap3:Visible = TRUE;
  344. Bitmap3:FileName = Bitone.bmp;
  345. Bitmap3:ShowBorder = TRUE;
  346. Bitmap3:FitToScreen = FALSE;
  347. Bitmap3:Width = 292;
  348. Bitmap3:Height = 80;
  349.  ResetImage (  Bitmap3  );  
  350.  
  351.        /*************************************
  352.         ****  INSTANCE: Button1
  353.         *************************************/
  354. MakeInstance( Button1, Button );
  355. Button1:X = 8;
  356. Button1:Y = 36;
  357. Button1:Title = "INITialize MarysCar";
  358. Button1:Visible = TRUE;
  359. Button1:Width = 175;
  360. Button1:Height = 27;
  361. Button1:Action = Clear;
  362. Button1:ShowBorder = FALSE;
  363.  ResetImage (  Button1  );  
  364.  
  365.        /*************************************
  366.         ****  INSTANCE: StateBox1
  367.         *************************************/
  368. MakeInstance( StateBox1, StateBox );
  369. StateBox1:X = 9;
  370. StateBox1:Y = 86;
  371. StateBox1:Visible = TRUE;
  372. StateBox1:Title = "Status of MarysCar Battery";
  373. StateBox1:ShowBorder = TRUE;
  374. StateBox1:Width = 162;
  375. StateBox1:Height = 87;
  376. StateBox1:Owner = MarysCar;
  377. StateBox1:OwnerSlot = Battery;
  378.  ResetImage (  StateBox1  );  
  379.  
  380.        /*************************************
  381.         ****  INSTANCE: Button2
  382.         *************************************/
  383. MakeInstance( Button2, Button );
  384. Button2:X = 8;
  385. Button2:Y = 3;
  386. Button2:Title = "Check MarysCar Battery";
  387. Button2:Visible = TRUE;
  388. Button2:Width = 188;
  389. Button2:Height = 27;
  390. Button2:Action = RunExam1;
  391. Button2:ShowBorder = TRUE;
  392.  ResetImage (  Button2  );  
  393.  
  394.        /*************************************
  395.         ****  INSTANCE: Meter1
  396.         *************************************/
  397. MakeInstance( Meter1, Meter );
  398. Meter1:X = 187;
  399. Meter1:Y = 86;
  400. Meter1:Visible = TRUE;
  401. Meter1:Title = "Show Speed of MarysCar";
  402. Meter1:ShowBorder = TRUE;
  403. Meter1:Value = 55;
  404. Meter1:Width = 181;
  405. Meter1:Height = 85;
  406. Meter1:Owner = MarysCar;
  407. Meter1:OwnerSlot = Speed;
  408.  ResetImage (  Meter1  );  
  409.  
  410.        /*************************************
  411.         ****  INSTANCE: Slider1
  412.         *************************************/
  413. MakeInstance( Slider1, Slider );
  414. Slider1:X = 376;
  415. Slider1:Y = 87;
  416. Slider1:Visible = TRUE;
  417. Slider1:Title = "Set Speed of MarysCar";
  418. Slider1:RightAction = INIT;
  419. Slider1:ShowBorder = TRUE;
  420. Slider1:Value = 55;
  421. Slider1:Width = 191;
  422. Slider1:Height = 85;
  423. Slider1:Owner = MarysCar;
  424. Slider1:OwnerSlot = Speed;
  425.  ResetImage (  Slider1  );  
  426.  
  427.  
  428.  
  429. /*********************************************************/
  430. /**         ALL RULES ARE SAVED BELOW             **/
  431. /*********************************************************/
  432.  
  433.        /*************************************
  434.         ****  RULE: BadElecSys
  435.         *************************************/
  436. MakeRule( BadElecSys, [car|Autos],
  437.     car:SparkPlugCondition #= Bad Or car:Timing #= OutOfSynch
  438.       Or car:Battery #= Low,
  439.     car:ElectricalSystem = Bad );
  440.  
  441.        /*************************************
  442.         ****  RULE: GoodElecSys
  443.         *************************************/
  444. MakeRule( GoodElecSys, [car|Autos],
  445.     car:SparkPlugCondition #= Okay And car:Timing #= InSynch And
  446.       car:Battery #= Charged,
  447.     car:ElectricalSystem = Okay );
  448.  
  449.        /*************************************
  450.         ****  RULE: BadEngineSys
  451.         *************************************/
  452. MakeRule( BadEngineSys, [car|Autos],
  453.     car:IgnitionKey #= Off Or car:GasSystem #= Bad Or car:ElectricalSystem
  454.       #= Bad,
  455.     car:Status = Stopped );
  456.  
  457.        /*************************************
  458.         ****  RULE: BrightLights
  459.         *************************************/
  460. MakeRule( BrightLights, [car|Autos],
  461.     car:LightSwitch #= On And car:Battery #= Charged,
  462.     car:LightsAppearance = Bright );
  463.  
  464.        /*************************************
  465.         ****  RULE: NoLights
  466.         *************************************/
  467. MakeRule( NoLights, [car|Autos],
  468.     car:LightSwitch #= Off,
  469.     car:LightAppearance = Dark );
  470.  
  471.        /*************************************
  472.         ****  RULE: BriskTurnover
  473.         *************************************/
  474. MakeRule( BriskTurnover, [car|Autos],
  475.     car:Ignition #= On And car:ElectricalSystem #= Okay,
  476.     car:EngineTurnover = Brisk );
  477.  
  478.        /*************************************
  479.         ****  RULE: NoTurnover
  480.         *************************************/
  481. MakeRule( NoTurnover, [car|Autos],
  482.     car:IgnitionKey #= Off,
  483.     car:EngineTurnover = Absent );
  484.  
  485.        /*************************************
  486.         ****  RULE: DimLights
  487.         *************************************/
  488. MakeRule( DimLights, [car|Autos],
  489.     car:LightSwitch #= On And car:Battery #= Low,
  490.     car:LightsAppearance = Dim );
  491.  
  492.        /*************************************
  493.         ****  RULE: GoodEngSys
  494.         *************************************/
  495. MakeRule( GoodEngSys, [car|Autos],
  496.     car:IgnitionKey #= On And car:GasSystem #= Okay And car:Battery
  497.       #= Charged,
  498.     car:Status = Running );
  499.  
  500.        /*************************************
  501.         ****  RULE: SluggishTurnover
  502.         *************************************/
  503. MakeRule( SluggishTurnover, [car|Autos],
  504.     car:IgnitionKey #= On And car:ElectricalSystem #= Bad,
  505.     car:EngineTurnover = Sluggish );
  506.  
  507.        /*************************************
  508.         ****  RULE: CalculateAge
  509.         *************************************/
  510. MakeRule( CalculateAge, [person|People],
  511.     person:Age #= 21,
  512.     person:licensed = yes );
  513.  
  514.        /*************************************
  515.         ****  RULE: HaveHouse
  516.         *************************************/
  517. MakeRule( HaveHouse, [person|People],
  518.     person:Income > 100000,
  519.     person:House = TRUE );
  520.  
  521.        /*************************************
  522.         ****  RULE: NotHaveHouse
  523.         *************************************/
  524. MakeRule( NotHaveHouse, [person|People],
  525.     person:Income <= 100000,
  526.     person:House = FALSE );
  527.  
  528.  
  529.  
  530. /*********************************************************/
  531. /**         ALL GOALS ARE SAVED BELOW             **/
  532. /*********************************************************/
  533.  
  534.        /*************************************
  535.         ****  GOAL: Planeflying
  536.         *************************************/
  537. MakeGoal( Planeflying,
  538.     Plane:Flying );
  539.  
  540.        /*************************************
  541.         ****  GOAL: LowBatt
  542.         *************************************/
  543. MakeGoal( LowBatt,
  544.     MarysCar:Battery #= Low );
  545.  
  546.        /*************************************
  547.         ****  GOAL: ElecSys
  548.         *************************************/
  549. MakeGoal( ElecSys,
  550.     MarysCar:ElectricalSystem #= Bad );
  551.  
  552.        /*************************************
  553.         ****  GOAL: Running
  554.         *************************************/
  555. MakeGoal( Running,
  556.     MarysCar:Status #= Running );
  557.  
  558.        /*************************************
  559.         ****  GOAL: MCStatus
  560.         *************************************/
  561. MakeGoal( MCStatus,
  562.     MarysCar:Status #= Running );
  563.  
  564.        /*************************************
  565.         ****  GOAL: MaryHouse
  566.         *************************************/
  567. MakeGoal( MaryHouse,
  568.     KnownValue?( Mary:House ) );
  569.