Skip to content

Commit 21ddc74

Browse files
committed
report more solving stats
1 parent ca60ad8 commit 21ddc74

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

src/commonMain/kotlin/ai/hypergraph/kaliningraph/CommonUtils.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,14 @@ class KBitSet(val n: Int) {
133133
constructor(n: Int, v: Collection<Int>) : this(n) { v.forEach { set(it) } }
134134
// Each element of 'data' holds 64 bits, covering up to n bits total.
135135
private val data = LongArray((n + 63) ushr 6)
136-
var set = mutableSetOf<Int>()
137-
var modified = false
136+
// var set = mutableSetOf<Int>()
137+
// var modified = false
138138

139139
fun set(index: Int) {
140-
modified = true
140+
// modified = true
141+
// set += index
141142
val word = index ushr 6
142143
val bit = index and 63
143-
set += index
144144
data[word] = data[word] or (1L shl bit)
145145
}
146146

src/commonMain/kotlin/ai/hypergraph/kaliningraph/parsing/SetValiant.kt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,25 @@ fun CFG.isValid(str: List<Σᐩ>): Bln =
7777
dp[0][str.size][bindex[START_SYMBOL]]
7878
}
7979

80-
fun CFG.isValidAlt(str: List<Σᐩ>): Bln =
81-
if (str.size == 1) checkUnitWord(str.first()).isNotEmpty()
82-
else {
83-
val dp = Array(str.size + 1) { Array(str.size + 1) { KBitSet(nonterminals.size) } }
84-
str.map {
85-
if (it == "_" || tmMap[it] == null) (0..<nonterminals.size).toList()
86-
else tmToVidx[tmMap[it]!!] }.forEachIndexed { i, it -> it.forEach { vidx -> dp[i][i+1].set(vidx) } }
87-
88-
for (dist: Int in 0 until dp.size) {
89-
for (iP: Int in 0 until dp.size - dist) {
90-
val p = iP
91-
val q = iP + dist
92-
val appq = p..q
93-
for (r in appq) for (lt in dp[p][r].set) for (rt in dp[r][q].set)
94-
bimap.R2LHSI[lt][rt].forEach { dp[p][q].set(it) }
95-
}
96-
}
97-
dp[0][str.size][bindex[START_SYMBOL]]
98-
}
80+
//fun CFG.isValidAlt(str: List<Σᐩ>): Bln =
81+
// if (str.size == 1) checkUnitWord(str.first()).isNotEmpty()
82+
// else {
83+
// val dp = Array(str.size + 1) { Array(str.size + 1) { KBitSet(nonterminals.size) } }
84+
// str.map {
85+
// if (it == "_" || tmMap[it] == null) (0..<nonterminals.size).toList()
86+
// else tmToVidx[tmMap[it]!!] }.forEachIndexed { i, it -> it.forEach { vidx -> dp[i][i+1].set(vidx) } }
87+
//
88+
// for (dist: Int in 0 until dp.size) {
89+
// for (iP: Int in 0 until dp.size - dist) {
90+
// val p = iP
91+
// val q = iP + dist
92+
// val appq = p..q
93+
// for (r in appq) for (lt in dp[p][r].set) for (rt in dp[r][q].set)
94+
// bimap.R2LHSI[lt][rt].forEach { dp[p][q].set(it) }
95+
// }
96+
// }
97+
// dp[0][str.size][bindex[START_SYMBOL]]
98+
// }
9999

100100
fun CFG.corner(str: Σᐩ) =
101101
solveFixedpoint(str.tokenizeByWhitespace())[0].last().map { it.root }.toSet()

src/commonTest/kotlin/ai/hypergraph/kaliningraph/parsing/SetValiantTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ class SetValiantTest {
417417
@Test
418418
fun testUTMRepresentationEquivalence() {
419419
with(vanillaS2PCFG) {
420+
println("SIZE: ${nonterminals.size}")
420421
val str = "NAME = NAME ( NAME , NUMBER ) . NAME ( ) NEWLINE NAME = NAME . NAME NEWLINE NAME = STRING . NAME ( NAME for NAME in NAME if NAME . NAME ( ) ) NEWLINE NAME ( NAME ) NEWLINE".tokenizeByWhitespace()
421422
// with("""P -> ( P ) | P P | ε""".parseCFG()) {
422423
// val str = "( ( ) ( ) ) ( ) ( ( ( ) ) ( ) ) ( ( ( ) ) ) ( ) ( ) ( ) ( ( ) ( ) ) ( ) ( ( ) ( ) ) ( ) ( ( ) ( ) ) ( )".tokenizeByWhitespace()

0 commit comments

Comments
 (0)