Integer Programming Models for the Median of a 0-1 String Set Under Levenshtein Distance
Abstract
The Median String Problem calls for finding a string that minimizes the average distance from a given set of strings. Under the Levenshtein (or edit) metric, the problem is -hard even for binary strings. We devised two novel integer linear programming models for this case and tested them against the only formulation we are aware of in the literature. Our numerical experiments attest to the efficacy of the proposed approach.
Keywords and phrases:
Levenshtein Distance, Median String Problem, Integer ProgrammingFunding:
Claudio Arbib: National Innovation Ecosystem grant ECS00000041–VITALITY–CUP E13C22001060006. VITALITY: Innovation, digitalization and sustainability for the diffused economy in Central Italy (Ecosistema di Innovazione, Digitalizzazione e Sostenibilità per l’Economia Diffusa nell’Italia Centrale).Copyright and License:
2012 ACM Subject Classification:
Mathematics of computing Combinatorial optimization ; Theory of computation Integer programmingSupplementary Material:
Software: https://github.com/D-hash/CenterLevenshtein [2]archived at
swh:1:dir:29a2a7464e7ff0450026b55e399cfb749ef45866
Acknowledgements:
The authors are grateful to the reviewers for their helpful comments.Editors:
Martin Aumüller and Irene FinocchiSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl – Leibniz-Zentrum für Informatik
1 Introduction
Given a set of strings formed by elements taken from a finite alphabet , the Closest String Problem calls for finding another string that minimizes its distance from . This is called a median or centre of , according to whether its distance from is defined as the average or the largest distance between and the , respectively.
Popular metrics for this problem are the Hamming distance, that counts the minimum number of symbols of one should replace to obtain , and the Levenshtein (or edit) distance. According to the latter metric, any two strings can be transformed into one another by the repeated application of three operations: addition, deletion, substitution. For example, one can transform into by directly replacing all elements of the first string but the last; or, also, by adding an o before the string head (obonzo), replacing b by z (ozonzo) and deleting the z before the last element. Unlike the Hamming distance, this metric is well defined for strings of different lengths.
Let , respectively, denote the cost of addition, deletion and substitution. Then the weighted Levenshtein distance of and is defined as the minimum total cost to transform into (or vice-versa). These costs can also depend, in general, on the position in the string(s) where the operation is performed. For non-negative costs, the function so defined is clearly non-negative, symmetric, subadditive, and is 0 if and only if .
In some applications, it is assumed that , and in this case we speak of the unweighted Levenshtein distance. The Levenshtein distance between an -string and an -string can be computed in time (see Section 2 below), but under the Strong Exponential Time Hypothesis it cannot be computed in strongly subquadratic time [5].
Two major types of Closest String Problem are considered in the literature:
The Median String Problem: Find a string that minimizes
The Centre String Problem: Find a string that minimizes
Both problems are -hard under the Levenshtein metric [21, 31]. Under the Hamming metric, which is the special case of Levenshtein with , the median problem is trivial while the centre problem remains -hard [15]: the best exact algorithms for the latter problem are based on integer linear programming, see [4], [13] (note that also sampling centre strings under the Hamming metric is -hard [7]).
1.1 Literature
Median and centre strings are fundamental in such applications as classification [14, 26], trace reconstruction and matrix completion [10, 24], DNA/RNA sequence alignment [22], character and shapes recognition [8, 11]. Various solution methods were developed for metrics based on the Hamming distance: from heuristics and approximation algorithms [12, 16, 17, 34, 35], to exact methods based on Integer Linear Programming (ILP) [3, 4, 28]. However, the Hamming distance is not well-suited to models arising in computational biology and, to some extent, information theory, where the Levenshtein distance [6] is often more appropriate. The increasing complexity introduced by this metric explains why algorithms for this problem are, at the moment, less numerous and with comparatively poorer performance.
Several heuristics were devised for the Median String Problem, such as perturbation iterative refinement algorithms. Starting from an initial string [1], edits are done one at a time in sequence [27] or multiple at once [9], the latter achieving a faster convergence at the expense of solution quality. The procedure is interrupted when no further improvements can be found. Critical aspects lie in the definition of good initial strings and of operation ranking [29]. Alternatively, combination iterative refinement algorithms make use of subsequent averaging steps among pairwise input strings, up to finding an output string.
To our knowledge, only one ILP model has been investigated so far [20]. In that paper, a finite set of strings is given, each one weighted by the probability of its occurrence. The edit costs are arbitrary and independent of the position of the character. The goal is to minimize the total cost paid to transform the median string into each of the strings given, weighted by string occurrence probabilities, minus an incentive (equal to ) for any character saved in the output string: in other words, the median string is penalized proportionally to its length. Although ingenious, this formulation appears of little practical benefit: up to 100 000 seconds of CPU are in fact reported to compute the median of ten 4-characters strings of length 10.
1.2 Our contribution
In this paper, we revise the ILP model proposed in [20] and compare it with two new ILP formulations for the Median String Problem. Unlike [20], we do not consider different string occurrence probabilities, nor different operation costs , because flat coefficients in the objective function generally make the problem harder due to symmetry.
More general cases and the Centre String Problem will be approached and discussed in a subsequent study. Also, we focus on the simpler case where is binary: an extension to non-binary alphabets is formally straightforward, but its efficiency remains to be ascertained and will be the subject of future research.
Limiting to a binary alphabet, and in particular encoding in , has the advantage of a numerical interpretation of the output string that allows us to directly use its 0-1 components in the formulation, eliminating the need for auxiliary variables. In fact, even for binary , in [20] the median string components are generically integer and not 0-1, and for that reason their formulation requires activation constraints containing a “big M”.
Note also that the median string length cannot be predicted in a closed form from the problem data, but is an indeterminate of the problem and, as such, it is introduced in [20] as a single integer decision variable of the model. We adopt a different approach and, in our formulations, “digitalize” this variable by means of a limited amount of 0-1 variables. Another improvement we propose regards the upper bound to the median string length: the value proposed in [20], i.e., the sum of the string lengths in , can in fact be replaced by twice the maximum length of a string in minus 1.
Our computational findings demonstrate the advantage obtained with the modifications described.
2 Levenshtein distance computation
In this section we survey two methods to compute the distance between two given strings . Each method corresponds to an ILP model, that will be recalled in Section 3 in order to develop our ILP formulations.
2.1 Shortest path computation
The Levenshtein distance between two strings , can be computed by a simple recursion [33], which amounts to finding the shortest path from to in a directed acyclic graph where
and respectively stand for add (or across), delete (or down) and substitute (or slant) arcs. All the arcs are directed from left to right and/or from up to down: those in link to , to and so on, up right to for all ; those in link to , to and so on, down to ; finally, those in diagonally link to (see Figure 1). Summarizing:
We identify arcs with transitions that transform into in the following way:
-
An across arc corresponds to updating by adding immediately after its element.
-
A down arc corresponds to deleting the element of .
-
A slant arc corresponds to replacing with .
When node is eventually reached, .
Graph has arcs. Let () be the cost of adding to (deleting from , substituting) an entry in the transition identified by arc . Then the weight of a shortest -path equals the weighted Levenshtein distance between and . Defining for any , this distance is obtained by solving
| (1) | |||||
| s.t. | |||||
where () is the set of arcs entering (leaving) the generic node , with . Since the polyhedron is integral, does not need to be constrained in .
2.2 Planar matching computation
Definition 1.
Given a bipartite graph , a matching is planar (or non-crossing) if no two edges in cross in the canonical drawing of .
Besides the method seen in § 2.1, we can represent the problem of finding the Levenshtein distance between as that of finding a planar matching in a complete undirected bipartite graph with node sets corresponding to the components of , . Precisely:
-
Matching to corresponds to substituting with .
-
An unmatched node of in position corresponds to adding to , in that position, the corresponding element of .
-
An unmatched node of corresponds instead to deleting the corresponding element from .
Since the matching is planar, the letters are inserted, replaced, or removed in the same order as they appear in the sequences. Then, to get the weight of the operations required to transform into , one simply has to add the weight of the unmatched nodes to that of the edges, which represent costly substitutions (that is, those with ).
As an example, consider the planar matching depicted in Figure 2 and interpreted in the caption. This matching corresponds to the shortest path shown in Figure 1.
Defining for all , with
if and only if ;
if and only if is left unmatched;
if and only if is left unmatched;
the distance between and is computed by solving
| (2) | |||||
| s.t. | |||||
where
-
is the cost of replacing with ;
-
() is the cost of deleting from (of adding to );
-
contains all the edges that cross in a canonical drawing of .
The graph has edges, as many as the essential variables of model (2) (the and variables are auxiliary and can be derived from the equations).
3 Integer linear programming formulations
In this section, we formulate the Median String Problem as an ILP, based on the Levenshtein distance computation methods presented in § 2.1 and § 2.2.
3.1 Path formulation
Let us begin with the distance computation presented in § 2.1. Let denote the length of and suppose for the moment that we know the median string to be of length . Associate then the string of with a directed acyclic multigraph where
The only difference from the graph of § 2.1 is that each slant arc is duplicated: that is, we define , where () is the set of costly (free) slant arcs of . Consistent with our initial assumption of unweighted distance, we let for and in all remaining cases. Given its shape, we call a grid (see Figure 1) with nodes arranged into rows (indexed by ) and columns (indexed by ).
The path used in § 2.1 to compute the distance between and is identified by a unit flow that traverses from source 00 to sink . Let denote the flow in arc , and call (respectively, ) the set containing the arcs that enter (leave) node . Considering also duplicated slant arcs, and contain up to four arcs; in particular, and are empty. Finally, if , then we let .
To reduce the length of a path, one can take advantage of free arcs, provided that they have non-zero capacity. But the capacity of a free arc ending in depends on and , being 1 if (because in this case replacement has no cost and one can use the free arc) and 0 if (for in this case, replacement has a cost and the free arc must be interdicted). Thus, if , then the capacity will be , while if , it will be . This consideration leads to the following mixed-integer linear model written for :
| (3) | |||||
| (4) | |||||
| (5) | |||||
| (6) | |||||
| (7) | |||||
Setting the objective reads
| (8) |
The path formulation thus obtained is essentially derived from the model proposed in [20]. Equations (3) enforce that each path starts in 00 and ends in , and define the paths together with flow conservation conditions (4). Inequalities (5), (6), that strengthen (c1) and (c2) of [20], allow a path to use free slant arcs provided that . Note that the -variables need not be constrained in , since the constraint matrix is totally unimodular for any choice of the -variables in .
However, a crucial detail omitted so far in our path formulation is that the median (or centre) string length is not known, which is why in [20] a further integer variable is introduced to represent it. This variable, named , is subject to the constraints () of [20] that involve a so-called “big M”: in such cases, the bounds obtained by linear relaxation are generally very loose, and the formulation performance is consequently expected to be very poor. To limit this inconvenience, we digitalize variable by introducing the following 0-1 decision variables for , where and are suitable bounds to :
-
if the median (or centre) length is at least ;
-
otherwise.
Naturally,
| (9) |
as implies . The generic grid is extended up to the column by setting
and the flow in each arc entering column is capped by
| (10) |
By (10), then, no flow can reach a node for larger than the median length.
Since is unknown, also the sink node is not determined and depends on the . The second condition (3), that assumes the sink in node , is then replaced by
| (11) |
(where we set by definition ). In fact,
We can prove the following upper bound on .
Proposition 2.
Let and assume . Then .
Proof.
Let be a median of with length , and suppose . Then every input string would require at least insertions just to match the median’s length. Hence, the total edit distance is . Let , and let us evaluate the distance of from . Any string of can be transformed into using edits, and itself requires no edit: hence, the total distance of from is , which means that is not median.
3.2 Matching formulation
The matching formulation is constructed after the distance computation method presented in § 2.2. For each we start from a complete undirected bipartite graph , where nodes in and in are ordered, so that the node of corresponds to and the node of to . Because we do not know the median string length , we suppose . The basic idea is to associate an edge joining the node of to the node of with the operation of substituting with . To distinguish between the case and we duplicate the edges of :
-
the set of edges of that represent a costly substitution;
-
the set of edges of that represent a free substitution.
Leaving the node of (the node of ) unmatched corresponds to bearing the cost of adding to (of deleting from) the median string. Unmatched nodes are represented by self-loops added to , so we define
-
the set of edges with both extremes in ;
-
the set of edges with both extremes in ;
and form in this way the final edge set
For every node of we then define the set of all edges (including self-loops) that have that node as an extreme:
Let be a lower bound to , and let us introduce our 0-1 decision variables:
if and only if is selected ();
the element of the median string ();
if and only if the median string length is at least ().
That is, the -variables are as the in § 2.2, while the - and the -variables are as in § 3.1. For , we let . The feasible region is then described by the following conditions written for :
| (12) | |||||
| (13) | |||||
| (14) | |||||
| (15) | |||||
| (16) | |||||
| (17) | |||||
| (18) | |||||
| (19) | |||||
| (20) |
Equation (14) forbids the selection of any edge that touches if is larger than the median string length . Condition (15) rewrites the no-cross condition in § 2.2, with being the set of edges of that cross in a canonical drawing of : if is selected, then the right-hand side is 0 and no edge crossing can in turn be selected; otherwise, the right-hand side is since this is the largest number of edges in a matching of . This condition can be further strengthened by redefining as follows for :
| (21) |
The objective is formally written as (8), but now or for self-loops, for , and for all the other edges.
4 Numerical experience
In this section, we report a computational experiment carried out with the formulations of Section 3. We use pat to denote the path formulation of § 3.1; mat for the matching formulation of § 3.2 strengthened with defined by (21); and finally, hay for the state-of-the-art formulation of [20].
We organized the testbed in two types of datasets.
-
Random (rnd): Each dataset of this type is denoted by rnd--, where is an upper bound to the lengths of the strings in the pool and is the total number of strings. String lengths are sampled uniformly at random from the interval . Each string element is drawn independently and uniformly from the alphabet .
-
Error Correcting Codes (ecc): These datasets consist of binary strings that are codewords of classical error–correcting codes. Each pool of strings is generated by sampling random messages and encoding them with the generator matrix of the chosen code family.
-
–
ham: Pool ham- consists of codewords from binary Hamming codes for [19]. Each codeword is obtained by sampling a random message and computing , where is the corresponding generator matrix. The resulting Hamming codewords have fixed lengths and .
- –
-
–
For each dataset, and each combination of parameters and , we sampled three string pools.
The experiments were run on a MacBook M4 Pro with a 12-cores CPU with 48GB of RAM, macOS Tahoe 26.2. All formulations were implemented in Python. We used Gurobi 13 [18] to solve the ILPs.
| instance | pat | mat | hay | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| opt | opt | opt | |||||||||||||
| rnd-5-10 | 0.02 | 0.03 | 0 | 0 | 3/3 | 0.04 | 0.05 | 0 | 0 | 3/3 | 0.20 | 0.34 | 0 | 0 | 3/3 |
| rnd-5-20 | 0.05 | 0.07 | 0 | 0 | 3/3 | 0.10 | 0.11 | 0 | 0 | 3/3 | 1.14 | 1.58 | 0 | 0 | 3/3 |
| rnd-5-30 | 0.12 | 0.14 | 0 | 0 | 3/3 | 0.20 | 0.25 | 0 | 0 | 3/3 | 3.38 | 3.77 | 0 | 0 | 3/3 |
| rnd-5-40 | 0.13 | 0.15 | 0 | 0 | 3/3 | 0.31 | 0.42 | 0 | 0 | 3/3 | 4.34 | 4.72 | 0 | 0 | 3/3 |
| rnd-5-50 | 0.17 | 0.18 | 0 | 0 | 3/3 | 0.55 | 0.67 | 0 | 0 | 3/3 | 6.76 | 7.13 | 0 | 0 | 3/3 |
| rnd-10-10 | 0.25 | 0.26 | 0 | 0 | 3/3 | 1.59 | 1.87 | 0 | 0 | 3/3 | 2.29 | 2.40 | 0 | 0 | 3/3 |
| rnd-10-20 | 0.72 | 0.79 | 0 | 0 | 3/3 | 3.71 | 4.01 | 0 | 0 | 3/3 | 15.12 | 22.19 | 0 | 0 | 3/3 |
| rnd-10-30 | 1.29 | 1.44 | 0 | 0 | 3/3 | 8.84 | 11.02 | 0 | 0 | 3/3 | 74.96 | 91.46 | 0 | 0 | 3/3 |
| rnd-10-40 | 1.83 | 2.05 | 0 | 0 | 3/3 | 23.72 | 39.43 | 0 | 0 | 3/3 | 143.45 | 205.83 | 0 | 0 | 3/3 |
| rnd-10-50 | 2.83 | 3.07 | 0 | 0 | 3/3 | 44.61 | 57.56 | 0 | 0 | 3/3 | 366.24 | tlr | 41.49 | 124.48 | 2/3 |
| rnd-15-10 | 1.52 | 1.95 | 0 | 0 | 3/3 | tlr | tlr | 14.38 | 25.00 | 0/3 | 23.75 | 36.69 | 0 | 0 | 3/3 |
| rnd-15-20 | 3.20 | 3.33 | 0 | 0 | 3/3 | 430.29 | tlr | 16.95 | 27.27 | 1/3 | 126.39 | 164.90 | 0 | 0 | 3/3 |
| rnd-15-30 | 7.07 | 9.36 | 0 | 0 | 3/3 | tlr | tlr | 35.68 | 41.72 | 0/3 | 368.46 | 525.33 | 0 | 0 | 3/3 |
| rnd-15-40 | 20.31 | 30.09 | 0 | 0 | 3/3 | tlr | tlr | 25.92 | 30.76 | 0/3 | tlr | tlr | 68.89 | 127.40 | 0/3 |
| rnd-15-50 | 25.00 | 29.45 | 0 | 0 | 3/3 | tlr | tlr | 34.92 | 46.96 | 0/3 | tlr | tlr | 116.28 | 135.15 | 0/3 |
| rnd-20-10 | 9.95 | 12.05 | 0 | 0 | 3/3 | tlr | tlr | 39.20 | 43.10 | 0/3 | 199.16 | 258.21 | 0 | 0 | 3/3 |
| rnd-20-20 | 77.91 | 91.89 | 0 | 0 | 3/3 | tlr | tlr | 47.30 | 51.38 | 0/3 | tlr | tlr | 32.68 | 34.54 | 0/3 |
| rnd-20-30 | 182.39 | 296.27 | 0 | 0 | 3/3 | tlr | tlr | 49.88 | 55.20 | 0/3 | tlr | tlr | 47.22 | 54.70 | 0/3 |
| rnd-20-40 | 193.82 | 240.44 | 0 | 0 | 3/3 | tlr | tlr | 56.24 | 59.03 | 0/3 | tlr | tlr | 106.50 | 110.91 | 0/3 |
| rnd-20-50 | 233.71 | 318.32 | 0 | 0 | 3/3 | tlr | tlr | 56.56 | 60.00 | 0/3 | tlr | tlr | 112.22 | 116.03 | 0/3 |
For each instance, we reported the runtime (cpu), that is, the time spent by Gurobi to solve the model, with a time limit of seconds. If the solver stopped for time limit, we also recorded the optimality gap (gap) between the best feasible solution (bfs) and the best dual bound (bdb). The gap (in percentage) is computed as In what follows, we use and to denote, respectively, the average and maximum runtime over the three instances of the same pool size; and indicate, respectively, the average and the maximum optimality gap over the same set, and opt reports how many of the three instances were solved to optimality. The acronym tlr indicates that the time limit has been reached.
4.1 Random dataset
Table 1 reports the computational results of the three formulations on the rnd dataset. The data reveal clear differences among the performance of the formulations as the maximum string length and the pool size increase. All in all, pat is consistently the most efficient and scalable model, mat shows moderate performance for small and medium instances but quickly deteriorates as grows, while hay becomes impractical already for moderately large values of and .
For short strings (), all formulations solve every instance to optimality. However, runtime differs substantially: pat remains below seconds even for , mat stays below seconds, whereas hay already requires up to seconds. Increasing the pool size from to affects hay much more severely than the other two formulations.
When the maximum string length allowed increases to , the performance gap between formulations increases significantly. pat still solves all instances in seconds, while mat takes up to seconds for . The hay formulation shows a steep increase in runtime, reaching seconds for and hitting the time limit for , where it solves two instances of three, with a very large gap (124.48%) on the unsolved one.
For , the differences become even more evident. pat continues to solve all instances to optimality, with runtimes up to seconds. In contrast, for mat could only solve one instance (RND-15-20), reaching the time limit in all the remaining cases and showing average gaps between and , with a maximum of on rnd-15-50. The hay formulation performs better than mat for small , solving all instances up to , but reaches the time limit for , with gaps exceeding .
The longest strings tested () clearly illustrate the scalability limits of the formulations. pat remains the only model capable of solving all instances within the time limit, with a runtime of up to seconds. Both mat and hay hit the time limit for every instance with (mat also for ), but the gaps of hay are substantially larger for and : mat shows average gaps around and a maximum of , while hay reaches . Figures 3–4 provide an illustrative overview of the statistics discussed.
4.2 Error Correcting Codes dataset
Table 2 reports the computational results of the three formulations on the ecc dataset. We recall that the ecc instances contain codewords with fixed lengths and strong algebraic structure. This distinction has a clear impact on the behaviour of the formulations. Across all experiments, pat remains the most efficient and reliable model. It solves every instance to optimality, with modest increases in runtime as the pool size grows. For both Hamming and Reed-Muller instances, the runtime remains below seconds for , and the optimality gap is always zero. This confirms that pat scales very well even when the underlying strings come from highly structured code families.
The performance of mat is more subtle. For the smallest Hamming instances (), it solves all cases to optimality, albeit with runtime significantly larger than pat and hay. As the pool size increases, mat reaches the time limit more frequently, especially for Hamming codes with . Nevertheless, even when it cannot close the gap completely, mat often keeps it reasonably small (e.g., for and for , on average, with a peak of ) and provides, in general, meaningful bounds and feasible solutions. A similar pattern appears in the rm dataset: although mat hits the time limit for all pool sizes, the resulting gaps remain relatively stable (between and , with a peak of ), indicating a performance that degrades gradually rather than sharply.
The hay formulation has a different trend. It performs very well for small and medium Hamming instances (), solving them all to optimality in a runtime that remains quite manageable (up to seconds for ). However, its scalability deteriorates for larger pool sizes: for , hay reaches the time limit and returns large optimality gaps (on average, and , peaking at ). In rm, hay again solves all instances up to , but its performance drops for larger pools: it solves two out of three instances for and none for , with non-negligible gaps (although, in this case, smaller on average than mat). A graphical comparison of the mean CPU time and gap is provided in Figure 5.
| instance | pat | mat | hay | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| opt | opt | opt | |||||||||||||
| ham-10 | 1.52 | 1.82 | 0 | 0 | 3/3 | 167.60 | 337.67 | 0 | 0 | 3/3 | 11.78 | 14.09 | 0 | 0 | 3/3 |
| ham-20 | 4.97 | 5.86 | 0 | 0 | 3/3 | tlr | tlr | 5.30 | 9.57 | 0/3 | 72.11 | 85.88 | 0 | 0 | 3/3 |
| ham-30 | 12.83 | 13.74 | 0 | 0 | 3/3 | tlr | tlr | 17.95 | 21.81 | 0/3 | 357.04 | 569.50 | 0 | 0 | 3/3 |
| ham-40 | 20.18 | 21.68 | 0 | 0 | 3/3 | 563.01 | tlr | 6.97 | 14.70 | 1/3 | tlr | tlr | 45.05 | 112.14 | 0/3 |
| ham-50 | 27.87 | 29.01 | 0 | 0 | 3/3 | tlr | tlr | 15.13 | 15.51 | 0/3 | tlr | tlr | 50.57 | 109.63 | 0/3 |
| rm-10 | 3.45 | 4.30 | 0 | 0 | 3/3 | tlr | tlr | 19.24 | 22.80 | 0/3 | 37.10 | 47.79 | 0 | 0 | 3/3 |
| rm-20 | 7.64 | 10.19 | 0 | 0 | 3/3 | tlr | tlr | 19.43 | 21.62 | 0/3 | 85.15 | 118.30 | 0 | 0 | 3/3 |
| rm-30 | 11.68 | 12.10 | 0 | 0 | 3/3 | tlr | tlr | 23.51 | 25.90 | 0/3 | 196.65 | 255.23 | 0 | 0 | 3/3 |
| rm-40 | 20.41 | 26.33 | 0 | 0 | 3/3 | tlr | tlr | 25.25 | 25.75 | 0/3 | 434.79 | tlr | 9.32 | 27.98 | 2/3 |
| rm-50 | 26.77 | 29.41 | 0 | 0 | 3/3 | tlr | tlr | 25.45 | 28.42 | 0/3 | tlr | tlr | 14.17 | 16.60 | 0/3 |
5 Conclusions
In this paper, we consider the Median String Problem under the Levenshtein metric focusing on the case of 0-1 strings. We move from the ILP formulation proposed in [20] (here referred to as hay) and devise two novel ILPs that improve hay in several aspects:
-
The path formulation (pat), which models a sort of network design problem where a graph is modified in order to select a series of paths of minimum cost.
-
The matching formulation (mat), which computes the distance of each input string from the median as a planar matching of minimum cost.
Limiting our attention to 0-1 strings offers the advantage of a simplified set of decision variables. A general improvement is obtained by digitalizing the median string length that, being not known in advance, needs to be treated as a problem decision variable: with respect to this, we also use an upper bound on the median string length that, despite its simplicity, improves the one adopted in [20].
Summarizing the result of our computational experience, pat clearly proves to be the most scalable method in all datasets considered. A comparison between mat and hay reveals an interesting interplay between strength and scalability. Although hay is generally more effective for small and medium instances, mat tends to degrade more smoothly as the pool size increases. Except for some instances (specifically, those in the dataset rm), when mat cannot find an optimal solution it terminates however with moderate gaps, as opposed to hay which shows a sharper deterioration for large pools. Thus, although mat is not the fastest formulation, it remains valuable in challenging settings where hay becomes computationally prohibitive or unstable.
Further benefits could be gained by further reducing the upper bound on the median string length (so reducing the number of -variables in both pat and mat), or by devising valid inequalities and computing effective heuristic solutions for warm start to reduce optimality gaps (especially in mat).
References
- [1] José I Abreu Salas and Juan R Rico-Juan. A new iterative algorithm for computing a quality approximate median of strings based on edit operations. Pattern Recognition Letters, 36:74–80, 2014. doi:10.1016/j.patrec.2013.09.014.
- [2] Claudio Arbib, Andrea D’Ascenzo, Oya E. Karaşan, and Andrea Pizzuti. D-hash/CenterLevenshtein. Software, swhId: swh:1:dir:29a2a7464e7ff0450026b55e399cfb749ef45866 (visited on 2026-06-01). URL: https://github.com/D-hash/CenterLevenshtein, doi:10.4230/artifacts.26233.
- [3] Claudio Arbib, Giovanni Felici, Mara Servilio, and Paolo Ventura. Optimum solution of the closest string problem via rank distance. In Combinatorial Optimization: 4th International Symposium, ISCO 2016, Vietri sul Mare, Italy, May 16-18, 2016, Revised Selected Papers 4, pages 297–307. Springer, 2016. doi:10.1007/978-3-319-45587-7_26.
- [4] Claudio Arbib, Mara Servilio, and Paolo Ventura. An improved integer linear programming formulation for the closest 0-1 string problem. Computers & Operations Research, 80:94–100, 2017. doi:10.1016/J.COR.2016.11.019.
- [5] Arturs Backurs and Piotr Indyk. Edit distance cannot be computed in strongly subquadratic time (unless seth is false). In Proceedings of the forty-seventh annual ACM symposium on Theory of computing, pages 51–58, 2015. doi:10.1145/2746539.2746612.
- [6] Bonnie Berger, Michael S Waterman, and Yun William Yu. Levenshtein distance, sequence comparison and biological database search. IEEE transactions on information theory, 67(6):3287–3294, 2020. doi:10.1109/TIT.2020.2996543.
- [7] Christina Boucher and Mohamed Omar. On the hardness of counting and sampling center strings. IEEE/ACM Transactions on Computational Biology and Bioinformatics, 9(6):1843–1846, 2012. doi:10.1109/TCBB.2012.84.
- [8] Horst Bunke, Xiaoyi Jiang, Karin Abegglen, and Abraham Kandel. On the weighted mean of a pair of strings. Pattern Analysis & Applications, 5:23–30, 2002. doi:10.1007/S100440200003.
- [9] Ramón A Mollinedas Cardenas. A learning model for multiple-prototype classification of strings. In Proceedings of the 17th International Conference on Pattern Recognition, 2004. ICPR 2004., volume 4, pages 420–423 Vol.4, 2004. doi:10.1109/ICPR.2004.1333792.
- [10] Diptarka Chakraborty, Debarati Das, and Robert Krauthgamer. Approximate Trace Reconstruction via Median String (In Average-Case). In Mikołaj Bojańczy and Chandra Chekuri, editors, 41st IARCS Annual Conference on Foundations of Software Technology and Theoretical Computer Science (FSTTCS 2021), volume 213 of Leibniz International Proceedings in Informatics (LIPIcs), pages 11:1–11:23, Dagstuhl, Germany, 2021. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. doi:10.4230/LIPIcs.FSTTCS.2021.11.
- [11] Sei-Wang Chen, ST Tung, Chiung-Yao Fang, Shen Cherng, and Anil K Jain. Extended attributed string matching for shape recognition. Computer Vision and Image Understanding, 70(1):36–50, 1998. doi:10.1006/CVIU.1998.0599.
- [12] Debarati Das and Barna Saha. Approximating LCS and Alignment Distance over Multiple Sequences. In Amit Chakrabarti and Chaitanya Swamy, editors, Approximation, Randomization, and Combinatorial Optimization. Algorithms and Techniques (APPROX/RANDOM 2022), volume 245 of Leibniz International Proceedings in Informatics (LIPIcs), pages 54:1–54:21, Dagstuhl, Germany, 2022. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. doi:10.4230/LIPIcs.APPROX/RANDOM.2022.54.
- [13] Federico Della Croce and Michele Garraffa. The selective fixing algorithm for the closest string problem. Computers & operations research, 41:24–30, 2014. doi:10.1016/J.COR.2013.07.017.
- [14] Liviu P Dinu and Radu Tudor Ionescu. Clustering based on median and closest string via rank distance with applications on dna. Neural Computing and Applications, 24:77–84, 2014. doi:10.1007/S00521-013-1468-X.
- [15] Moti Frances and Ami Litman. On covering problems of codes. Theory of Computing Systems, 30:113–119, 1997. doi:10.1007/S002240000044.
- [16] Arun Ganesh, Tomasz Kociumaka, Andrea Lincoln, and Barna Saha. How compression and approximation affect efficiency in string distance measures. In Proceedings of the 2022 Annual ACM-SIAM Symposium on Discrete Algorithms (SODA), pages 2867–2919. SIAM, 2022. doi:10.1137/1.9781611977073.112.
- [17] Leszek Ga̧sieniec, Jesper Jansson, and Andrzej Lingas. Efficient approximation algorithms for the hamming center problem. In Proceedings of the tenth annual ACM-SIAM symposium on Discrete algorithms, pages 905–906, 1999.
- [18] Gurobi Optimization, LLC. Gurobi Optimizer Reference Manual, 2023. URL: https://www.gurobi.com.
- [19] Richard W Hamming. Error detecting and error correcting codes. The Bell system technical journal, 29(2):147–160, 1950.
- [20] Morihiro Hayashida and Hitoshi Koyano. Finding median and center strings for a probability distribution on a set of strings under levenshtein distance based on integer linear programming. In Biomedical Engineering Systems and Technologies: 9th International Joint Conference, BIOSTEC 2016, Rome, Italy, February 21–23, 2016, Revised Selected Papers 9, pages 108–121. Springer, 2017. doi:10.1007/978-3-319-54717-6_7.
- [21] Gary Hoppenworth, Jason W Bentley, Daniel Gibney, and Sharma V Thankachan. The fine-grained complexity of median and center string problems under edit distance. In 28th Annual European Symposium on Algorithms, ESA 2020, 2020.
- [22] Tao Jiang, Ying Xu, and Michael Q. Zhang. Bio-Sequence Comparison and Applications, pages 45–69. MIT Press, 2002.
- [23] Marcos Kiwi and Martin Loebl. Largest planar matching in random bipartite graphs. Random Structures & Algorithms, 21(2):162–181, 2002. doi:10.1002/rsa.10048.
- [24] Tomohiro Koana, Vincent Froese, and Rolf Niedermeier. The complexity of binary matrix completion under diameter constraints. Journal of Computer and System Sciences, 132:45–67, 2023. doi:10.1016/J.JCSS.2022.10.001.
- [25] Federico Malucelli, Thomas Ottmann, and Daniele Pretolani. Efficient labelling algorithms for the maximum noncrossing matching problem. Discrete Applied Mathematics, 47(2):175–179, 1993. doi:10.1016/0166-218X(93)90090-B.
- [26] Carlos D Martínez-Hinarejos, Alfons Juan, and Francisco Casacuberta. Use of median string for classification. In Proceedings 15th International Conference on Pattern Recognition. ICPR-2000, volume 2, pages 903–906. IEEE, 2000.
- [27] Carlos D Martínez-Hinarejos, Alfons Juan-Císcar, and Francisco Casacuberta. Median strings for k-nearest neighbour classification. Pattern Recognition Letters, 24(1):173–181, 2003. doi:10.1016/S0167-8655(02)00209-X.
- [28] Cláudio N Meneses, Zhaosong Lu, Carlos AS Oliveira, and Panos M Pardalos. Optimal solutions for the closest-string problem via integer programming. INFORMS Journal on Computing, 16(4):419–429, 2004. doi:10.1287/IJOC.1040.0090.
- [29] Pedro Mirabal, José I Abreu Salas, and Diego Seco. Assessing the best edit in perturbation-based iterative refinement algorithms to compute the median string. Pattern Recognition Letters, 120:104–111, 2019. doi:10.1016/j.patrec.2019.02.004.
- [30] David E Muller. Application of boolean algebra to switching circuit design and to error detection. Trans. I R E Prof. Group Electron. Comput., 3(3):6–12, 1954. doi:10.1109/IREPGELC.1954.6499441.
- [31] François Nicolas and Eric Rivals. Hardness results for the center and median string problems under the weighted and unweighted edit distances. Journal of discrete algorithms, 3(2-4):390–415, 2005. doi:10.1016/J.JDA.2004.08.015.
- [32] Irving S Reed. A class of multiple-error-correcting codes and the decoding scheme. Trans. IRE Prof. Group Inf. Theory, 4:38–49, 1954. doi:10.1109/TIT.1954.1057465.
- [33] Robert A Wagner and Michael J Fischer. The string-to-string correction problem. Journal of the ACM (JACM), 21(1):168–173, 1974. doi:10.1145/321796.321811.
- [34] Shirley Xu and David Perkins. A heuristic solution to the closest string problem using wave function collapse techniques. IEEE Access, 10:115869–115883, 2022. doi:10.1109/ACCESS.2022.3218003.
- [35] Shota Yuasa, Zhi-Zhong Chen, Bin Ma, and Lusheng Wang. Designing and implementing algorithms for the closest string problem. Theoretical Computer Science, 786:32–43, 2019. doi:10.1016/J.TCS.2018.05.017.
