Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Genetic algorithm on a knapsack-alike optiproblem

I have a optimzation problem i'm trying to solve using a genetic algorithm. Basically, there is a list of 10 bound real valued variables (-1 <= x <= 1), and I need to maximize some function of that list. The catch is that only up to 4 variables in the list may be != 0 (subset condition).

Mathematically speaking: For some function f: [-1, 1]^10 -> R min f(X) s.t. |{var in X with var != 0}| <= 4

Some background on f: The function is NOT similar to any kind of knapsack objective function like Sum x*weight or anything like that.

What I have tried so far:

Just a basic genetic algorithm over the genome [-1, 1]^10 with 1-point-crossover and some gaussian mutation on the variables. I tried to encode the subset condition in the fitness function by using just the first 4 nonzero (zero as in close enough to 0) values. This approach doesn't work that well and the algorithm is stuck at the 4 first variables and never uses values beyond that. I saw some kind of GA for the 01-knapsack problem where this approach worked well, but apparently this works just with binary variables.

What would you recommend me to try next?

like image 961
dassmann Avatar asked Nov 08 '11 23:11

dassmann


People also ask

Can genetic algorithm (GA) solve knapsack problem?

Previously, we discussed about Genetic Algorithm (GA) and its working and also saw its simple implementation. This time we will solve a classical problem using GA. The problem we will be solving is Knapsack Problem.

What is the knapsack problem?

The knapsack problem is popular in the research field of constrained and combinatorial optimization with the aim of selecting items into the knapsack to attain maximum profit while simultaneously not exceeding the knapsack’s capacity.

Does constrained optimization work for the knapsack problem?

Here, we only discussed the application to one instance of constrained optimization: the knapsack problem. In a simple example, we demonstrated that the SGA solution yields a higher total profit than the greedy approach, where both solutions exhibit the same total weight at the capacity limit.

What are some of the best books on genetic algorithms?

“A Genetic Algorithm Approach for Combinatorial Optimisation Problems,” Ph.D. Thesis, University of London. Chu, P.C. and J.E. Beasley. (1995). “Constraint Handling in Genetic Algorithms: The Set Partitioning Problem,” Imperial College, Working paper.


2 Answers

If your fitness function is quick and dirty to evaluate then it's cheap to increase your total population size.

The problem you are running into is that you're trying to select two completely different things simultaneously. You want to select which 4 genomes you care about, and then what values are optimal.

I see two ways to do this.

  1. You create 210 different "species". Each specie is defined by which 4 of the 10 genomes they are allowed to use. Then you can run a genetic algorithm on each specie separately (either serially, or in parallel within a cluster).

  2. Each organism has only 4 genome values (when creating random offspring choose which genomes at random). When two organisms mate you only cross over with genomes that match. If your pair of organisms contain 3 common genomes then you could randomly pick which of the genome you may prefer as the 4th. You could also, as a heuristic, avoid mating organisms that appear to be too genetically different (i.e. a pair that shares two or fewer genomes may make for a bad offspring).

I hope that gives you some ideas you can work from.

like image 130
Nate Avatar answered Sep 20 '22 04:09

Nate


You could try a "pivot"-style step: choose one of the existing nonzero values to become zero, and replace it by setting one of the existing zero values to become nonzero. (My "pivot" term comes from linear programming, in which a pivot is the basic step in the simplex method).

Simplest case would be to be evenhandedly random in the selection of each of these values; you can choose a random value, or multiple values, for the new nonzero variable. A more local kind of step would be to use a Gaussian step only on the existing nonzero variables, but if one of those variables crosses zero, spawn variations that pivot to one of the zero values. (Note that these are not mutually exclusive, as you can easily add both kinds of steps).

If you have any information about the local behavior of your fitness score, you can try to use that to guide your choice. Just because actual evolution doesn't look at the fitness function, doesn't mean you can't...

like image 44
comingstorm Avatar answered Sep 19 '22 04:09

comingstorm