Megaprogram Example: Code
io_mmh = SETUP ("InputOutput")
route_mmh = SETUP ("RouteInfo")
best2_mmh.SETATTRIBUTES (criterion = "cost")
cities_default = route_mmh.GETPARAM(Pair_of_Cities)
input_cities_ih = io_mmh.INVOKE ("input”, cities_default)
WHILE (input_cities_ih.EXAMINE() != DONE) {}
cities = input_cities_ih.EXTRACT()
route_ih = route_mmh.INVOKE ("AllRoutes", Pair_of_Cities = cities)
WHILE (route_ih.EXAMINE() != DONE) {}
routes = route_ih.EXTRACT()
IF (best1_mmh.ESTIMATE("Best_Route")
< best2_mmh.ESTIMATE("Optimum") )
THEN {best_ih = best1_mmh.INVOKE ("Best_Route", Goods = info_goods,
Pair_of_Cities = cities, List_of_Routes = routes,
Cost_Ground = cost_list_ground, Cost_Air = cost_list_air)}
ELSE {best_ih = best2_mmh.INVOKE ("Optimum", Goods = info_goods,
// Setup connections to megamodules.
// Set global variables valid for all invocations
// Get information from the megaprogram user
// about the goods to be transported and about
// the two desired cities.
// Get all routes between the two cities.
//Get all city pairs in these routes.
//Calculate the costs of all the routes.
// Figure out the optimal megamodule for
// picking the best route.
//Pick the best route and display the result.
// Terminate all invocations