From bbe4fa182fb1945745fc7963ff7eb77d21a0b7f1 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sun, 17 Sep 2017 23:19:07 -0700 Subject: [PATCH] Add functions to generate inputs and outputs within the range. --- .../org/nwapw/abacus/fx/graphing/Graph.kt | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/fx/src/main/kotlin/org/nwapw/abacus/fx/graphing/Graph.kt b/fx/src/main/kotlin/org/nwapw/abacus/fx/graphing/Graph.kt index eacd458..34b72b9 100644 --- a/fx/src/main/kotlin/org/nwapw/abacus/fx/graphing/Graph.kt +++ b/fx/src/main/kotlin/org/nwapw/abacus/fx/graphing/Graph.kt @@ -37,11 +37,30 @@ class Graph(val abacus: Abacus, } fun evaluateWith(tree: TreeNode, values: List, - contextModifier: MutableEvaluationContext.(T) -> Unit) = runBlocking { + contextModifier: MutableEvaluationContext.(T) -> Unit) = runBlocking { values.map { val context = abacus.context.mutableSubInstance() context.contextModifier(it) async(CommonPool) { abacus.evaluateTreeWithContext(tree, context) } }.map { it.await() } } + + fun List.evaluateWith(tree: TreeNode, + contextModifier: MutableEvaluationContext.(T) -> Unit ) = + evaluateWith(tree, this, contextModifier) + + fun generateInputs(): List = + generateSequence(1) { + it + 1 + }.map { + val context = abacus.context.mutableSubInstance() + context.setVariable(pointInputVariable, + context.inheritedNumberImplementation!!.instanceForString(it.toString())) + abacus.evaluateTreeWithContext(pointExpressionTree!!, context).value + }.takeWhile { it in domain }.toList() + + fun generateOutputs(inputs: List): List = + inputs.evaluateWith(expressionTree!!) { + setVariable(inputVariable, it) + }.map { it.value } }