Skip to content

Commit

Permalink
move functions about belief from belief-system/ to belief/
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Oct 5, 2024
1 parent 5ab2000 commit 8cf3ea5
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 19 deletions.
7 changes: 3 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

> https://github.com/cicada-lang/propagator/issues/4
恢复之前实现时忽略的 check-consistent! 和 process-nogood!
`nogood/` -- global map about about nogood
`nogood/` -- `processNogood` -- should be called by `checkConsistent`

- belief-system/checkConsistent.ts

global map about about nogood
`checkConsistent` -- 恢复之前实现时忽略的 check-consistent!

propagators/binaryAmb
propagators/oneOf
Expand Down
6 changes: 3 additions & 3 deletions src/belief-system/assimilateBelief.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Belief } from "../belief/Belief.js"
import { type Nothing, isNothing } from "../nothing/Nothing.js"
import type { Belief } from "../belief/index.js"
import { isStrongerBelief } from "../belief/index.js"
import { type Nothing, isNothing } from "../nothing/index.js"
import { BeliefSystem } from "./BeliefSystem.js"
import { isStrongerBelief } from "./isStrongerBelief.js"

export function assimilateBelief<A>(
base: BeliefSystem<A>,
Expand Down
7 changes: 5 additions & 2 deletions src/belief-system/beliefSystemMerge.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import {
beliefMergeManyStillBelieved,
checkConsistent,
} from "../belief/index.js"
import { type Contradiction } from "../contradiction/index.js"
import { assimilateBelief } from "./assimilateBelief.js"
import { assimilateBeliefSystem } from "./assimilateBeliefSystem.js"
import { beliefMergeManyStillBelieved } from "./beliefMergeManyStillBelieved.js"
import { BeliefSystem } from "./BeliefSystem.js"

// Asking the belief system to deduce all the consequences of all its
Expand All @@ -16,6 +19,6 @@ export function beliefSystemMerge<A>(
): BeliefSystem<A> | Contradiction {
const candidate = assimilateBeliefSystem(content, increment)
const consequence = beliefMergeManyStillBelieved(candidate.beliefs)
// checkConsistent(consequence)
checkConsistent(consequence)
return assimilateBelief(candidate, consequence)
}
8 changes: 6 additions & 2 deletions src/belief-system/beliefSystemQuery.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { type Belief } from "../belief/index.js"
import {
beliefMergeManyStillBelieved,
checkConsistent,
type Belief,
} from "../belief/index.js"
import type { Nothing } from "../nothing/Nothing.js"
import type { BeliefSystem } from "./BeliefSystem.js"
import { assimilateBelief } from "./assimilateBelief.js"
import { beliefMergeManyStillBelieved } from "./beliefMergeManyStillBelieved.js"

export function beliefSystemQuery<A>(
beliefSystem: BeliefSystem<A>,
Expand All @@ -13,5 +16,6 @@ export function beliefSystemQuery<A>(
beliefSystem.beliefs = betterBeliefSystem.beliefs
}

checkConsistent(answer)
return answer
}
3 changes: 0 additions & 3 deletions src/belief-system/checkConsistent.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/belief-system/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ export * from "./BeliefSystem.js"
export * from "./beliefSystemEqual.js"
export * from "./beliefSystemMerge.js"
export * from "./beliefSystemQuery.js"
export * from "./checkConsistent.js"
export * from "./isStillBelieved.js"
File renamed without changes.
6 changes: 6 additions & 0 deletions src/belief/checkConsistent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Nothing } from "../nothing/index.js"
import type { Belief } from "./Belief.js"

export function checkConsistent(belief: Nothing | Belief<any>): void {
//
}
4 changes: 4 additions & 0 deletions src/belief/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ export * from "./Belief.js"
export * from "./beliefEqual.js"
export * from "./beliefMerge.js"
export * from "./beliefMergeMany.js"
export * from "./beliefMergeManyStillBelieved.js"
export * from "./checkConsistent.js"
export * from "./isStillBelieved.js"
export * from "./isStrongerBelief.js"
File renamed without changes.
File renamed without changes.
4 changes: 1 addition & 3 deletions src/examples/barometer-belief-system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import {
BeliefSystem,
beliefSystemEqual,
beliefSystemQuery,
bringIn,
kickOut,
} from "../belief-system/index.js"
import { Belief, beliefEqual } from "../belief/index.js"
import { Belief, beliefEqual, bringIn, kickOut } from "../belief/index.js"
import { Cell, patch } from "../cell/index.js"
import { theContradiction } from "../contradiction/index.js"
import { Interval, intervalAlmostEqual, isInterval } from "../interval/index.js"
Expand Down

0 comments on commit 8cf3ea5

Please sign in to comment.