// Example of how a megaprogram for the transportation modules could look like // ATTENTION: this example has never been compiled or executed // CREATED: 2/18/98, D. Beringer; UPDATED: 08/04/98 by L. Melloul // Language Syntax as defined by July 1998 // This example shows the interaction between a Megaprogram and // six Megamodules through the CHAIMS primitives. InputOutput // (IO megamodule), MathMegamodule, RouteInfo, AirGround, // PickBest and RouteOptimizer are Megamodules whose services // will be invoked by the Megaprogram. The aim is to retrieve // information about goods to be transported between two cities // and to find the best route between these two cities (Air, or // Ground, or combination of both). // Notes: IO Megamodule and Math Megamodule are called Helper Modules; // PickBest and RouteOptimizer are two megamodules offering the // same service. Transportation BEGINCHAIMS // Bind to the megamodules; mmh stands for megamodule_handle io_mmh = SETUP ("InputOutput") math_mmh = SETUP ("MathMegamodule") route_mmh = SETUP ("RouteInfo") cost_mmh = SETUP ("AirGround") best1_mmh = SETUP ("PickBest") best2_mmh = SETUP ("RouteOptimizer") // Set default values for some parameter names of methods or global parameters // of megamodules, respectively for PickBest and RouteOptimizer best1_mmh.SETPARAM (Criterion = "cost") best2_mmh.SETPARAM (Criterion = "cost") // Get information from the megaprogram user about the goods to be transported // (start and end time, size and weight) and the two desired cities; ih stands // for invocation_handle input_goods_ih = io_mmh.INVOKE ("info_goods") input_cities_ih = io_mmh.INVOKE ("input_cities") // info_goods and input_cities are two method names which belong to // the IO megamodule; here, no parameters are given as input of these // functions WHILE (input_cities_ih.EXAMINE() != DONE) {} (cities_var = cities) = input_cities_ih.EXTRACT() // cities_var represents the two cities we are looking for (i.e. source // and destination); we do not need at this point the result of the // IO invocation input_goods_ih. // Get all routes between the two cities and all city pairs in these routes // Call the "AllRoutes" method in the RouteInfo megamodule route_ih = route_mmh.INVOKE ("AllRoutes", Pair_of_Cities = cities_var) WHILE (route_ih.EXAMINE() != DONE) {} (routes_var = routes) = route_ih.EXTRACT() pairs_h = route_mmh.INVOKE ("CityPairList", List_of_Routes = routes_var) WHILE (pairs_ih.EXAMINE() != DONE) {} (city_pairs_var = city_pairs) = pairs_ih.EXTRACT() // Extract the information about the goods before calculating all the // costs of all routes between city pairs; cost calculated for each // intermediate route for each type of route, i.e. ground and air WHILE (input_goods_ih.EXAMINE() != DONE) {} (info_goods_var = info_goods) = input_goods_ih.EXTRACT() cost_ground_ih = cost_mmh.INVOKE ("Cost_for_Ground", List_of_City_Pairs = city_pairs_var, Goods = info_goods_var) cost_air_ih = cost_mmh.INVOKE ("Cost_for_Air", List_of_City_Pairs = city_pairs_var, Goods = info_good_var) WHILE (cost_ground_ih.EXAMINE() != DONE) {} (cost_ground_var = cost_list_ground) = cost_ground_ih.EXTRACT() WHILE (cost_air_ih.EXAMINE() != DONE) {} (cost_air_var = cost_list_air) = cost_air_ih.EXTRACT() // ESTIMATE the total cost of the best route as calculated by each of the // two optimization megemodules (PickBest and RouteOptimizer) // Pick the actual best route and display the result (myfee1 = fee) = best1_mmh.ESTIMATE("Best_Route") (myfee2 = fee) = best2_mmh.ESTIMATE("Best_Route") smaller_ih = math_mmh.INVOKE("Smaller", Arg1 = myfee1, Arg2 = myfee2) WHILE (smaller_ih.EXAMINE() != DONE) {} (comp_res = result) = smaller_ih.EXTRACT() IF (comp_res = TRUE) THEN { best_ih = best1_mmh.INVOKE ("Best_Route", Goods = info_goods_var, Pair_of_Cities = cities_var, List_of_Routes = routes_var, Cost_Ground = cost_ground_var, Cost_Air = cost_air_var) } ELSE { best_ih = best2_mmh.INVOKE ("Best_Route", Goods = info_goods_var, Pair_of_Cities = cities_var, List_of_Routes = routes_var, Cost_Ground = cost_ground_var, Cost_Air = cost_air_var) } WHILE (best_ih.EXAMINE() != DONE) {} (result_var = result) = best_ih.EXTRACT() print_ih = io_mmh.INVOKE ("Print_Best_Route", Best_Route = result_var) WHILE (print_ih.EXAMINE() != DONE) {} // TERMINATE the connection with the six megamodules io_mmh.TERMINATE() math_mmh.TERMINATE() route_mmh.TERMINATE() cost_mmh.TERMINATE() best1_mmh.TERMINATE() best2_mmh.TERMINATE() ENDCHAIMS