subset_sum, a Fortran77 code which seeks solutions of the subset sum problem, in which it is desired to find a subset of integers which has a given sum.
This function works by brute force, that is, it tries every possible subset to see if it sums to the desired value.
Given N weights, every possible selection can be described by one of the N-digit binary numbers from 0 to 2^N-1.
This function includes a range, which allows the user to control which subsets are to be checked. Thus, if there are N weights, specifying a range of [ 0, 2^N-1] indicates that all subsets should be checked. On the other hand, this full range could be broken down into smaller subranges, each of which could be checked independently.
It is possible that, in the given range, there may be multiple solutions of the problem. This function will only return one such solution, if found. However, the function may be called again, with an appropriate restriction of the range, to continue the search for other solutions.
The information on this web page is distributed under the MIT license.
subset_sum is available in a C version and a C++ version and a Fortran90 version and a MATLAB version and an Octave version and a Python version.
change_making, a Fortran77 library which considers the change making problem, in which a given sum is to be formed using coins of various denominations.
combination_lock, a Fortran77 program which simulates the process of determining the secret combination of a lock.
combo, a Fortran77 library which includes many combinatorial routines.
knapsack, a Fortran77 library which solves a variety of knapsack problems.
knapsack_01, a Fortran77 library which uses brute force to solve small versions of the 0/1 knapsack problem;
LAMP, a Fortran77 library which solves linear assignment and matching problems.
PARTITION_PROBLEM, a Fortran77 library which seeks solutions of the partition problem, splitting a set of integers into two subsets with equal sum.
SATISFY, a Fortran77 program which demonstrates, for a particular circuit, an exhaustive search for solutions of the circuit satisfiability problem.
subset_sum_brute, a Fortran77 code which uses brute force to solve the subset sum problem, to find a subset of a set of integers which has a given sum.
tsp_brute, a Fortran77 program which reads a file of city-to-city distances and solves the traveling salesperson problem, using brute force.
You can go up one level to the Fortran77 source codes.