Skip to content

Commit

Permalink
Added Kotlin support
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravby committed Oct 21, 2024
1 parent d198a16 commit efb35e0
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
12 changes: 12 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
id 'idea'
id 'org.openjfx.javafxplugin' version '0.0.13'
id 'org.beryx.jlink' version '2.25.0'
id 'org.jetbrains.kotlin.jvm'
}

idea {
Expand Down Expand Up @@ -56,6 +57,7 @@ dependencies {
implementation 'org.apache.commons:commons-rng-simple:1.4'
implementation 'org.apache.commons:commons-lang3:3.4'
implementation 'commons-io:commons-io:2.11.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
}

version = '1.0'
Expand Down Expand Up @@ -102,3 +104,13 @@ jlink {
name = 'app'
}
}
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
6 changes: 5 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/*
pluginManagement {
plugins {
id 'org.jetbrains.kotlin.jvm' version '2.0.21'
}
}/*
* This settings file was generated by the Gradle 'init' task.
*
* The settings file is used to specify which projects to include in your build.
Expand Down
46 changes: 46 additions & 0 deletions src/org/um/feri/ears/algorithms/so/random/RandomSearch.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.um.feri.ears.algorithms.so.random

import org.um.feri.ears.algorithms.AlgorithmInfo
import org.um.feri.ears.algorithms.Author
import org.um.feri.ears.algorithms.NumberAlgorithm
import org.um.feri.ears.problems.DoubleProblem
import org.um.feri.ears.problems.NumberSolution
import org.um.feri.ears.problems.StopCriterionException
import org.um.feri.ears.problems.Task

class RandomSearch : NumberAlgorithm() {

// needs to extend NumberAlgorithm
private var best: NumberSolution<Double?>? = null // used to save global best solution

fun RandomSearch() {
ai = AlgorithmInfo("RW", "Random Walk", "")
au = Author("Matej", "matej.crepinsek@um.si")
}

@Throws(StopCriterionException::class)
override fun execute(task: Task<NumberSolution<Double?>, DoubleProblem>): NumberSolution<Double?>? { // method which executes the algorithm
// the task object holds information about the stopping criterion
// and information about the problem (number of dimensions, number of constraints, upper and lower bounds...)
var newSolution: NumberSolution<Double?>
best =
task.randomEvaluatedSolution // generate new random solution (number of evaluations is incremented automatically)
// to evaluate a custom solution or an array use task.eval(mySolution)
while (!task.isStopCriterion) { // run until the stopping criterion is not reached

newSolution = task.randomEvaluatedSolution
if (task.problem.isFirstBetter(
newSolution,
best
)
) { // use method isFirstBetter to check which solution is better (it checks constraints and considers the type of the problem (minimization or maximization))
best = newSolution
}
task.incrementNumberOfIterations() // increase the number of generations for each iteration of the main loop
}
return best // return the best solution found
}

override fun resetToDefaultsBeforeNewRun() {
}
}
1 change: 0 additions & 1 deletion src/org/um/feri/ears/visualization/gp/GPInterface.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.um.feri.ears.visualization.gp;

import javafx.scene.input.KeyCode;
import org.um.feri.ears.algorithms.GPAlgorithm;
import org.um.feri.ears.algorithms.gp.ElitismGPAlgorithm;
import org.um.feri.ears.algorithms.gp.GPAlgorithmExecutor;
Expand Down

0 comments on commit efb35e0

Please sign in to comment.