001/** 002 * Copyright (C) 2007 - 2016, Jens Lehmann 003 * 004 * This file is part of DL-Learner. 005 * 006 * DL-Learner is free software; you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation; either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * DL-Learner is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package org.dllearner.algorithms.gp; 020 021import org.dllearner.learningproblems.ScorePosNeg; 022import org.semanticweb.owlapi.model.OWLClassExpression; 023 024/** 025 * This class represents a program, i.e. an individual. 026 * 027 * @author Jens Lehmann 028 * 029 */ 030public class Program { 031 032 // public static int fitnessEvaluations = 0; 033 034 private OWLClassExpression hypothesis; 035 036 // private Concept extendedHypothesis; 037 038 private OWLClassExpression adc; 039 040 private ScorePosNeg score; 041 042 // private Score scoreAdc; 043 044 // private LearningProblem learningProblem; 045 046 private double fitness; 047 048 /** 049 * Create a new program. 050 * 051 */ 052 public Program(ScorePosNeg score, OWLClassExpression hypothesis) { 053 this(score, hypothesis, null); 054 } 055 056 public Program(ScorePosNeg score, OWLClassExpression hypothesis, OWLClassExpression adc) { 057 // this.learningProblem = learningProblem; 058 this.score = score; 059 this.hypothesis = hypothesis; 060 this.adc = adc; 061 // TODO: es sind Prozent pro Längeneinheit, also ist hier die 062 // Implementierung falsch !! 063 // fitness = score.getScore() - hypothesis.getLength() * Config.percentPerLengthUnit; 064 // => in getScore() ist jetzt schon der length penalty integriert 065 fitness = score.getScoreValue(); 066 // fitnessEvaluations++; 067 068 // System.out.println("new program: " + hypothesis); 069 070 /* 071 // falls R�ckgabetyp spezifiziert ist, dann muss hier der Baum 072 // entsprechend ver�ndert werden 073 if (!Config.returnType.equals("")) { 074 // newRoot.addChild(new AtomicConcept(Config.returnType)); 075 // newRoot.addChild(hypothesis); 076 Concept newRoot = new Conjunction(new AtomicConcept(Config.returnType),hypothesis); 077 // parent wieder auf null setzen, damit es nicht inkonsistent wird 078 // TODO: ist nicht wirklich elegant und auch inkompatibel mit 079 // dem Hill-Climbing-Operator 080 hypothesis.setParent(null); 081 extendedHypothesis = newRoot; 082 } else 083 extendedHypothesis = hypothesis; 084 085 // fitness evaluation on program creation 086 calculateFitness(); 087 */ 088 } 089 090 // nur aufrufen, wenn Programm ver�ndert wird und deshalb die Fitness neu 091 // berechnet werden muss 092 /* 093 public void calculateFitness() { 094 if(Config.GP.adc) 095 score = learningProblem.computeScore(extendedHypothesis, adc); 096 else 097 score = learningProblem.computeScore(extendedHypothesis); 098 099 fitness = score.getScore() - 0.1 * hypothesis.getConceptLength(); 100 101 if (Config.GP.adc) 102 fitness -= 0.1 * adc.getConceptLength(); 103 104 // zus�tzliche Bestrafung f�r sehr lange Definitionen 105 if(hypothesis.getNumberOfNodes()>50) 106 fitness -= 10; 107 fitnessEvaluations++; 108 } 109 */ 110 111 /** 112 * Returns the previously calculated fitness of the program. 113 * 114 * @return The fitness of the program. 115 */ 116 public double getFitness() { 117 return fitness; 118 } 119 120 /** 121 * Returns the program tree corresponding to this program. 122 * 123 * @return The program tree. 124 */ 125 public OWLClassExpression getTree() { 126 return hypothesis; 127 } 128 129 public ScorePosNeg getScore() { 130 return score; 131 } 132 133 public OWLClassExpression getAdc() { 134 return adc; 135 } 136}