combinatorics

Which language for rapid-prototyping of heuristics in combinatorial optimization?

I have to develop a fast heuristic-like algorithm for a hard combinatorial problem. Therefore I think, it would be the best to learn a more expressive language than C++ first for tackling the problem, because I think a lot of different algorithm attempts are needed to solve my assignment. Some personal views about some languages which a...

Computing number of permutations of two values, with a restriction on runs

I was thinking about ways to solve this other question about counting the number of values whose digits sum to a target, and decided to try the case where the range was of the form [0, n^base). So essentially you get N independent digits to work with, which is a simpler problem. The number of ways N natural numbers can sum to a target T...

Generate all combinations in SQL

I have a need to generate all combinations of size @k in a given set of size @n. Can someone please review the following SQL and determine first if the following logic is returning the expected results. And secondly, is there a better way? /*CREATE FUNCTION dbo.Factorial ( @x int ) RETURNS int AS BEGIN DECLARE @value int IF ...

Creating restricted permutations of a list of items by category

I am trying to create a number of restricted permutations of a list of items. Each item has a category, and I need to find combinations of items such that each combination does not have multiple items from the same category. To illustrate, here's some sample data: Name | Category ==========|========== 1. Orange | fruit 2. ...

List all k-tuples with entries summing to n, ignoring rotations

Is there an efficient algorithm for finding all sequences of k non-negative integers that sum to n, while avoiding rotations (completely, if possible)? The order matters, but rotations are redundant for the problem I'm working on. For example, with k = 3 and n = 3, I would want to get a list like the following: (3, 0, 0), (2, 1, 0), (2...

Permutation for numbers in C

Hi programming masses, I'm trying to write a C function to list all permutations of a set of numbers, in groups of five, including repeat numbers: 15-11-49-43-5 2-30-34-6-11 So it's easy enough to write a function to grab all permutations of a number set and throw them out, but mapped to a certain group size, i'm somewhat stuck.. T...

Recreate sets from combinations of these sets

hi, I came across a specific problem and looking for some algorithm for it. The problem to solve is as described below. Let's say we have combinations like below 1 - 3 - 5 1 - 4 - 5 1 - 8 - 5 2 - 4 - 5 3 - 4 - 5 2 - 4 - 7 These combinations were generated from given sets, in this particular case let's say from {1},{3,4,8},{5} ...

combination of combination java

I need to find combination of combination in JAVA. I have for instance 6 students in class. Out of them, I need to create combination of 4 people in group, and for each group I can choose an intimate group of 2. I have to make sure that there are no doubles (order does not matter).! and need to print the 4 people group. However, this...

Arrangement of n objects (Permutation with duplicates)

Hi everybody, I am looking for a fast implementation of the "arrangement" algorithm (permutation with duplicates). Given N objects (A in quantity a, B in quantity b, ...), generate all the possible combinations. Exemple: Arrangement("AAA", "B", "CC") would return : "AAABCC" "AABACC" "AABCAC" "AABCCA" "ABAACC" "ABACAC" "ABACCA" "A...

Generating all 5 card poker hands

This problem sounds simple at first glance, but turns out to be a lot more complicated than it seems. It's got me stumped for the moment. There are 52c5 = 2,598,960 ways to choose 5 cards from a 52 card deck. However, since suits are interchangeable in poker, many of these are equivalent - the hand 2H 2C 3H 3S 4D is equivalent to 2D 2S ...

Optimizing a cycle sort implementation

Cycle sort is an in-place sort based on the idea that the permutation you're sorting can be factored into cycles. If you rotate each cycle one position, the array will be sorted. This can easily be coded so that the number of writes to the array is the theoretical minimum needed for any in-place sort (which is nice for huge data sets on,...

Generating Unique Combinations from a list of possible repeated characters

I am looking to generate combinations from a list of elements. Right now i am using a approach of generating power set. For example to generate combinations from {a,b,c}, i will enumerate 001,010,100 ,101 etc...and take the element for which the corresponding binary index is set to 1. But the problem comes when there are repeated charac...

Is this combinatorial optimization problem NP-hard?

I working on a combinatorial optimization problem that I suspect is NP-hard, and a genetic algorithm has been working well with our dataset. We're a research group and plan to publish our results in our field (not in math or CS), and I'd like to explore the NP-hard question before sending the manuscript out for review. There are two ...

partition of integers

A partition of a positive integer n is an non-increasing array of positive integers a[1] , a[2] , ... , a[m] satisfying a[1] + a[2] + ... +a[m] = n. m is called the length of this partition. We can list all the partitions of n in an specified order. For example, if we use the rule by which a lexicography sorts all the English word...

Knapsack with items to consider constraint

I have items I1, I2, I3, I4 with weights W1...W4 and Values V1...V4. I want to maximize values with minimum weights. This is a traditional Knapsack. However there is small constraint some items cannot go together. So lets say I2 and I3 cannot go together. Can anyone provide a dynamic programming solution or any other solution for the sam...

Algorithm to find the possible number of selections

I have been asked this question and have given this quite some thought but was not able to solve it. The question is: I am asked to select n colored Pencils. There are pencils of k different color group. From each color group there are also infinitely many pencils. I want to have at least one pencil of each color group, but still there...

Implementing the Hungarian Method as described by Papadimitriou & Steiglitz

If you've implemented the Hungarian Method exactly as given in Figure 11-2 of Combinatorial Optimization: Algorithms and Complexity, did you succeed without altering the pseudo-code in any [significant] way? To be specific, I'm referring to the corrected 1998 Dover edition, which is up-to-date with respect to the errata file dated Octobe...