3 * Description: Contains a set of points.
5 * @ Author Create/Modi Note
6 * Xiaofeng Xie Mar 7, 2003
7 * Xiaofeng Xie May 3, 2003
8 * Xiaofeng Xie May 11, 2004
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * Please acknowledge the author(s) if you use this code in any way.
25 package net
.adaptivebox
.knowledge
;
27 import net
.adaptivebox
.global
.*;
28 import net
.adaptivebox
.goodness
.*;
29 import net
.adaptivebox
.problem
.*;
31 public class Library
{
32 private SearchPoint
[] libPoints
= new SearchPoint
[0];
33 protected int gIndex
= -1;
35 public Library(SearchPoint
[] points
){
36 this.libPoints
= points
;
39 public Library(int number
, ProblemEncoder problemEncoder
){
40 libPoints
= new SearchPoint
[number
];
41 for (int i
=0; i
<number
; i
++) {
42 libPoints
[i
] = problemEncoder
.getEncodedSearchPoint();
46 public SearchPoint
getGbest() {
47 return getSelectedPoint(gIndex
);
50 public void refreshGbest(IGoodnessCompareEngine qualityComparator
) {
51 gIndex
= tournamentSelection(qualityComparator
, getPopSize()-1, true);
54 public int getPopSize() {
55 return libPoints
.length
;
58 public SearchPoint
getSelectedPoint(int index
) {
59 return libPoints
[index
];
62 public static boolean replace(IGoodnessCompareEngine comparator
, SearchPoint outPoint
, SearchPoint tobeReplacedPoint
) {
63 boolean isBetter
= false;
64 if(comparator
.compare(outPoint
.getEncodeInfo(), tobeReplacedPoint
.getEncodeInfo())<IGoodnessCompareEngine
.LARGER_THAN
) {
65 tobeReplacedPoint
.importPoint(outPoint
);
71 public int tournamentSelection(IGoodnessCompareEngine comparator
, int times
, boolean isBetter
) {
72 int[] indices
= RandomGenerator
.randomSelection(getPopSize(), times
);
73 int currentIndex
= indices
[0];
74 for (int i
=1; i
<indices
.length
; i
++) {
75 int compareValue
= comparator
.compare(libPoints
[indices
[i
]].getEncodeInfo(), libPoints
[currentIndex
].getEncodeInfo());
76 if (isBetter
== (compareValue
<IGoodnessCompareEngine
.LARGER_THAN
)) {
77 currentIndex
= indices
[i
];
83 public double getExtremalVcon(boolean isMAX
) {
84 double val
=BasicBound
.MINDOUBLE
;
85 for(int i
=0; i
<libPoints
.length
; i
++) {
86 if(libPoints
[i
].getEncodeInfo()[0]>val
==isMAX
) {
87 val
= libPoints
[i
].getEncodeInfo()[0];
93 public int getVconThanNum(double allowedCons
) {
95 for(int i
=0; i
<libPoints
.length
; i
++) {
96 if(libPoints
[i
].getEncodeInfo()[0]<=allowedCons
) {