mirror of
https://github.com/DanilaFe/abacus
synced 2025-01-09 07:44:14 -08:00
Add functions to generate inputs and outputs within the range.
This commit is contained in:
parent
3bffa1c78f
commit
bbe4fa182f
@ -44,4 +44,23 @@ class Graph(val abacus: Abacus,
|
|||||||
async(CommonPool) { abacus.evaluateTreeWithContext(tree, context) }
|
async(CommonPool) { abacus.evaluateTreeWithContext(tree, context) }
|
||||||
}.map { it.await() }
|
}.map { it.await() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun <T> List<T>.evaluateWith(tree: TreeNode,
|
||||||
|
contextModifier: MutableEvaluationContext.(T) -> Unit ) =
|
||||||
|
evaluateWith(tree, this, contextModifier)
|
||||||
|
|
||||||
|
fun generateInputs(): List<NumberInterface> =
|
||||||
|
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<NumberInterface>): List<NumberInterface> =
|
||||||
|
inputs.evaluateWith(expressionTree!!) {
|
||||||
|
setVariable(inputVariable, it)
|
||||||
|
}.map { it.value }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user