Commit 97a65114 authored by Riegel's avatar Riegel
Browse files

Merge branch 'dev' into 'master'

Version 3.15.0

See merge request !8
parents 99c8f6a8 5950ea5f
Pipeline #10106 passed with stage
in 3 minutes and 15 seconds
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.ToolBar?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<SplitPane dividerPositions="0.7" orientation="VERTICAL" xmlns="http://javafx.com/javafx/8.0.221" xmlns:fx="http://javafx.com/fxml/1">
<items>
<HBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity">
<children>
<SplitPane dividerPositions="0.5" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" HBox.hgrow="ALWAYS">
<items>
<VBox spacing="5.0">
<children>
<Label text="Current">
<font>
<Font size="18.0" />
</font></Label>
<Pane fx:id="currentCanvas" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" VBox.vgrow="ALWAYS" />
</children>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</VBox>
<VBox spacing="5.0">
<children>
<Label text="Next">
<font>
<Font size="18.0" />
</font></Label>
<Pane fx:id="nextCanvas" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" VBox.vgrow="ALWAYS" />
</children>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</VBox>
</items>
</SplitPane>
</children>
</HBox>
<VBox maxWidth="1.7976931348623157E308">
<children>
<ToolBar maxWidth="1.7976931348623157E308" prefHeight="50.0">
<items>
<Button fx:id="selectFeatureBtn" disable="true" mnemonicParsing="false">
<graphic>
<ImageView fx:id="selectImageView" fitHeight="32.0" fitWidth="32.0" pickOnBounds="true" preserveRatio="true" />
</graphic></Button>
<Button fx:id="nextStep" disable="true" mnemonicParsing="false">
<graphic>
<ImageView fx:id="nextStepImage" fitHeight="32.0" fitWidth="32.0" pickOnBounds="true" preserveRatio="true" />
</graphic></Button>
<Button fx:id="healCompleteBtn" disable="true" mnemonicParsing="false">
<graphic>
<ImageView fx:id="healCompleteImage" fitHeight="32.0" fitWidth="32.0" pickOnBounds="true" preserveRatio="true" />
</graphic></Button>
<Button fx:id="acceptBtn" disable="true" mnemonicParsing="false">
<graphic>
<ImageView fx:id="acceptBtnImage" fitHeight="32.0" fitWidth="32.0" pickOnBounds="true" preserveRatio="true" />
</graphic></Button>
<Button fx:id="cancelButton" disable="true" mnemonicParsing="false">
<graphic>
<ImageView fx:id="cancelImage" fitHeight="32.0" fitWidth="32.0" pickOnBounds="true" preserveRatio="true" />
</graphic></Button>
<Pane maxWidth="1.7976931348623157E308" />
<Button fx:id="meshBtn" disable="true" mnemonicParsing="false" text="Create Mesh" />
<Button fx:id="solidInjectorBtn" disable="true" mnemonicParsing="false" text="SolidInjector" />
<Button fx:id="fixBtn" disable="true" mnemonicParsing="false" text="Fix All" />
</items>
</ToolBar>
<HBox spacing="5.0">
<children>
<VBox spacing="5.0" HBox.hgrow="NEVER">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<children>
<Label text="Selected Feature:" />
<Label fx:id="selectedFeatureLabel" />
<Label text="Feature Type:" />
<Label fx:id="featureTypeLabel" />
<Label text="Geometry:" />
<Label fx:id="geometryLabel" />
</children>
</VBox>
<VBox spacing="5.0" HBox.hgrow="NEVER">
<children>
<Label text="Current Errors:" />
<ListView fx:id="currentErrorList" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minWidth="0.0" prefWidth="350.0" />
</children>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</VBox>
<VBox spacing="5.0">
<children>
<Label text="Next Errors:" />
<ListView fx:id="nextErrorList" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minWidth="0.0" prefWidth="350.0" />
</children>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</VBox>
</children>
</HBox>
</children>
</VBox>
</items>
</SplitPane>
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.ToggleButton?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.HBox?>
<HBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" spacing="5.0" xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml">
<children>
<ToggleButton fx:id="cullingBtn" mnemonicParsing="false" selected="true">
<graphic>
<ImageView fx:id="cullingImage" fitHeight="32.0" fitWidth="32.0" pickOnBounds="true" preserveRatio="true" />
</graphic>
</ToggleButton>
<ToggleButton fx:id="wireframeBtn" mnemonicParsing="false">
<graphic>
<ImageView fx:id="wireframeImage" fitHeight="32.0" fitWidth="32.0" pickOnBounds="true" preserveRatio="true" />
</graphic>
</ToggleButton>
<Separator orientation="VERTICAL" />
<Button id="loadBtn" fx:id="simplyBtn" mnemonicParsing="false">
<graphic>
<ImageView fx:id="simplyImageView" fitHeight="32.0" fitWidth="32.0" pickOnBounds="true" preserveRatio="true" />
</graphic>
</Button>
<HBox fx:id="spacer" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minWidth="0.0" />
<Button fx:id="saveBtn" mnemonicParsing="false">
<graphic>
<ImageView fx:id="saveImage" fitHeight="32.0" fitWidth="32.0" pickOnBounds="true" preserveRatio="true" />
</graphic>
</Button>
</children>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</HBox>
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" spacing="5.0" xmlns="http://javafx.com/javafx/8.0.221" xmlns:fx="http://javafx.com/fxml/1">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<children>
<CheckBox fx:id="useBsCheckBox" mnemonicParsing="false" selected="true" text="Use BoundarySurfaces" />
<CheckBox fx:id="useBiCheckBox" mnemonicParsing="false" selected="true" text="Use BuildingInstallations" />
<Separator prefWidth="200.0" />
<CheckBox fx:id="lod2Box" mnemonicParsing="false" selected="true" text="LOD 2" />
<CheckBox fx:id="lod3Box" mnemonicParsing="false" selected="true" text="LOD 3" />
<CheckBox fx:id="lod4Box" mnemonicParsing="false" selected="true" text="LOD 4" />
<HBox alignment="CENTER_RIGHT" fillHeight="false" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" spacing="5.0">
<children>
<Button fx:id="okBtn" alignment="CENTER_RIGHT" mnemonicParsing="false" text="OK" />
<Button fx:id="cancelBtn" alignment="CENTER_RIGHT" mnemonicParsing="false" text="Cancel" />
</children>
</HBox>
</children>
</VBox>
GUISettings.properties
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<ns prefix="gml" uri="http://www.opengis.net/gml"/>
<ns prefix="bldg" uri="http://www.opengis.net/citygml/building/2.0"/>
<pattern>
<rule context="//*:Building">
<assert test="count(descendant::*:lod1Solid) &gt; 0 or count(descendant::*:lod2Solid) &gt; 0 or count(descendant::*:lod3Solid) &gt; 0 or count(descendant::*:lod4Solid) &gt; 0"><value-of select="@gml:id | @id"/>||||SE_ATTRIBUTE_MISSING||any solid</assert>
</rule>
<rule context="//*:BuildingPart">
<assert test="count(*:lod1Solid) = 1 or count(*:lod2Solid) = 1 or count(*:lod3Solid) = 1 or count(*:lod4Solid) = 1"><value-of select="ancestor::*:Building/@*:id"/>||<value-of select="@gml:id | @id"/>||SE_ATTRIBUTE_MISSING||any solid</assert>
</rule>
</pattern>
</schema>
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.hft.stuttgart</groupId>
<artifactId>CityDoctorParent</artifactId>
<version>3.15.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>CityDoctorHealerGenetic</artifactId>
<dependencies>
<dependency>
<groupId>de.hft.stuttgart</groupId>
<artifactId>CityDoctorHealerGUI</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package de.hft.stuttgart.citydoctor2.healer.genetic;
public interface Crossover<T> {
public T cross(T parent1, T parent2);
}
package de.hft.stuttgart.citydoctor2.healer.genetic;
public interface FitnessEvaluation<T> {
public double evaluate(T t);
}
package de.hft.stuttgart.citydoctor2.healer.genetic;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
public class GeneticAlgorithm<T> implements Runnable {
private int populationSize = 5;
private int maxGenerations = 2;
private Crossover<T> cross;
private Mutation<T> mutate;
private Heuristic<T> heuristic;
private FitnessEvaluation<T> evaluation;
private Individual<T> result;
private GeneticAlgorithm(Crossover<T> cross, Mutation<T> mutate, Heuristic<T> heuristic,
FitnessEvaluation<T> evaluation) {
this.cross = Objects.requireNonNull(cross);
this.mutate = Objects.requireNonNull(mutate);
this.heuristic = Objects.requireNonNull(heuristic);
this.evaluation = Objects.requireNonNull(evaluation);
}
public static <T> GeneticAlgorithm<T> of(Crossover<T> cross, Mutation<T> mutate, Heuristic<T> heuristic,
FitnessEvaluation<T> evaluation) {
return new GeneticAlgorithm<>(cross, mutate, heuristic, evaluation);
}
@Override
public void run() {
// initial population
List<Individual<T>> population = new ArrayList<>();
for (int i = 0; i < populationSize; i++) {
population.add(new Individual<>(heuristic.generate()));
}
for (Individual<T> genome : population) {
genome.evaluateFitness(evaluation);
}
Collections.sort(population);
System.out.println("Best Fitness: " + population.get(0).getFitness());
// do the generations thing
for (int i = 0; i < maxGenerations; i++) {
// generate children
for (int j = 0; j < populationSize - 1; j++) {
// maybe random children generation
Individual<T> parent1 = population.get(j);
Individual<T> parent2 = population.get(j + 1);
Individual<T> child1 = new Individual<>(cross.cross(parent1.getObject(), parent2.getObject()));
Individual<T> child2 = new Individual<>(cross.cross(parent2.getObject(), parent1.getObject()));
// mutate
child1 = new Individual<>(mutate.mutate(child1.getObject()));
child2 = new Individual<>(mutate.mutate(child2.getObject()));
child1.evaluateFitness(evaluation);
child2.evaluateFitness(evaluation);
population.add(child1);
population.add(child2);
}
// sort
Collections.sort(population);
// eliminate
List<Individual<T>> newGeneration = new ArrayList<>(populationSize);
for (int j = 0; j < populationSize; j++) {
newGeneration.add(population.get(j));
}
population = newGeneration;
System.out.println("Best Fitness: " + population.get(0).getFitness());
}
result = population.get(0);
System.out.println("End. Best fitness: " + population.get(0).getFitness() + " with plan: " + population.get(0).getObject());
}
public Individual<T> getResult() {
return result;
}
}
package de.hft.stuttgart.citydoctor2.healer.genetic;
public interface Heuristic<T> {
public T generate();
}
package de.hft.stuttgart.citydoctor2.healer.genetic;
public class Individual<T> implements Comparable<Individual<T>> {
private T object;
private double fitness;
public Individual(T object) {
this.object = object;
}
public void evaluateFitness(FitnessEvaluation<T> evaluation) {
fitness = evaluation.evaluate(object);
}
public double getFitness() {
return fitness;
}
@Override
public int compareTo(Individual<T> o) {
return Double.compare(o.getFitness(), fitness);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(fitness);
result = prime * result + (int) (temp ^ (temp >>> 32));
result = prime * result + ((object == null) ? 0 : object.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Individual<?> other = (Individual<?>) obj;
if (Double.doubleToLongBits(fitness) != Double.doubleToLongBits(other.fitness)) {
return false;
}
if (object == null) {
if (other.object != null) {
return false;
}
} else if (!object.equals(other.object)) {
return false;
}
return true;
}
public T getObject() {
return object;
}
@Override
public String toString() {
return "Genotype [object=" + object + ", fitness=" + fitness + "]";
}
public void setFitness(double fitness) {
this.fitness = fitness;
}
}
package de.hft.stuttgart.citydoctor2.healer.genetic;
public interface Mutation<T> {
public T mutate(T genotype);
}
package de.hft.stuttgart.citydoctor2.healer.genetic;
import de.hft.stuttgart.citydoctor2.healer.HealingPlan;
public class NoMutation implements Mutation<HealingPlan> {
@Override
public HealingPlan mutate(HealingPlan plan) {
return plan;
}
}
package de.hft.stuttgart.citydoctor2.healer.genetic;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import de.hft.stuttgart.citydoctor2.check.HealingMethod;
import de.hft.stuttgart.citydoctor2.healer.HealingPlan;
public class OrderCrossover implements Crossover<HealingPlan> {
private Random r;
public OrderCrossover() {
r = new Random();
}
@Override
public HealingPlan cross(HealingPlan parent1, HealingPlan parent2) {
int size1 = parent1.getHealingMethods().size();
int firstPoint = Math.max(0, r.nextInt(size1 - 2));
int secondPoint = Math.min(size1, firstPoint + r.nextInt(size1 - firstPoint) + 1);
List<HealingMethod> childMethods = new ArrayList<>(size1);
// fill with empty values, so set(i, x) works
for (int i = 0; i < size1; i++) {
childMethods.add(null);
}
for (int i = firstPoint; i < secondPoint; i++) {
childMethods.set(i, parent1.getHealingMethods().get(i));
}
int writeIndex = 0;
for (HealingMethod m : parent2.getHealingMethods()) {
if (!contains(childMethods, m)) {
while (childMethods.get(writeIndex) != null) {
writeIndex++;
}
childMethods.set(writeIndex, m);
}
}
for (HealingMethod m : parent1.getHealingMethods()) {
if (!contains(childMethods, m)) {
while (childMethods.get(writeIndex) != null) {
writeIndex++;
}
childMethods.set(writeIndex, m);
}
}
HealingPlan child = new HealingPlan();
child.getHealingMethods().addAll(childMethods);
return child;
}
private boolean contains(List<HealingMethod> childMethods, HealingMethod m) {
for (HealingMethod method : childMethods) {
if (method != null && method.getClass() == m.getClass()) {
return true;
}
}
return false;
}
}
package de.hft.stuttgart.citydoctor2.healer.genetic;
import de.hft.stuttgart.citydoctor2.healer.HealingPlan;
public class RandomFitness implements FitnessEvaluation<HealingPlan> {
@Override
public double evaluate(HealingPlan plan) {
return Math.random() * 50000;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment