/weakSchurParallel

Project to write parallel algorithms to compute weak schur numbers and weakly sum-free partitions

Primary LanguageJupyter Notebook

Parallel Algorithms for Weak-Schur Numbers

This repo aims to provide code using simulated annealing (and potentially other genetic algorithms) to compute weakly sum-free partitions, over multiple processes and in parallel. The upshot is that there are also reasonably fast functions which verify partitions and compute the fitness score of a given potential partition, which are completely implemented in numpy for speed.

The proposal for the algorithm, and its motivations, have been detailed in Algorithm Proposal.

WeakSchur contains the explanation for the main code in greater detail.

verify_partition and fitness

Both algorithms are based on the same method of generating all unique pairs of numbers in a given color partition; the idea is to generate a meshgrid of all possible pairs, and then get the (strictly) upper triangular part of the returned matrices of meshgrid: say xx and yy. The performance of this implementation of verify_partition is as follows.

Performance

In each case, the X-axis represents the total number of iterations used by timeit, and the time is in seconds. As expected, the total time taken is linear in the number of iterations, but time taken per iteration remains fairly constant.

fitness simply counts the number of pairs a,b,c such that they violate the sum-free property of the partition i.e. a+b=c for distinct a,b,c. Since the code isn't too different, the performance is not expected to be very different either. The specific times (in seconds) are in the following table.

10 100 500 1000 2500 5000
0.00002689999999994086 0.00018969999999995935 0.0010127999999998138 0.0019521000000000122 0.00863309999999995 0.007054699999999858

algorithm

The idea of this algorithm is to be simple, and parallellizable. The steps are as follows:

  • Step 1 Get the number to add for the current iteration
  • Step 2 Sequentially add it to each subset in the partition, and evaluate the fitness
  • Step 3 Choose the solution that has the minimum fitness, or according to a choice algorithm like SimulatedAnnealing.