## How to impletement a multi-objective optimization in Optaplanner? - optaplanner

I want to implement a multi-objective optimization with Optaplanner, and I have read the "Pareto Scoring" chapter in the document. I understood the principle of multi-objective planning in optaplanner, but don't actually know how to implement it, there are bellow queries:
How to design a custom score definition class, which class it should extend from, and what filed it should have basically?
As a multi-objective planning, I have to provide multiple solutions to the user. But the best solution is only one, how can I keep more than one solutions while planning? Does it mean, in the bestScoreChange event, I have to calculate the scores, find and keep the best solutions for each objective?

If you really just have 2 goals, you can also fake it through running the Solver twice with different score levels in the #ConstraintWeights in the #ConstraintConfiguration class.
Real pareto solving is much more complex and requires adjustments to the BestScolutionRecaller, which is just the tip of the iceberg.

## Related

### Implementing crossover in genetic programming [closed]

I'm writing a genetic programming (GP) system (in C but that's a minor detail). I've read a lot of the literature (Koza, Poli, Langdon, Banzhaf, Brameier, et al) but there are some implementation details I've never seen explained. For example: I'm using a steady state population rather than a generational approach, primarily to use all of the computer's memory rather than reserve half for the interim population. Q1. In GP, as opposed to GA, when you perform crossover you select two parents but do you create one child or two, or is that a free choice you have? Q2. In steady state GP, as opposed to a generational system, what members of the population do the children created by crossover replace? This is what I haven't seen discussed. Is it the two parents, or is it two other, randomly-selected members? I can understand if it's the latter, and that you might use negative tournament selection to choose members to replace, but would that not create premature convergence? (After a crossover event the population contains the two original parents plus two children of those parents, and two other random members get removed. Elitism is inherent.) Q3. Is there a Web forum or mailing list focused on GP? Oddly I haven't found one. Yahoo's GP group is used almost exclusively for announcements, the Poli/Langdon Field Guide forum is almost silent, and GP discussions on general/game programming sites like gamedev.net are very basic. Thanks for any help you can provide!

Firstly, relax. There are no "correct" methods in GP. GP is more art than science. Try lots of schemes and pick the ones that work best. Q1: 1, 2, or many. You choose. Q2: Replace, 1, 2, all. Or try some elitism. Q3: You probably won't find forums discussing these questions b/c there are no right/best answers. Sorry. PS. In my research, crossover never really performed well...

If you can read Python, you may want to take a look at Pyevolve. I am mainly involved in it on the GA side, but it has support for GP as well. May be you can get some hint there.

Q1 is your choice, but single child would probably be more common. Every time you do the lottery selection of parents, you're applying selection pressure, which is what you want. Q2: Negative tournament selection is exactly the right approach. Yes, losing low-fitness members of the population causes rapid convergence initially, but once your population gets into the hard-to-search part of the solution space, it won't be as cut-and-dried which ones lose the tournament / lottery. What you do have to beware of is stagnation of the gene pool; I suggest monitoring the entropy of the genome to track its heterogeneity. "elitism is inherent" -- Well, yeah, that's the point! ;-) Q3: comp.ai.genetic is probably your best bet. Sometimes the topic is picked up in game development fora, like on Gamasutra. P.S. Genetic programming in C?!? How are you assuring the viability of the offspring? Doing genetic programming in a non-homoiconic language is a real challenge.

Check out MetaOptimize.com for your stacky needs.

As Ray, says, it's mostly up to you but typically in a steady-state setup you would only create a single offspring. Again you have options. I wouldn't replace the parents. If they've been picked as parents based on their fitness you could be eliminating some of the fittest members of the population. Easiest is just to randomly pick an individual to be replaced. Alternatively, you could replace the least fit individual, but that can lead to premature convergence. Another option is to use the same selection strategy that you use to choose parents but use the inverse fitness so that it favours less fit individuals. You could try comp.ai.genetic on USENET (and Google Groups).

It sounds like some of your questions are not necessarily specific to genetic programming; if that's true, you might have some luck asking the folks over at the NEAT Users Group. They primarily discuss the Neuroevolution of Augmenting Topologies (or NEAT) algorithm, which is a genetic algorithm used to evolve neural networks. But topics like elitism and crossover strategies are pretty general, and can apply to both GA and GP algorithms. Otherwise, as Dan and Ray have said, a lot of these decisions are made after experimentation with one's particular software and domain. Try applying your algorithm to different problems and pay attention to how it behaves -- after a while, you'll probably develop an intuition for what works and what doesn't.

I would create an unlimited number of offspring, but only on the basis of success, and let older members of the population die. Lack of fitness can also lead to early death. This just seems to follow a natural order.

Q1. In GP, as opposed to GA, when you perform crossover you select two parents but do you create one child or two, or is that a free choice you have? Yes its your choice; but generally, its not advisable to create many individuals with the same parents, because the difference among the individual's trends created by the same parents would be very limited and that could cost processing speed and memory which could have been spent on other individuals showing different trends and behaviors that requires analysis (but creating more individuals cannot be a problem if the evolution process is close to reaching its endpoint). Q2. In steady state GP... It is advisable to replace individuals based on the ranking provided by the fitness function you have adopted.

