123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- package psoAlgoCode;
- import ui.controller.Control;
- import ui.model.Model;
- public class Function {
- public static String name;
- private int desiredFunction;
- private int type;
- public static double upperLimit;
- public static double lowerLimit;
- public Function() {
- super();
- name = "";
- desiredFunction = Constants.function;
- upperLimit = 0;
- lowerLimit = 0;
- type = 0;
- }
- /*public void setParameters(Object obj) {
- if (obj.getClass().equals(Boolean.class)) {
- name = "Boolean function";
- // upperLimit = 500;
- // lowerLimit = -500;
- type = 0;
- } else if (obj.getClass().equals(Double.class) && desiredFunction == 0) {
- name = "Sphere function";
- upperLimit = 100;
- lowerLimit = 50;
- type = 1;
- } else if (obj.getClass().equals(Double.class) && desiredFunction == 1) {
- name = "Rastrigin function";
- upperLimit = 5.12;
- lowerLimit = 2.56;
- type = 1;
- } else if (obj.getClass().equals(Double.class) && desiredFunction == 2) {
- name = "Griewank function";
- upperLimit = 600;
- lowerLimit = 300;
- type = 1;
- }
- }*/
- public double execute(Particle p, int index, Model model, Control control) {
- double result = 0.0;
- if (type == 0) {
- result = executeSmartGrid(p, index, model, control);
- } /*else if (type == 1 && desiredFunction == 0) {
- result = executeSphere(p, index);
- } else if (type == 1 && desiredFunction == 1) {
- result = executeRastrigin(p, index);
- } else if (type == 1 && desiredFunction == 2) {
- result = executeGriewank(p, index);
- }*/
- return result;
- }
- private static double executeSmartGrid(Particle p, int index, Model model, Control control) {
- double result = 0.0;
- SGFunctions sg = new SGFunctions(p, model, control);
- result = sg.calculateFitness();
- return result;
- }
- /*private static double executeSphere(Particle p, int index) {
- double result = 0.0;
- for (int dim = 0; dim < p.getDimensions(); dim++) {
- for (int i = 0; i < p.getPositionAdv().getCoord(dim).size(); i++) {
- double temp = (double) p.getPositionAdv().getCoord(dim).get(i);
- result += Math.pow(temp, 2);
- }
- }
- return result;
- }*/
- /*private static double executeRastrigin(Particle p, int index) {
- double result = 0.0;
- for (int dim = 0; dim < p.getDimensions(); dim++) {
- for (int i = 0; i < p.getPositionAdv().getCoord(dim).size(); i++) {
- double temp = (double) p.getPositionAdv().getCoord(dim).get(i);
- result += (Math.pow(temp, 2) - (10 * Math.cos(2 * Math.PI * temp)) + 10);
- }
- }
- return result;
- }*/
- /*
- private static double executeGriewank(Particle p, int index) {
- double sum = 0.0;
- double mult = 1.0;
- double result = 0.0;
- for (int dim = 0; dim < p.getDimensions(); dim++) {
- for (int i = 0; i < p.getPositionAdv().getCoord(dim).size(); i++) {
- double temp = (double) p.getPositionAdv().getCoord(dim).get(i);
- sum += Math.pow(temp, 2) / 4000;
- mult *= Math.cos(temp / Math.sqrt(index));
- }
- }
- result = sum - mult + 1;
- return result;
- }
- */
- }
|