Best Matching Algorithm Help

All calls through and within a Quadro are made according to call routing patterns that specify a destination based on a dialed number. When a user dials a number to make a call, the Quadro matches the dialed number against the existing patterns that are specified in the Call Routing table. If the dialed number matches only to a single pattern, this pattern will be used to set up a call. If several patterns have been found to match the number, the Quadro uses the Best Matching Algorithm to prioritize the matching patterns. Once the patterns are prioritized, the pattern with the highest priority will be used as a preferred route for call setup. The successive patterns will be used only if the destination specified by a higher priority pattern is unreachable.

To prioritize the matching patterns, the following criteria are sequentially applied to matching patterns. The criteria are ordered by their priorities: Each consecutive criterion is calculated only for the patterns that take the same value for the preceding criteria: that is Criterion 3 is calculated only for patterns that take the same value for Criterion 1 and Criterion 2.

List 1
Criterion 1 The presence of asterisks ("*") in a pattern
The patterns without "*" have higher priority.
Criterion 2 The total number of matching digits/symbols inside and outside the braces/brackets
The more matching digits a pattern contains, the higher its priority.
Criterion 3 The number of matching digits/symbols outside the braces/brackets
The more matching digits outside braces/brackets a pattern contains, the higher its priority.
Note: This criterion is used only if several patterns take an equal but non-zero value for Criterion 2.
Criterion 4 The total number of question marks ("?") inside and outside the braces/brackets
The more question marks a pattern contains, the higher its priority.
Criterion 5 The number of question marks ("?") outside braces/brackets
The more question marks outside braces/brackets a pattern contains, the higher its priority.
Note: This criterion is used only if several patterns take an equal but non-zero value for Criterion 4.
Criterion 6 The number of square brackets ("[]")
The more ranges a pattern has, the higher its priority.
Criterion 7 The number of braces ("{}")
The more ranges a pattern has, the higher its priority.
Criterion 8 The number of asterisks ("*")
The fewer asterisks a pattern has, the higher its priority.
Criterion 9 The value of the metric
The lower the metric of a pattern is, the higher its priority.
Criterion 10 The position in the routing table
The higher the position of a pattern in the routing table is, the higher its priority.

The algorithm is discussed in the example below.

Example: The user has dialed 1231 and the following matching patterns have been found.

The list of matching patterns found by RA
*1*
123*
{11-15}3*
?2?1
123?
[1-3]*
[1-3]???
{100-150, asd, \*\?}1
12*31
1[1-3]3[0-8]
1231
*2*1
*

The step-by-step discussion of the Best Matching Algorithm is as follows.

Step 1: The list is split into two groups separating the patterns with "*" from those without (Criterion 1). The patterns with "*" form a group with a lower priority and are pushed back to the end of the list.

Criterion 1
The list split into two subgroups
?2?1
123?
[1-3]???
{100-150, asd, \*\?}1
1[1-3]3[0-8]
1231
*1*
123*
{11-15}3*
[1-3]*
12*31
*2*1
*

Step 2: The two groups of patterns are arranged separately from each other by the total number of matching digits inside and outside the braces/brackets in the descending order (Criterion 2). The patterns that contain the same number of matching digits are grouped into sub-lists.

Criterion 2
The list of patterns Matching digits
?2?1 2
123? 3
[1-3]??? 1
{100-150, asd, \*\?}1 4
1[1-3]3[0-8] 4
1231 4
*1* 1
123* 3
{11-15}3* 3
[1-3]* 1
12*31 4
*2*1 2
* 0
Criterion 2
The list of patterns Matching digits
1[1-3]3[0-8]
1231
{100-150, asd, \*\?}1
4
4
4
123? 3
?2?1 2
[1-3]??? 1
12*31 4
123*
{11-15}3*
3
3
*2*1 2
*1*
[1-3]*
1
1
* 0

Step 3: The new sub-lists are arranged separately from each other by the number of matching digits outside the braces/brackets (Criterion 3). The patterns that contain the same number of matching digits are grouped into sub-lists.

Criterion 3
The list of patterns Matching digits
1[1-3]3[0-8]
1231
{100-150, asd, \*\?}1
2
4
1
123? -
?2?1 -
[1-3]??? -
12*31 -
123*
{11-15}3*
3
1
*2*1 -
*1*
[1-3]*
1
0
* -
Criterion 3
The list of patterns Matching digits
1231
1[1-3]3[0-8]
{100-150, asd, \*\?}1
4
2
1
123? -
?2?1 -
[1-3]??? -
12*31 -
123* 3
{11-15}3* 1
*2*1 -
*1* 1
[1-3]* 0
* -

The Best Matching Algorithm will stop after executing step 3 as no new sub-lists are formed. The resultant list of prioritized patterns will be the following:

The sorted list of patterns
1231
1[1-3]3[0-8]
{100-150, asd, \*\?}1
123?
?2?1
[1-3]???
12*31
123*
{11-15}3*
*2*1
*1*
[1-3]*
*