Thursday, December 8, 2011

opinions.go

package main

import "time"

func main() {

  // FIXME: This is not thread-safe. Then again, that just makes it
  // interesting.

  // All opinions strengthen over time, given no facts.
  go func() {
    time.Sleep(24 * 60 * 60 * 1000000000) // 1 day
    for _, op := range opinions {
      op.strengthen(stuckInMyWaysDelta) // presumably >0 but small
      // NOTE: stuckInMyWaysDelta keeps getting increased each time we
      // release. This is becoming a problem.
    }
  }()

  // Accept incoming facts, adjust opinions accordingly. Congruent facts
  // strengthen opinions, incongruent facts weaken opinions.
  go func() {
    for f := range factChan {
      for _, op := range opinions {
        agree, value := op.arbitrateFact(f)
        if !agree {
          value = -value
        }
        relevancy := op.factRelevancy(f) // >= 0.0
        op.strengthen(value * relevancy)
      }
    }
  }()

  // Contrariness loop:
  // Disabled if pleasant or uninteresting.
  if !pleasant || interesting {
    go func() {
      // For each incoming opinion (from another program), reconcile with
      // existing, local opinions. Unlike facts, opinions are strengthened
      // because of disagreement, not agreement.
      for inOp := range opinionChan {
        for _, op := range opinions {
          agree, value := op.arbitrate(inOp)
          if agree {
            value = -value
          }
          value *= howMuchICareCoefficient // see social.go
          relevancy := op.relevancy(inOp) // >= 0.0
          op.strengthen(value * relevancy)
        }
      }
    }()
  }

  go inspireNewOpinions()
  go garbageCollectStaleOpinions()

  metabolize() // doesn't return until SIGTERM
}

2 comments:

Anonymous said...

rejecting of facts or opinions due to failure to comply with current paradigm.
please include this upgrade in opinion.go.2

Craig Brandenburg said...

Anonymous— Good catch! Too bad JEC doesn't have a bug-tracking system.