Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions main/demand/demand.metta
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,59 @@
)
(= (getDemandByName $space $name) (match $space (demand $name $x) (demand $name $x)))


(= (demandDecay $space $demand $value)
(let* (
($oldValue (match $space (demand $demand $oldValue) $oldValue))
($newValue (- $oldValue $value))
)
(if (>= $newValue 0)
(setDemandValue $space $demand $newValue)
(let* (($demandAtom (match $space (demand $demand $oldValue) (demand $demand $oldValue)))
(() (remove-atom $space $demandAtom))
)
(
(remove-atom $space (skip $demand))
)
)
)
))

; New function to apply decay only to skipped demands
(= (decaySkippedDemands $space $decayValue)
(let* (
($skippedDemandNames (collapse (match $space (skip $x) $x)))
($skippedDemands (collapse (match $space (demand $x $value) (demand $x $value))))
)
(if (== (size-atom $skippedDemands) 0 )
(There is no skipped demand)
(demandDecay $space (superpose $skippedDemandNames) $decayValue)
))
)
; New function to apply decay to all demands (both enabled and skipped)
(= (decayAllDemands $space $decayValue)
(let* (
($allDemands (getAllDemands $space))
($demandNames (collapse (match $space (demand $x $_) $x)))
)
(if (== (size-atom $allDemands) 0 )
(No demands in the space)
(demandDecay $space (superpose $demandNames) $decayValue)
))
)

; New function to apply different decay rates to enabled vs skipped demands
(= (decayDemandsWithDifferentRates $space $enabledDecayRate $skippedDecayRate)
(let* (
($enabledDemandNames (getEnabledDemands $space))
($enabledDemands (collapse (unify $enabledDemandNames (demand $x $_) $x ())))
($skippedDemandNames (collapse (match $space (skip $x) $x)))
($_ (decaySkippedDemands $space $skippedDecayRate))
)
(if (== (size-atom $enabledDemands) 0)
(There is no skipped demand)
(demandDecay $space (superpose $enabledDemands) $enabledDecayRate)

))
)

11 changes: 11 additions & 0 deletions main/demand/tests/demand-test.metta
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
!(skipDemand &demandSpace competence)

!(assertEqual (getDemandByName &demandSpace energy) (demand energy 0.6))

!(assertEqual (exists-In &demandSpace (demand energy 0.6)) True)
!(assertEqual (exists-In &demandSpace (demand competence 0.2)) True)
!(assertEqual (getAllDemands &demandSpace ) ((demand energy 0.6) (demand affiliation 0.5) (demand competence 0.2)))
Expand All @@ -24,3 +25,13 @@
!(assertEqual (fetch-demand &demandSpace energy) (demand energy 0.8))
!(assertEqual (fetch-demand-val &demandSpace energy) 0.8)
!(assertEqual (getEnabledDemands &demandSpace) ((demand energy 0.8) (demand affiliation 0.5) ))

!(bind! &decayspace (new-space))
!(addDemand &decayspace energy 0.6)
!(addDemand &decayspace affiliation 0.5)
!(addDemand &decayspace competence 0.4)
!(skipDemand &decayspace competence)
!(getEnabledDemands &decayspace)
!(decaySkippedDemands &decayspace 0.1)
!(decayAllDemands &decayspace 0.05)
!(get-atoms &decayspace)