From fc0bf72701db2f2cea5742711d7bb75681b6ef2c Mon Sep 17 00:00:00 2001
From: Alexander Diewald <diewald@fortiss.org>
Date: Tue, 3 Jul 2018 13:58:58 +0200
Subject: [PATCH] DI: Introduce a service interface for ExploraionModules.

Signed-off-by: Alexander Diewald <diewald@fortiss.org>
---
 .../af3/exploration/alg/service/.ratings      |  1 +
 .../service/IExplorationModuleService.java    | 80 +++++++++++++++++++
 2 files changed, 81 insertions(+)
 create mode 100644 org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/IExplorationModuleService.java

diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/.ratings b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/.ratings
index 9a3221ac..a3e10a31 100644
--- a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/.ratings
+++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/.ratings
@@ -6,6 +6,7 @@ IExplorationContraintTransformationModule.java 1d3560401275f719e2b9901d1639a6be6
 IExplorationEncoding.java f58adbcf840af521333c2777f50041a60548bff3 RED
 IExplorationEvaluatationService.java b4d242fb3d16796e98db31dd8db50aa4d003d49f RED
 IExplorationExtension.java c2a148e18c580d2432357e93da45e7bf7df8eb0c RED
+IExplorationModuleService.java 9280ae46ce9918c3b58e2f8189535707ac232c1c RED
 IExplorationRepairService.java 9fdbc6c62436e32f1ebc7f3e6c43517199271f32 RED
 IExplorationService.java 29252f52f28fcd036272bbb05dcd48897ee33dfd RED
 IExplorationTargetEvaluator.java 99c27a053a123462b8a4faadc9c3530fe6bc0c67 RED
diff --git a/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/IExplorationModuleService.java b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/IExplorationModuleService.java
new file mode 100644
index 00000000..9280ae46
--- /dev/null
+++ b/org.fortiss.af3.exploration.alg/src/org/fortiss/af3/exploration/alg/service/IExplorationModuleService.java
@@ -0,0 +1,80 @@
+/*-------------------------------------------------------------------------+
+| Copyright 2018 fortiss GmbH                                              |
+|                                                                          |
+| Licensed under the Apache License, Version 2.0 (the "License");          |
+| you may not use this file except in compliance with the License.         |
+| You may obtain a copy of the License at                                  |
+|                                                                          |
+|    http://www.apache.org/licenses/LICENSE-2.0                            |
+|                                                                          |
+| Unless required by applicable law or agreed to in writing, software      |
+| distributed under the License is distributed on an "AS IS" BASIS,        |
+| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+| See the License for the specific language governing permissions and      |
+| limitations under the License.                                           |
++--------------------------------------------------------------------------*/
+package org.fortiss.af3.exploration.alg.service;
+
+import org.fortiss.af3.exploration.alg.dse.backend.opt4j.extensions.compositegene.phenotype.Phenotype;
+import org.opt4j.core.Genotype;
+import org.opt4j.core.optimizer.Operator;
+import org.opt4j.core.problem.Creator;
+import org.opt4j.core.problem.Decoder;
+import org.opt4j.core.problem.Evaluator;
+
+import com.google.inject.AbstractModule;
+
+/**
+ * Service for adding Exploration Modules to the DSE. The define the concrete problems that shall
+ * be solved by the DSE process. Modules registered with this service are known to the DSE and
+ * can be selected by users to define a DSE process. The Modules registered here are not defining a
+ * a concrete DSE process, just the concrete problems.
+ * 
+ * Exploration modules can be categorized into three classes: Variable definitions, Problem
+ * statements and transformations, and Evaluators (solution metrics). The variable definitions
+ * consist of a {@link Genotype}s (variables), {@link Operator}s (modify variables), and
+ * {@link Creator}s (variable initialization). Problem statements transform {@link Genotype}s into
+ * evaluable solutions implemented by {@link Decoder}s that produce {@link Phenotype}s.
+ * {@link Evaluator}s
+ * rate {@link Phenotype}s such that the quality of a solution can be quantified.
+ * 
+ * The complete DSE process is based on DI: each of the elements composing exploration modules have
+ * to be implemented as Guice {@link AbstractModule}s.
+ * 
+ * @author diewald
+ */
+public interface IExplorationModuleService extends IExplorationService {
+
+	/**
+	 * Registers an optimization variable ({@code genotype}) with the DSE, along with its
+	 * initializer ({@code creator}) and modificator ({@code operator}).
+	 * 
+	 * @param genotype
+	 *            optimization variable.
+	 * @param creator
+	 *            initializes the opt. variable.
+	 * @param operator
+	 *            modifications applied during the process iterations.
+	 */
+	<G extends Genotype> void
+			registerVariable(G genotype, Creator<G> creator, Operator<G> operator);
+
+	/**
+	 * Registers a problem definition with the DSE process. The {@code phenotype} is equivalent to
+	 * a candidate solution that is produced by the given {@code decoder}.
+	 * 
+	 * @param phenotype
+	 *            candidate solution.
+	 * @param decoder
+	 *            transforms variables (and/or other inputs) to candidate solutions.
+	 */
+	<P extends Phenotype> void registerProblem(P phenotype, Decoder<Genotype, P> decoder);
+
+	/**
+	 * Registers the given {@code evaluator} to quantifies the quality of a solution by some metric.
+	 * 
+	 * @param evaluator
+	 *            applies some metric to a candidate solution.
+	 */
+	void registerEvaluator(Evaluator<Phenotype> evaluator);
+}
-- 
GitLab