Harry Haller
2013-07-31
Hi,
i´m trying to implement a hybrid algorithm for the facility layout problem in java. The basic idea is, that a genetic algorithm is hybridised with a CP that should handle hard constraints like non-overlapping. To handle the non-overlapping constraint i use the diff2 constraint in jacop.
The CP gets information about fixed facilities and for for other facilities proposed points (x/y-coordinates) to place them. So this facilities should be placed as near as possible to this proposed points. First i tried to implement this with a cost function (distance between IntVar and the proposed point), but this was very time consuming. Because of that my question is, if it´s possible to write an own class that implements the Indomain interface and selects the value which is the closest to the proposed one in the current domain.
I hope my explanations are not to confusing.
Thank you very much for any help in advance.
kris
2013-08-01
Hi!
You may try IndomainList (http://jacopapi.osolpro.com/JaCoP/search/IndomainList.html).
/Kris
Harry Haller
2013-08-01
Hi Kris,
thanks for your answer. I think this could work. If i get it right, i would have to create an IndomainList object for each variable and "add" them to an IndomainHierarchical object, if i want the order to be different for each of the variables?
Harry
kris
2013-08-01
Hi Harry,
It works for all variables using the same order. If you need different order for different variables you need to implement your own indomain.
/Kris
Radoslaw Szymanek
2013-08-01
Hi Harry,
You are correct, you could use IndomainHierarchical to specify different indomains for different variables.
https://sourceforge.net/p/jacop-solver/code/131/tree/trunk/JaCoP/search/IndomainHierarchical.java
You could use within IndomainHierarchical, an IndomainList to really have a lot of control how you do the indomain.
Please keep in mind that you could implement your own indomain that can do very complex computation and check values for all other variables. It may be easier solution then trying to fit your desired indomain into Hierarchical and a List one. Your indomain object can pretend to be a constraint and when you impose it then it will be getting all information about propagations of other variables. It may even implement Search listeners and be aware of how you were doing search up to the current search node.
best regards,
Radek
Harry Haller
2013-08-01
Hi Radek,
thank you for your answer. I implemented my own indomain, at the moment it´s a very simple one. Unfortunately i´m no expert neither in CP nor in jacop. But if i find the time, i will have a closer look to some of your suggestions.
Harry
Harry Haller
2013-08-01
Hi Kris,
my solution would be to change the parameter "int[]order" in to a hashmap which contains the array of orders for each variable. That should work i think.
public class IndomainHashList<T extends IntVar> implements Indomain<T> { private Indomain<T> defIndomain; private HashMap<T, int[]> hashmap; public IndomainHashList(HashMap<T, int[]> hashmap, Indomain<T> defIndomain) { this.hashmap = hashmap; this.defIndomain = defIndomain; } public int indomain(T var) throws RuntimeException { int[] order; if (this.hashmap.containsKey(var)) { order = this.hashmap.get(var); for (int next : order) { if (var.dom().contains(next)) { return next; } } } if (this.defIndomain == null) { throw new RuntimeException(); } return this.defIndomain.indomain(var); } }
Harry
kris
2013-08-01
Yes. It looks correct to me.
/Kris
Harry Haller
2013-08-01
Ok, thank you very much for your help.
Harry