{'fraction_non_alphanumeric': 0.026788419093781105, 'fraction_numerical': 0.00558272384991561, 'mean_word_length': 4.471939379587971, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Discovering Locally Maximal Bipartite Subgraphs

Induced bipartite subgraphs of maximal vertex cardinality are an essential concept for the analysis of graphs. Yet, discovering them in large graphs is known to be computationally hard. Therefore, we consider in this work a weaker notion of this problem, where we discard the maximality constraint in favor of inclusion maximality. Thus, we aim to discover locally maximal bipartite subgraphs. For this, we present three heuristic approaches to extract such subgraphs and compare their results to the solutions of the global problem. For the latter, we employ the algorithmic strength of fast SAT-solvers. Our three proposed heuristics are based on a greedy strategy, a simulated annealing approach, and a genetic algorithm, respectively. We evaluate all four algorithms with respect to their time requirement and the vertex cardinality of the discovered bipartite subgraphs on several benchmark datasets


Introduction
Graphs are used in a variety of sciences to model and to analyze complex relationships. In this context, the search for interesting and relevant substructures is a standard procedure. So-called bipartite graphs represent a particularly interesting substructure, since they allow a multitude of further mathematically intrinsic as well as scientifically extrinsic interpretations, e.g., communities in social networks or codewords in coding theory. Yet, discovering the largest bipartite subgraph of a graph is a problem that is known to be of high computational complexity. Formally, the problem that relates to our work can be stated as follows: For a graph G = (V, E), what is a subset of vertices X ⊆ V such that the graph G(X, E ∩ (X × X)) is bipartite and the size of X is maximal? From a result by Lewis and Yannakakis [8] follows that deciding for G whether such a set of cardinality k exists is an NP-complete task. While the computational complexity of this problem is well-investigated, it is not yet explored how to efficiently discover large, yet not maximal, induced bipartite subgraphs of a given graph.
The present work investigates a related problem where the global maximality condition of the computed subgraph is replaced with inclusion-maximality of the vertex set. In this setting, we optimize on the order of the computed subgraph, i.e., we maximize the number of its vertices. In order to make our algorithms suitable for real-world data, we limit ourselves to designs that are executable in polynomial time in the size of the data.
As a benchmark, we recollect an exact solution of the bipartite subgraph problem which we proposed in Dürrschnabel et al. [4]. This solution shows a principal way how a corresponding SAT problem can be formulated and subsequently solved using a high-performance SAT-solver. We then present three polynomial-time heuristics to compute locally maximal solutions. All three have different runtime-performance trade-offs which we point out. In detail, we evaluate all four algorithms against each other on common benchmark graph datasets and compare their runtime and the qualities of the results, i.e., the cardinality of the computed induced bipartite subgraphs. Our results show that the greedy heuristic has the best runtime, while the genetic algorithm performs best with respect to the order of the computed bipartite subgraph. Finally, the employed simulated annealing algorithm balances runtime and performance.
We investigate this task because of our previous work [4] in the realm of order diagram drawing. In this, the proposed solution requires the computation of a large inclusion-maximal bipartite subgraph in the so-called transitive incompatibility graph of the ordered set. Other possible fields are datasets that are by their nature bipartite such as author-to-publication networks but are extracted from non-bipartite relations and thus have noise that makes them non-bipartite. Also in the realm of system biology and medicine, bipartite graphs are of interest [10] and these areas could thus profit from our work. Furthermore, the approach could be used to discover hidden two-mode networks in graph data.

Globally Maximal Bipartite Subgraphs
In this work, we refer to graphs of order n as tuples G = (V, E) with |V | = n and E ⊆ (V ×V ) with vertex set V and edge set E. For a subset of the vertices X ⊆ V the graph (X, E ∩ (X × X)) is called an induced subgraph of G and denoted by G[X]. In this work we always refer to induced subgraphs when we say subgraph. A graph is called bipartite, if its vertices can be partitioned into two sets A and A well-known property of graphs is that they are bipartite if and only if they contain no cycles of odd length. For a natural number n we denote the set {i ∈ N | 1 ≤ i ≤ n} by [n]. We only consider finite graphs, i.e., graphs of order n < ∞.
Even though we are interested in bipartite subgraphs of maximal order, we use the equivalent dual formulation from here on. For a graph G = (V, E), we want to find a minimal set of vertices D such that the graph G[V \ D] is bipartite. This is, as D can be interpreted as erroneous data that makes the graph non-bipartite.
In this section we repeat and expand on an approach that we already briefly suggested in [4], to approaches the global problem formulation, i.e., the problem: Because of the focus of this work, we are able to properly evaluate this approach against the later proposed heuristics. Checking for a graph if it is bipartite can be done in polynomial time by doing a breath-first search and coloring the vertices in alternating colors conditional on their distance to the starting vertex. Either the graph is bipartite, and the two color classes will result in a valid bipartition or the algorithm will try to assign some vertex to both color classes. A naive approach could thus check for all subset of vertices, whether their deletion makes the graph bipartite. However, even for small examples, i.e., graphs with few vertices, this is infeasible as checking all subset of cardinality k of a graph of order n will result in n k such tests. For a more sophisticated approach to the problem, we reduce it to an instance of the Boolean satisfiability problem which we can then solve with a SAT-Solver, in our case MiniSat [5] in version 2.2. To be exact, we want to know for a graph G = (V, E) on n vertices and m edges whether by deleting k vertices we can make the graph bipartite. Solving is done by finding a partition of V into the three sets A, B, D, such that A and B are independent sets and |D| ≤ k. For the at-most-k condition, we make use of the variables and clauses introduced by Sinz [11]. Altogether, our SAT instance has (n − 1)(k + 3) + 3 variables and 2m + 2nk + 2n − 3k − 1 clauses. For this CNF the following holds. Proposition 1. The CNF from Definition 1 of a graph G = (V, E) has a valid assignment, iff the graph can be made bipartite by deleting k vertices. Then, for Proof. Let the conjugative normal form have a valid assignment. Then the set D has cardinality at most k by construction. Note, that every vertex that is not in D has to be in exactly one of A or B because of their definition and condition (i) of the conjugative normal form. Assume A and B are not bipartition classes of G[V \ D]. Then there have to be two vertices in either A or B that are connected by an edge, without loss of generality A. But this is a contradiction to the definition of A and condition (ii) of the conjugative normal form. Assume now on the other hand, that there is a setD of cardinality at most k, such that G[V \ D] is bipartite. Call the bipartition setsÃ andB. But then the variable assignment Now we can build this SAT instance for each k increasing from 1 until we achieve satisfiable instance. Then, the set {v i | V i,3 = T } is exactly the subset of

Algorithm 1 Greedy Algorithm
random−e l e m e n t (N ).add ( u ) return A, B, D vertices we have to remove to make the graph bipartite. As a speed-up technique we apply a binary search where at the beginning k is doubled in each step until an initial solution is found. Then, in each step the mean value of the known upper and lower bounds is checked until the exact solution is found.

Heuristics for the Local Problem
In this section we now deal with the local version of the problem. Formally: , what is a set of vertices D ⊆ V such that the graph G[V \D] is bipartite and there is no setD D with the same property.
Compared to Problem 1, this problem does not search for a set D of global minimality and restricts it to only inclusion-minimality.

Greedy
Our greedy algorithm is formalized in Algorithm 1, which reflects the main routine greedy and the subroutine greedy-fill. The subroutine has to be called with the vertex set V partitioned into A, B, and D. It is required that neither A nor B contain two vertices connected by an edge. The algorithm checks for all vertices u in D in a random order, whether they already have a neighbor in one of the bipartition classes A or B. Then, N contains the classes to which u can be added based on the previous assignments. If N is empty, it can't be added to any bipartition class and is therefore stays in D, otherwise one of the classes in N is selected at random. To avoid ambiguity, if N only contains the empty set we add u to A. Thus, the routine moves elements from D to A and B, until all elements in D are connected with an edge to some element in A and in B.
To compute an inclusion-minimal set D, such that the induced graph on V \ D is bipartite, we can now call this subroutine with V as D and empty sets

Algorithm 2 Simulated Annealing
def s i m u l a t e d −a n n e a l i n g (V, E, imax) : for A and B. The algorithm then computes D and the bipartition classes A and B of the resulting graph. By this design, we can rely on this subroutine for the heuristics later proposed in this work.

Simulated Annealing
Simulated annealing algorithms are motivated by the physical process of annealing metal which involves controlled cooling in order to achieve better physical properties. Classical hill-climbing algorithms generate a starting solution which is then improved iteratively by choosing neighboring solutions of better quality. By design, these algorithms often terminate in a minimum which is only local. The simulated annealing approach tries to overcome this issue by accepting to worsen the current solution using a probability function which thus allows the algorithm to leave local minima. At the beginning, the algorithm accepts worse solutions with a high probability and then decreases this probability iteratively towards zero based on a cooling function. Thus, in the last iterations, the algorithm behaves similar to a hill-climbing version.
Our version of the simulated approach in Algorithm 2 is initialized with a maximal number of iterations i max , a starting temperature t max and a cooling function which maps to a range from 0 to t max . The initial solution is generated using the greedy algorithm. In each iteration, a neighboring solution is chosen by selecting a random vertex u from D and removing all vertices that are connected by an edge to u from the bipartition classes A and B. Then, u can be added to A or B, from which one is chosen at random. Finally, the greedy-fill routine is used to ensure that the set D is minimal. Note, that using a cooling function that maps every value to zero results in a hill-climbing algorithm.

Genetic Algorithm
Finally, we propose an adaptation of a genetic algorithm which is motivated by the evolutionary process of reproduction. For this a set of starting individuals is chosen. The ones, with the highest fitness, with respect to the optimization task, are allowed to reproduce to generate a new generation of individuals. Furthermore, mutations can be introduced to avoid local minima. This process is repeated, until a good solution is found. In our version of this approach, which is formalized in Algorithm 3, we provide a maximal number of generations g max , a number of individuals i max that exist in each generation and a mutation probability p mut . At the beginning we initialize i max starting individuals using the greedy algorithm from Section 3.1.
In each iteration of the loop, a new generation next_gen of individuals is generated which replaces the current set of individuals cur_gen with a new one. For this, a probability distribution based on the fitness of the current generation is computed. We choose the probability distribution such that the probability is linear with respect to the cardinality of D and that the element with the smallest cardinality D has ten times the probability of the one with the largest cardinality D. The elements of next_gen are generated by choosing two distinct elements for each based on the probability distribution and breeding them to a new individual. This is done by using the breed function which first computes the set D n as the union of both D-sets from the chosen individuals. Because bipartiteness is a hereditary property and D n is a superset of the D-sets, the graph G[V \ D n ] is also bipartite. Finally, the new individual is generated using the routine greedy-fill to ensure that the resulting D is inclusion-minimal. Alternatively, with probability p mut , a mutation is introduced using the neighborhood choosing from the simulated annealing algorithm.

Evaluation and Discussion
In this section we discuss and compare the different approaches proposed in this work with respect to their runtime and the quality of their results.

Datasets and Implementation
We test our algorithm on four different datasets. The DAGmar 3 generator can produce random leveled graphs for given vertex numbers and densities. We use the graphs bundled with the DAGmar generator as our first testing dataset. Those have between 20 and 400 vertices and an edge-vertex ratio between 1.6 and 10.6. We refer to this dataset as DAGmar. The Rome and North (AT&T) graphs 4 are two datasets that are well-known benchmark graphs amd are commonly applied by the graph drawing community. The Random class contains randomly generated graphs on vertices between 10 and 500 vertices. The edge-vertex ratio was chosen, such that it is between 1 and 10.
All of our experiments are implemented in Python 3, for the SAT-solver we used the binaries provided on the MiniSat website 5 . The experiments are conducted on an Intel Xeon Gold 5122 CPU equipped with 300 GB RAM. For reproducibility and further research, our source code is public. 6

Parameter Tuning
Our simulated annealing approach and our genetic algorithm require parameters which we have to chosen carefully. We provide recommendations based on 19.91 Fig. 1: Average results for different mutation probabilities.
extensive optimizations. Due to space constraints, we are only able to describe those partially in this section.

Simulated Annealing
The simulated annealing algorithm has three parameters that to optimize. For the starting temperature we observe that the average cardinality of D for all graphs in the test sets decreases until a temperature of around 45. Thus, we recommend using a starting temperature of 50. To decide, on the cooling function we provide the average result of the tests on four different cooling functions in Table 1. The results suggest, that the quadratic cooling function should be plugged. Finally, the number of iterations that algorithm runs for can be optimized. Our observations suggest that the improvements after more than 10000 iterations are marginal, and we thus recommend this parameter.
Genetic The genetic algorithm has three parameters. As a general rule, we observe that increasing the number of individuals or the number of generations improves the result. We are not able to observe a maximum number of individuals or generations, beyond which the cardinality of D does not become smaller, we thus cap our algorithm at 20 individuals and 1000 generations. For the mutation probability, Figure 1 suggests that a mutation rate of 1 provides the best results. We also experimented with survivors between generations, however, we observed that those increases the size of D.

Evaluation
We first consider the theoretical runtime of the different algorithms. Even though the transformation to the SAT instance is polynomial, the SAT-solver has by its nature an exponential runtime. The greedy algorithm has to process every edge once and is thus linear in the number of edges of the graph. In the worst case, the simulated annealing algorithm does a full procession of the greedy algorithm in each repetition and has thus a runtime of O(m · i max ). Finally, the runtime of the genetic algorithm is in O(m · g max · i max ), as in every repetition of the loop the greedy algorithm is called for each individual.  For the experiment-based evaluation, we choose our parameters as described in the last section. We fist consider the experimental runtime. Each graph is processed in our test-datasets with each algorithm once. If the SAT-algorithm ran longer than one hour, we canceled its computation. For the DAGmar graph class, only the computation of 304 from 1960 graphs finished in this time, for the random class it was 89 of 403. In Tables 2 and 3 we compare the average runtime and size D of the different algorithms split by graph class. If we compare the heuristics, it is as expected by the theoretical runtime investigation: The greedy algorithm is the fastest one and the genetic algorithm is the slowest with the simulated annealing algorithm being in the middle. When we consider the size of D, it is the other way round: The best results are achieved by the genetic algorithm and the worst ones by the greedy algorithm on all test datasets. The SAT algorithm is, by its nature of being an exact algorithm, always the one with the smallest set D. A more visual representation of the time requirement is provided in the plot of Figure 3. Here each graph in each graph class is represented by a dot which is placed on a logarithmic scale in the y-axis, depending  on the time its computation needs for each algorithm. In Figure 3 we plot for all graph classes and algorithms, how many graphs had a computed set D that is larger than k. To provide comparability, the graphs that did not finish in the SAT-experiment are excluded from this plot. Once again, we can observe that the greedy algorithm performs worst, while the simulated annealing and genetic algorithm come very close to the SAT-algorithm which, by its nature of being an exact algorithm, is always the lowest curve in all four plots.

Discussion
We propose four different algorithms in this work. Each of these algorithms has its merits, as they balance runtime against cardinality of D in different ways. An exact result is usually preferred, however we observe that the exact SAT-algorithm does not finish in under an hour for medium-sized and larger graphs. Because of the exponential nature of SAT-solving, one should thus not expect to always find a solution in a reasonable time. On the other hand, the greedy algorithm has a runtime which is linear in the number of edges of the graph and can thus usually be computed even on large graphs. The order of the computed bipartite subgraphs are not too unreasonable when compared to the exact solution of the SAT algorithm. Finally, the simulated annealing and greedy algorithm are in the middle of the other two approaches in both regards, runtime and quality. The simulated annealing approach is a bit faster but delivers worse results. However, it should be noted that both of them are very close to the exact solutions. For a general recommendation, one should usually make use of the algorithm with the highest runtime one can afford.

Related Work
Bipartiteness of graphs is a so-called hereditary property, i.e., every subgraph of a bipartite graph is once again bipartite. Lewis and Yannakakis [8] show in their work from 1980 that for any hereditary property P , it is NP-complete to decide, whether a graph G can be made to satisfy P by deleting k vertices. Even approximations are known to be in the same complexity class [9].
Cohen et al. [2] provide an algorithm to compute all maximal induced subgraphs with a desired hereditary property and Trukhanov et al. [13] give a framework on how to design an algorithm to find maximum vertex subset [13] with given hereditary property. Because of the complexity of the underlying decision problem, both approaches result in exponential algorithms.
A closely related problem is the edge-deletion problem. Here, instead of vertices, a set of edges is requested that makes the graph bipartite if it is deleted. Similarly to the vertex-deletion problem, deciding on the number of edges that have to be deleted is NP-complete [15].
Another well-investigated problem about subgraphs with a hereditary property is the clique-problem. For a given graph, the largest fully-connected subgraph is sought-after. Its NP-completeness was first proven by Karp in 1972 [6]. To tackle this problem, there are exact algorithms [1] as well as heuristics [14].
Deciding if an instance of the Boolean satisfiability problem is solvable is another NP-complete [3] task. So-called SAT-solvers such as MiniSat [5] try to investigate instances of this problem and, if the instance is solvable, try to provide valid variable assignments in reasonable time. In this work, we recapped our previous approach [4] which makes use of this by deducing the largest bipartite induced subgraph of a graph from the assignment computed by a SAT-solver for an instance of the problem.
Furthermore, we proposed three heuristics that compute locally maximal subgraphs: a greedy algorithm, a simulated annealing algorithm and a genetic algorithm. Simulated annealing and genetic algorithms are well-established tools in algorithm engineering. We refer the reader to surveys [12,7] to get an overview on the variations of both approaches.

Conclusion
In this work we proposed three algorithms to compute locally maximal induced bipartite subgraphs of large order. To this end, we employed an exact solution using a SAT-solver and three different heuristic approaches with a greedy strategy, a simulated annealing approach and a genetic algorithm. Furthermore, we compared the results on four benchmark datasets and demonstrated in an experimental evaluation that all three heuristics have a reason to exist by balancing the time-consumption and the order of the computed subgraph to different degrees.
A notable observation is, that the simulated annealing approach and the genetic heuristics could, by their design, work on any hereditary graph property. For this, only the greedy heuristic and the neighbor-choosing have to be adjusted. This raises the question, whether the approach generalizes to other properties of graphs that are hereditary. To confirm that these approaches work on other classes, further studies are necessary and are a natural future extension to this work. As we published our code, such experiments can easily be conducted.