Problem-Solving Functions  
 void function main ()
 {
   check_if_already_placed_employees();
   if (possible_to_place_the_group_head())
   { if (possible_to_place_the_secretaries())
     { if (possible_to_place_the_managers())
       { if (possible_to_place_the_heads_of_large_projects())
         { print; print "----- Placing simple researchers";
           try_to_place_simple_researchers_by_pairs();
           try_to_place_remaining_employees_alone();
         }
       }
     }
   }
 }
 boolean function possible_to_place_the_secretaries()
 {
   print "----- Placing the secretaries";
   spec Secretary : ?  | set The_secretaries;
   for s in $The_secretaries
   { spec "[Employee:$s]->(In)->[Office]" | set office_of_this_employee;
     if ($office_of_this_employee == "")  
     { if (! possible_to_place_with_another_secretary($s))
       { if (! possible_to_place_nearest_group_head($s,Large_office))
         { if (! possible_to_place_nearest_group_head($s,Small_office))
           { print "The secretary $s cannot be placed close to
                 $Office_of_group_head, the office of head of group $The_group_head"; 
             return false;
           }
         }
       }
     }
   }
   return true;
 }
    
 boolean function possible_to_place_nearest_group_head (employee,kind_of_office)
 {
   set near_chain "->(Near)->";  //first, try very close offices
   while (true)                  //the loop progressively increases $near_chain
   { spec "[Office:?]$near_chain[Office:$Office_of_group_head]"
         | set offices_near_group_head;
     if ($offices_near_group_head == "") { break; } //no more office at such distance 
     for o in $offices_near_group_head
     { ? $kind_of_office : $o  | set office_is_suitable;
       if ($office_is_suitable)
       { spec "[Employee]->(In)->[Office:$o]" | set occupied_office;
         if ("$occupied_office" == "") //$o is empty
         { place_employee_in($employee,$o); return true; }
       }
     }
     set near_chain "$near_chain[Office]->(Near)->";
   }
   return false;
 }
 void function place_employee_in (employee, office)
 {
   name "#$employee$office" "[Employee: $employee]->(In)->[Office: $office]";
   print "$employee is placed in $office";
   subtractFrom Employees_to_place $employee;
 }
 
 |   
 |