# Assigning Candidate Tutors to Modules: A Preference Adjustment Matching Algorithm (PAMA)
## 4 The Preference Adjustment Matching Algorithm (PAMA)
### The PAMA Logic  
The algorithm runs in rounds as long as assignments are being made. In each round, modules are examined sequentially, based on module rankings and tutors' preferences (pseudocode is provided in Scheme 1). The initial sequence of modules is randomly arranged, and during each turn, the algorithm examines each module one by one. If the module has available capacity, then it starts with its highest-ranked tutor, checking if he/she is eligible and if the module is his/her top choice. If both conditions are met, the tutor is assigned. If the tutor is eligible but the module is not in tutor's highest preference, then the algorithm marks that position as pending and moves to the next ranked tutor. This approach allows modules to secure their preferred tutors who also prioritize them while keeping options open for tutors who might be assigned elsewhere. The module examination continues until all positions are filled or all ranked tutors have been considered, balancing the needs of both modules and tutors. Once a tutor is assigned to a module, the algorithm removes him/her from the candidate rankings of all other modules and then cleans up the tutor's preference list. It also removes the particular module from tutors' preferences lists when a tutor becomes ineligible for a module. Ineligibility can occur if there are no free positions left or if all remaining positions are pended and reserved for potential higher-ranked tutors who prefer that module. When a module is removed from a tutor's preference list, all subsequent preferences shift up. For example, if a tutor with four preferences becomes ineligible for his/her top two preferences, his/her third preference becomes his/her new first choice, and his/her fourth becomes second, leaving him/her with only two preferences. When all modules are examined one-by-one, then the next round will reexamine the modules again. This first stage of the algorithm terminates if no assignments and no alterations in preference lists are made after cycling through all modules. However, a potential deadlock can occur when modules are left waiting for eligible tutors who do not have them as first preference. This creates a pending cycle where, for example, Module A waits for a tutor who prefers Module B, but Module B is waiting for a different tutor who prefers Module C (or A), and so on. This pending cycle can prevent assignments, leaving modules with unfilled pending positions. It is unlikely, in the practical application of the algorithm, that a module will end up with a zero list of contenders, since in most cases, the number of modules is always fewer than the available tutors. The algorithm prioritizes matching modules with their highest-ranked tutors, and a module losing all contenders would require all potential tutors to have better preferences or rankings elsewhere. Moreover, there is no specific maximum number of'reserved' tutors for a module as this depends on the module's capacity requirements. In the rare case where a module remains without contenders, the algorithm would flag this for human intervention, where vacant positions are filled manually after the automated process completes (Section 3). One important aspect regarding PAMA's sequential process of module evaluation is that the order of modules affects the outcome only during the deadlock resolution and not when a maximal solution is achievable. The sequence of modules is generated randomly, with no specific ordering criteria applied. When the algorithm achieves a maximal matching, different module examination sequences can result in different pending states and assignments within a round, but the outcome is consistent because the algorithm carefully takes into account both modules' rankings and tutors' preferences to ensure mutual satisfaction for both tutors and candidates. However, under deadlock situations, examination order plays a significant role in determining final assignments.