Extension of the Interface2DBorderProblem interface
This commit is contained in:
		@@ -120,7 +120,7 @@ public class TopoPlot extends Plot {
 | 
			
		||||
    		if (tmp < min) min = tmp;
 | 
			
		||||
    		if (tmp > max) max = tmp;
 | 
			
		||||
    		if (withGradientsIfAvailable && (problem instanceof InterfaceFirstOrderDerivableProblem)) {
 | 
			
		||||
    			double[] deriv = ((InterfaceFirstOrderDerivableProblem)problem).getFirstOrderGradients(pos);
 | 
			
		||||
    			double[] deriv = ((InterfaceFirstOrderDerivableProblem)problem).getFirstOrderGradients(problem.project2DPoint(pos));
 | 
			
		||||
    			for (int i=0; i<2;i++) maxDeriv=Math.max(maxDeriv, Math.abs(deriv[i])); // maximum deriv of first 2 dims
 | 
			
		||||
    		}
 | 
			
		||||
 | 
			
		||||
@@ -148,7 +148,7 @@ public class TopoPlot extends Plot {
 | 
			
		||||
    		for (int y=0; y<gridy; y++) {
 | 
			
		||||
    			pos[0]  = border[0][0]+x*deltaX;
 | 
			
		||||
    			pos[1]  = border[1][0]+y*deltaY;
 | 
			
		||||
    			double[] derivPos = ((InterfaceFirstOrderDerivableProblem)problem).getFirstOrderGradients(pos);
 | 
			
		||||
    			double[] derivPos = ((InterfaceFirstOrderDerivableProblem)problem).getFirstOrderGradients(problem.project2DPoint(pos));
 | 
			
		||||
    			Mathematics.svDiv(1.1*(2*maxDeriv/Math.max(deltaX, deltaY)), derivPos, derivPos);
 | 
			
		||||
    			Mathematics.vvAdd(pos, derivPos, derivPos);
 | 
			
		||||
    			getFunctionArea().drawLine(pos, derivPos);
 | 
			
		||||
 
 | 
			
		||||
@@ -338,12 +338,12 @@ public abstract class AbstractProblemDouble extends AbstractOptimizationProblem
 | 
			
		||||
    	return makeRange();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public double[] project2DPoint(double[] point) {
 | 
			
		||||
    	return Mathematics.expandVector(point, getProblemDimension(), 0.);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
	public double functionValue(double[] point) {
 | 
			
		||||
		double x[] = new double[getProblemDimension()];
 | 
			
		||||
		for (int i=0; i<point.length; i++) x[i]=point[i];
 | 
			
		||||
		for (int i=point.length; i<x.length; i++) x[i] = 0;
 | 
			
		||||
		return eval(x)[0];
 | 
			
		||||
		return eval(project2DPoint(point))[0];
 | 
			
		||||
	}
 | 
			
		||||
    /**********************************************************************************************************************
 | 
			
		||||
     * These are for GUI
 | 
			
		||||
 
 | 
			
		||||
@@ -22,6 +22,7 @@ import eva2.server.go.strategies.InterfaceOptimizer;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import eva2.server.go.problems.Interface2DBorderProblem;
 | 
			
		||||
import eva2.tools.math.Mathematics;
 | 
			
		||||
 | 
			
		||||
public class ExternalRuntimeProblem extends AbstractOptimizationProblem implements Interface2DBorderProblem, InterfaceProblemDouble {
 | 
			
		||||
 | 
			
		||||
@@ -328,11 +329,11 @@ public class ExternalRuntimeProblem extends AbstractOptimizationProblem implemen
 | 
			
		||||
        return (InterfaceDataTypeDouble)this.m_Template;
 | 
			
		||||
    }
 | 
			
		||||
	public double functionValue(double[] point) {
 | 
			
		||||
		double x[] = new double[m_ProblemDimension];
 | 
			
		||||
		for (int i=0; i<point.length; i++) x[i]=point[i];
 | 
			
		||||
		for (int i=point.length; i<m_ProblemDimension; i++) x[i] = 0;
 | 
			
		||||
		return eval(x)[0];
 | 
			
		||||
		return eval(project2DPoint(point))[0];
 | 
			
		||||
	}
 | 
			
		||||
    public double[] project2DPoint(double[] point) {
 | 
			
		||||
    	return Mathematics.expandVector(point, getProblemDimension(), 0.);
 | 
			
		||||
    }
 | 
			
		||||
	public double[][] get2DBorder() {
 | 
			
		||||
		return getDoubleRange();
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -12,9 +12,20 @@ public interface Interface2DBorderProblem {
 | 
			
		||||
     */
 | 
			
		||||
    public double[][] get2DBorder();
 | 
			
		||||
 | 
			
		||||
    /** This method returns the double value at a given position.
 | 
			
		||||
    /** 
 | 
			
		||||
     * This method returns the double value at a given position. The value should be
 | 
			
		||||
     * based on the same projection delivered by the project2DPoint function.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param point     The double[2] that is queried.
 | 
			
		||||
     * @return double
 | 
			
		||||
     */
 | 
			
		||||
    public double functionValue(double[] point);
 | 
			
		||||
    
 | 
			
		||||
    /**
 | 
			
		||||
     * Project a 2D point to the default higher-dimensional cut to be displayed (if required for plotting).
 | 
			
		||||
     * 
 | 
			
		||||
     * @param point the double[2] that is queried
 | 
			
		||||
     * @return a (higher dimensional) projection of the point
 | 
			
		||||
     */
 | 
			
		||||
    public double[] project2DPoint(double[] point);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1020,6 +1020,27 @@ public class Mathematics {
 | 
			
		||||
		} else return v;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * Expand a vector to a higher dimension (len) by filling it up 
 | 
			
		||||
	 * with a constant value.
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param x
 | 
			
		||||
	 * @param len
 | 
			
		||||
	 * @param v
 | 
			
		||||
	 * @return
 | 
			
		||||
	 */
 | 
			
		||||
	public static double[] expandVector(double[] x, int len, double v) {
 | 
			
		||||
		if (len <= x.length ) {
 | 
			
		||||
			System.err.println("Error, invalid length in expandVector, expecting l>" + x.length);
 | 
			
		||||
			return x;
 | 
			
		||||
	 	} else {
 | 
			
		||||
	 		double[] expanded = new double[len];
 | 
			
		||||
	 		System.arraycopy(x, 0, expanded, 0, x.length);
 | 
			
		||||
	 		for (int i=x.length; i<expanded.length; i++) expanded[i] = v;
 | 
			
		||||
	 		return expanded;
 | 
			
		||||
	 	}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * Calculate the average length of the range intervals over all dimensions.
 | 
			
		||||
	 * 
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user