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 } }