### Get best 3 scores in Optaplanner?

Can we get top 3 best scores using constraints in Optaplanner? For eg i have a use case where i need to show top 3 results which has highest score to user so that user can select the solution according to their need.

Sounds like pareto optimization (see docs). Not yet supported in OptaPlanner officially. But users have hacked it before, by implementing their own BestSolutionRecaller (= that class that holds the best solution(s)) and replacing the DefaultSolver's bestSolutionRecaller with it. This implies "taking the red pill" and "following the rabbit hole down to wonderland". Good luck :) Important note: Pareto optimization goes much further than just remember the n best solutions. It's about remember the n best solutions which aren't dominated by one of the other best solutions. So it entails changing the score comparison (and breaking the transitive aspect of score comparison).

### Multi-objective optimization method needed

EDIT: In lieu of other suggestions, I've decided to play around with the Python DEAP framework until I come up with something usable. Hopefully this helps people with a similar problem. I am implementing a system in which we need to do multi-objective optimization for a client, as follows: A manufacturing system has to produce N parts (of the same kind) by welding. For this, a certain material can be chosen, a welding method, and the number of welding points to use for building each part. The image below shows the parameters of the problem and their interdependencies: I can play with values for material welding method number of spot welding points I need to find the combination of material, welding method and number of welding points/part that minimizes the cost and maximizes the stability. I was thinking of using an evolutionary algorithm approach. However, my background is not in optimization, so, if someone could suggest a more specific algorithm that's suited for this problem, it would be really helpful.

Assuming that you have a cost function for 'cost' and 'stability' you can use a traditional multi-objective EA like NSGa-II, SPEA-2 and maybe PAES. Obviously, the choice of the algorithm is strongly dependent on the number of samples do you have, on the features of cost functions and other important characteristics. You can check on journals like Applied Soft Computing for similar applications.

Try SMS-EMOA: http://ls11-www.cs.uni-dortmund.de/people/beume/publications/BNR08_at.pdf The paper shows that it is kind of an improvement of NSGA-II

Old post, I realize, but for the sake of anyone with a similar situation... Although using an EA is one approach, this problem strikes me as particularly well-suited for Mixed Integer Programming. EA's can be great, but are not guaranteed to reach an optimal solution. MIP, on the other hand, can reach the optimal solution (and prove that it's optimal). Additionally, multiple objectives can be quite easy to implement. I'd recommend checking out Gurobi (https://www.gurobi.com/). They've done a great job of making MIP as accessible as possible, and have a lot of documentation and examples on their website to get started. It's a bit of a learning curve at first, but you'll soon see opportunities to use MIP everywhere you look, so I think the time investment pays off. I believe there is a trial license, too.

### Getting started with Finite Elements methods

There is a cubic block of fractured rock; the question is: how to simulate fluid flow from top-side to down-side or left-side to right-side? Is FEA (FEM,...) the only practical solution? If so for the question above in its simplest conditions, that is, flow can happen only through fractures; no interaction between matrix and the fluid; etc etc how to have a quick simulation with FEA? Is this practical someone with professionality in FEA could do this in a few minutes? Suppose there is already a suitable mesh generated. If not what would you recommend to get started rapidly to be able to solve such simple cases? Is there anybody having experience with similar problem (flow modeling); if so what did you use and how did you fulfilled the job? Note that we are aware of availability of many FEM packages e.g., FEniCS, OpenFoam, ....

There are a number of numerical techniques that could be used to solve this problem, finite elements being probably the most common. If you have a mesh of the fluid flow domain already (presumably the voids/cracks in the rock) it would be very straightforward to set up and run the flow model with pretty much any CFD package (finite element based or not) and most people with any exposure to FEA should be able to do it. I am assuming that you want to understand the fluid flow within the rock in some detail, rather than just evaluate the effects of the rock on the flow in some larger flow domain. In the latter case, there are other approaches which might be more computationally efficient.

Your question refers to simulation of the fluid in the porous medium, e.g. the rock. I highly recommend using LBM instead of FEM-based methods. LBM simulates the flow in porous media by nature. Phys Review E contains publications about that approach. What is even more attractive, LBM can be also easily parallelized on GPU.

You could use the one-dimensional form of Darcy's Law.

### Optimal optimization order

I am working on a system of optimisation problems. These tasks can be solved by a generic optimization accross all the state space. But some of my equations are independent of the remaining system( imagine a Jacobian Matrix with some blocks full of zero ) and i would like to use this fact to optimize first the joint equations and then taking the previous solution as an input finish to solve the independent components. The rules that say the relation between the tasks can be represented as an oriented graph, but this graph contains cycle because of the joint equations, which mean that i can't use a topological sort on it. Does anyone have an idea of how to solve this kind of pb? Thx

There are a couple of types of frameworks you can look into (instead of inventing it yourself), which might solve your problem. The question is a bit to abstract to tell which one suits your needs, so take a look at these: Use a solver framework to solve this optimization and look through the search space of. Take a look at Drools Planner, Gurobi, JGap, OpenTS, ... Use a rules engine to apply the optimization changes. Take a look at Drools Expert, JESS, ...