fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / nlpsolver / ThirdParty / EvolutionarySolver / src / net / adaptivebox / goodness / ACRComparator.java
blob1efd3c7ac8af465cda6914cabde14d0e8e4c39ec
1 /**
2 * Description: For comparison of goodness in landscape with loosed constraints
3 * which varied adaptively according to the social information.
5 * @Applied domain: efficiently for ridge class feasible space (SF), such as
6 * the problem with eqaulity constraints
8 * @ Author Create/Modi Note
9 * Xiaofeng Xie Jun 24, 2003 Created
10 * Xiaofeng Xie May 11, 2004
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * Please acknowledge the author(s) if you use this code in any way.
24 * @version 1.0
25 * @Since MAOS1.2
27 * [1] Xie X F, Zhang W J, Bi D C. Handling equality constraints by adaptive
28 * relaxing rule for swarm algorithms. Congress on Evolutionary Computation,
29 * Oregon, USA, 2004
32 package net.adaptivebox.goodness;
34 import net.adaptivebox.knowledge.*;
35 import net.adaptivebox.global.*;
38 public class ACRComparator implements IGoodnessCompareEngine, IUpdateCycleEngine {
39 private Library socialPool;
40 private double epsilon_t = 0;
42 private double RU = 0.75;
43 private double RL = 0.25;
44 private double BETAF = 0.618;
45 private double BETAL = 0.618;
46 private double BETAU = 1.382;
48 private double T = -1;
50 private double TthR = 0.5;
52 public ACRComparator(Library lib, int T) {
53 socialPool = lib;
54 this.T = T;
55 //set the (epsilon_t|t=0) as the maximum CONS value among the SearchPoints in the library
56 epsilon_t = lib.getExtremalVcon(true);
59 static public int compare(double data1, double data2) {
60 if (data1 < data2)
61 return LESS_THAN;
62 else if (data1 > data2)
63 return LARGER_THAN;
64 else
65 return EQUAL_TO;
68 public int compare(double[] fit1, double[] fit2) {
69 if(Math.max(fit1[0], fit2[0])<=Math.max(0, epsilon_t)) { //epsilon>0
70 return compare(fit1[1], fit2[1]);
71 } else {
72 return compare(fit1[0], fit2[0]);
76 public void updateCycle(int t) {
77 //calculates the ratio
78 double rn = (double)socialPool.getVconThanNum(epsilon_t)/(double)socialPool.getPopSize();
79 if(t>TthR*T &&T!=-1) { //Forcing sub-rule
80 epsilon_t *= BETAF;
81 } else { //Ratio-keeping sub-rules
82 if(rn>RU) {
83 epsilon_t *= BETAL; //Shrink
85 if(rn<RL) {
86 epsilon_t *= BETAU; //Relax