bump product version to 4.1.6.2
[LibreOffice.git] / nlpsolver / ThirdParty / EvolutionarySolver / src / net / adaptivebox / problem / ProblemEncoder.java
bloba5deb6315954dba41e2a4f5177448f51e42dd76a
1 /**
2 * Description: Encodes the specified problem into encoded information for
3 * forming the goodness landscape.
5 * @ Author Create/Modi Note
6 * Xiaofeng Xie May 31, 2000
7 * Xiaofeng Xie Sep. 19, 2002
8 * Xiaofeng Xie Mar. 01, 2003
9 * Xiaofeng Xie May 11, 2004
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * Please acknowledge the author(s) if you use this code in any way.
23 * @version 1.0
24 * @Since MAOS1.0
27 package net.adaptivebox.problem;
29 import net.adaptivebox.global.*;
30 import net.adaptivebox.space.*;
31 import net.adaptivebox.encode.*;
32 import net.adaptivebox.knowledge.*;
34 public abstract class ProblemEncoder {
35 //Store the calculated results for the responses
36 double[] tempResponseSet; //temp values
37 double[] tempLocation; //temp values
39 //the search space (S)
40 protected DesignSpace designSpace = null;
42 // For evaluate the response vector into encoded vector double[2]
43 protected EvalStruct evalStruct = null;
45 protected ProblemEncoder(int paramNum, int targetNum) throws Exception {
46 designSpace = new DesignSpace(paramNum);
47 evalStruct = new EvalStruct(targetNum);
48 tempLocation = new double[paramNum];
49 tempResponseSet = new double[targetNum];
52 public DesignSpace getDesignSpace() {
53 return designSpace;
56 public EvalStruct getEvalStruct() {
57 return evalStruct;
60 //set the default information for each dimension of search space (S)
61 protected void setDefaultXAt(int i, double min, double max, double grain) {
62 DesignDim dd = new DesignDim();
63 dd.grain = grain;
64 dd.paramBound = new BasicBound(min, max);
65 designSpace.setElemAt(dd, i);
68 protected void setDefaultXAt(int i, double min, double max) {
69 DesignDim dd = new DesignDim();
70 dd.paramBound = new BasicBound(min, max);
71 designSpace.setElemAt(dd, i);
74 //set the default information for evaluation each response
75 protected void setDefaultYAt(int i, double min, double max) {
76 EvalElement ee = new EvalElement();
77 ee.targetBound = new BasicBound(min, max);
78 evalStruct.setElemAt(ee, i);
81 protected void setDefaultYAt(int i, double min, double max, double weight) {
82 EvalElement ee = new EvalElement();
83 ee.targetBound = new BasicBound(min, max);
84 ee.weight = weight;
85 evalStruct.setElemAt(ee, i);
88 //get a fresh point
89 public SearchPoint getFreshSearchPoint() {
90 return new SearchPoint(designSpace.getDimension());
93 //get an encoded point
94 public SearchPoint getEncodedSearchPoint() {
95 SearchPoint point = getFreshSearchPoint();
96 designSpace.initializeGene(point.getLocation());
97 evaluate(point);
98 return point;
101 //evaluate the point into encoded information
102 public void evaluate(SearchPoint point) {
103 //copy to temp point
104 System.arraycopy(point.getLocation(), 0, this.tempLocation, 0, tempLocation.length);
105 //mapping the temp point to original search space S
106 designSpace.getMappingPoint(tempLocation);
107 //calculate based on the temp point
108 calcTargets(tempResponseSet, tempLocation);
109 evalStruct.evaluate(point.getEncodeInfo(), tempResponseSet);
110 point.setObjectiveValue(tempResponseSet[0]);
113 //calcuate each response, must be implemented
114 abstract protected double calcTargetAt(int index, double[] VX);
116 // calculate all the responses VY[] based on given point VX[]
117 private void calcTargets(double[] VY, double[] VX) {
118 for(int i=0; i<VY.length; i++) {
119 VY[i] = calcTargetAt(i, VX);