Skip to content

Commit

Permalink
tracegen added to xcfa execute config
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamZsofi committed Oct 27, 2024
1 parent 8cc79dc commit 5520360
Show file tree
Hide file tree
Showing 9 changed files with 561 additions and 465 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Copyright 2024 Budapest University of Technology and Economics
*
* 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 hu.bme.mit.theta.analysis.algorithm.tracegeneration

import hu.bme.mit.theta.analysis.Action
import hu.bme.mit.theta.analysis.State
import hu.bme.mit.theta.analysis.Trace
import hu.bme.mit.theta.analysis.algorithm.arg.ARG
import hu.bme.mit.theta.analysis.algorithm.arg.ArgNode
import hu.bme.mit.theta.analysis.expr.StmtAction
import java.io.BufferedReader
import java.io.IOException
import java.io.StringReader

class DoubleEndNodeRemover<S : State, A : Action> {

private fun isLastInternal(node: ArgNode<S, A>): Boolean {
return node.state.toString().contains("last_internal")
}

private fun isBadLeaf(node: ArgNode<S, A>): Boolean {
if (isLastInternal(node)) {
if (node.parent.isEmpty) return false
val parent = node.parent.get()
if (parent.parent.isEmpty) return false
val grandParent = node.parent.get().parent.get()
return if (node.isCovered && parent.parent.get() == node.coveringNode.get()) { // node is covered and parent is checked above
// bad node
true
} else {
false
}
} else {
var transitionFired = false
if (node.parent.isPresent && node.parent.get().parent.isPresent) {
val grandParent = node.parent.get().parent.get()
if (!(node.isCovered && node.coveringNode.get() == grandParent)) return false

val state = node.parent.get().state.toString()
val bufReader = BufferedReader(StringReader(state))
var line: String? = null
try {
while ((bufReader.readLine().also { line = it }) != null) {
if (line!!.trim { it <= ' ' }
.matches("^.*\\(__id_.*__.*\\strue\\).*$".toRegex())) transitionFired = true
}
} catch (e: IOException) {
e.printStackTrace()
}
return !transitionFired // if no transition was fired (and state not changed), this is a superfluous node
} else {
return false
}
}
}

companion object {

/**
* Mainly of use for XSTS!
* Collecting nodes that look like there should be traces to it, but shouldn't ("not firing anything" nodes)
* This should most likely note come up with other formalisms. This removal is executed on them anyways.
*/
fun <S : State, A : Action> collectBadLeaves(arg: ARG<S, A>): List<ArgNode<S, A>> {
val instance = DoubleEndNodeRemover<S, A>()
val badNodes: MutableList<ArgNode<S, A>> = ArrayList()
arg.nodes.filter { obj: ArgNode<S, A> -> obj.isLeaf }.forEach { node: ArgNode<S, A> ->
if (instance.isBadLeaf(node)) {
badNodes.add(node)
}
}
return badNodes
}

fun <S : State?, A : StmtAction?> filterSuperfluousEndNode(trace: Trace<S, A>): Trace<S, A> {
if (trace.states.size > 3) {
var transitionFired = false
val size = trace.states.size
if (trace.getState(size - 1).toString() == trace.getState(size - 3).toString()) {
val bufReader = BufferedReader(StringReader(trace.getState(size - 2).toString()))
var line: String? = null
try {
while ((bufReader.readLine().also { line = it }) != null) {
if (line!!.trim { it <= ' ' }
.matches("^\\(__id_.*__.*\\strue\\)*$".toRegex())) transitionFired = true
}
} catch (e: IOException) {
e.printStackTrace()
}
}
if (!transitionFired) {
val newStates = ArrayList(trace.states)
newStates.removeAt(newStates.size - 1)
newStates.removeAt(newStates.size - 1)
val newActions = ArrayList(trace.actions)
newActions.removeAt(newActions.size - 1)
newActions.removeAt(newActions.size - 1)
return Trace.of(newStates, newActions)
} else {
return trace
}
} else {
return trace
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import hu.bme.mit.theta.analysis.*
import hu.bme.mit.theta.analysis.algorithm.*
import hu.bme.mit.theta.analysis.algorithm.arg.ArgNode
import hu.bme.mit.theta.analysis.algorithm.arg.ArgTrace
import hu.bme.mit.theta.analysis.algorithm.cegar.Abstractor
import hu.bme.mit.theta.analysis.algorithm.cegar.BasicArgAbstractor
import hu.bme.mit.theta.analysis.algorithm.tracegeneration.summary.TraceGenerationResult
import hu.bme.mit.theta.analysis.algorithm.tracegeneration.summary.AbstractSummaryBuilder
import hu.bme.mit.theta.analysis.algorithm.tracegeneration.summary.AbstractTraceSummary
Expand All @@ -15,15 +15,15 @@ import kotlin.collections.ArrayList

class TraceGenerationChecker<S : State, A : Action, P : Prec>(
private val logger: Logger,
private val abstractor: Abstractor<S, A, P>,
private val abstractor: BasicArgAbstractor<S, A, P>,
private val getFullTraces : Boolean,
) : Checker<AbstractTraceSummary<S, A>, P> {
private var traces: List<Trace<S, A>> = ArrayList()

companion object {
fun <S : State, A : Action, P : Prec> create(
logger: Logger,
abstractor: Abstractor<S, A, P>,
abstractor: BasicArgAbstractor<S, A, P>,
getFullTraces: Boolean
): TraceGenerationChecker<S, A, P> {
return TraceGenerationChecker(logger, abstractor, getFullTraces)
Expand All @@ -34,17 +34,15 @@ class TraceGenerationChecker<S : State, A : Action, P : Prec>(
logger.write(Logger.Level.SUBSTEP, "Printing prec for trace generation...\n" + System.lineSeparator())
logger.write(Logger.Level.SUBSTEP, prec.toString())

val arg = abstractor.createArg()
val arg = abstractor.createProof()
abstractor.check(arg, prec)

logger.write(Logger.Level.SUBSTEP, "ARG done, fetching traces...\n")

// TODO remove xsts specific parts

// bad node: XSTS specific thing, that the last state (last_env nodes) doubles up and the leaf is covered by the
// bad node: mostly XSTS specific thing, that the last state (last_env nodes) doubles up and the leaf is covered by the
// last_env before which is superfluous.
// Possible side effect if not handled: possibly a "non-existing leaf" and superfluous traces or just traces that are 1 longer than they should be
val badNodes = XstsDoubleEndNodeRemover.collectBadLeaves(arg)
val badNodes = DoubleEndNodeRemover.collectBadLeaves(arg)
logger.write(Logger.Level.INFO, "Number of bad nodes filtered out: ${badNodes.size}")

// leaves
val endNodes = arg.nodes.filter { obj: ArgNode<S, A> -> obj.isLeaf }
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package hu.bme.mit.theta.analysis.algorithm.tracegeneration.summary
import com.google.common.base.Preconditions.checkState
import hu.bme.mit.theta.analysis.Action
import hu.bme.mit.theta.analysis.State
import hu.bme.mit.theta.analysis.algorithm.Witness
import hu.bme.mit.theta.analysis.algorithm.Proof
import hu.bme.mit.theta.analysis.algorithm.arg.ArgEdge
import hu.bme.mit.theta.analysis.algorithm.arg.ArgNode
import hu.bme.mit.theta.analysis.algorithm.arg.ArgTrace
Expand Down Expand Up @@ -110,7 +110,7 @@ data class AbstractTraceSummary<S : State, A : Action> (
val abstractSummaryEdges : Collection<AbstractSummaryEdge<S, A>>,
val summaryNodes : Collection<AbstractSummaryNode<S, A>>,
val initNode : AbstractSummaryNode<S, A>
) : Witness {
) : Proof {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import hu.bme.mit.theta.analysis.algorithm.Result
import hu.bme.mit.theta.analysis.algorithm.Statistics
import java.util.*

class TraceGenerationResult<W : AbstractTraceSummary<S, A>, S : State, A : Action>(val summary : W) : Result<W> {
class TraceGenerationResult<Pr : AbstractTraceSummary<S, A>, S : State, A : Action>(val summary : Pr) : Result<Pr> {

override fun getWitness(): W {
override fun getProof(): Pr {
return summary
}

Expand Down
Loading

0 comments on commit 5520360

Please sign in to comment.