Input: 𝐺 : The scenario graph in the form 𝐴 , 𝐸 , 𝑖 𝑛 , 𝐹
  RegionFound: a flag for deciding the termination criteria
Output: 𝐺 𝑘 : ITM
Data: 𝑐 𝑢 𝑟 𝑁 𝑜 𝑑 𝑒 : Denotes the next node to be inspected
    𝑒 𝑥 𝑖 𝑡 𝑁 𝑜 𝑑 𝑒 : Denotes the trailer node when the region is formed
1 𝐺 𝑘 = 𝐺     // Initially, 𝐺 is the ITM
2 𝑐 𝑢 𝑟 𝑁 𝑜 𝑑 𝑒 = 𝑖 𝑛    // Start from the initial node of 𝐺 𝑘
3 while 𝑐 𝑢 𝑟 𝑁 𝑜 𝑑 𝑒 is not a 𝑓 𝑖 𝑛 𝑎 𝑙 𝑁 𝑜 𝑑 𝑒 do
4 if 𝐹 𝑖 𝑛 𝑑 𝐶 𝑜 𝑛 𝑡 𝑟 𝑜 𝑙 𝑁 𝑜 𝑑 𝑒 ( 𝑐 𝑢 𝑟 𝑁 𝑜 𝑑 𝑒 ) then // 𝑐 𝑢 𝑟 𝑁 𝑜 𝑑 𝑒 is not a
   control node
5 𝑒 𝑥 𝑖 𝑡 𝑁 𝑜 𝑑 𝑒    =    𝐶 𝑜 𝑚 𝑝 𝑜 𝑠 𝑒 𝑅 𝑒 𝑔 𝑖 𝑜 𝑛 ( 𝐺 𝑘 , 𝑐 𝑢 𝑟 𝑁 𝑜 𝑑 𝑒 )
         // Composing to be carried out at 𝑐 𝑢 𝑟 𝑁 𝑜 𝑑 𝑒
6 else
7 if 𝑒 𝑥 𝑖 𝑡 𝑁 𝑜 𝑑 𝑒 = 𝑁 𝑈 𝐿 𝐿 then // Ensures that no composition was carried out so far
8    𝑅 𝑒 𝑔 𝑖 𝑜 𝑛 𝐹 𝑜 𝑢 𝑛 𝑑 = 𝐹 𝐴 𝐿 𝑆 𝐸 ;
9 end if;
1 0  break;
1 1 end if
1 2 𝑐 𝑢 𝑟 𝑁 𝑜 𝑑 𝑒 = 𝑒 𝑥 𝑖 𝑡 𝑁 𝑜 𝑑 𝑒 ;
1 3 end while
1 4 return 𝐺 𝑘
Function FormIntermediateGraph(G, RegionFound)
Procedure 3: Function FormIntermediateGraph.