class_docstr: Records progress through the set of linear nonbranching constraints with gaps.
class_docstr_tok: ["Records","progress","through","the","set","of","linear","nonbranching","constraints","with","gaps","."]
docstr: Reads in a token and advances the state. Here's how it works.
  
  We can advance to the next state if:
  - there is a matching child
  - its path isn't blocked
  
  A path is blocked when all constraints that are descendants of
  that node have already been generated, in the current state.
  
  If we are not able to advance from the current state, we "fall
  off the graph" and return to the root state. There, we again
  try to advance, checking the same criteria.
  
  In any case, when falling off the graph, we need to do some
  bookkeeping. We:
  - check whether any constraints were met (all prefixes of
    current state)
  - if one is found, mark it as completed
  - adjust visited nodes accordingly
docstr_tok: ["Reads","in","a","token","and","advances","the","state",".","Here","'s","how","it","works",".","We","can","advance","to","the","next","state","if",":","-","there","is","a","matching","child","-","its","path","is","n't","blocked","A","path","is","blocked","when","all","constraints","that","are","descendants","of","that","node","have","already","been","generated",",","in","the","current","state",".","If","we","are","not","able","to","advance","from","the","current","state",",","we","``","fall","off","the","graph","''","and","return","to","the","root","state",".","There",",","we","again","try","to","advance",",","checking","the","same","criteria",".","In","any","case",",","when","falling","off","the","graph",",","we","need","to","do","some","bookkeeping",".","We",":","-","check","whether","any","constraints","were","met","(","all","prefixes","of","current","state",")","-","if","one","is","found",",","mark","it","as","completed","-","adjust","visited","nodes","accordingly"]
code: def advance(self, token: int):
      """Reads in a token and advances the state. Here's how it works.
  
      We can advance to the next state if:
      - there is a matching child
      - its path isn't blocked
  
      A path is blocked when all constraints that are descendants of
      that node have already been generated, in the current state.
  
      If we are not able to advance from the current state, we "fall
      off the graph" and return to the root state. There, we again
      try to advance, checking the same criteria.
  
      In any case, when falling off the graph, we need to do some
      bookkeeping. We:
      - check whether any constraints were met (all prefixes of
        current state)
      - if one is found, mark it as completed
      - adjust visited nodes accordingly
      """
      token = int(token)
      # print(f"{self} ADVANCE({token}) {self.sequence} -> ", end="")
  
      if self.finished:
          # Accept anything
          next_state = self.copy()
  
      elif self.sequence[self.state + 1] == token:
          # Advance to the next token
          next_state = OrderedConstraintState(
              self.sequence, self.state + 1
          )
  
      elif self.sequence.endpoints[self.state]:
          # Accept anything between constraints (*)
          next_state = self.copy()
  
      elif token == self.sequence[0]:
          # Start over having generated the first token
          next_state = OrderedConstraintState(self.sequence, 0)
      else:
          # Start over from the root
          next_state = OrderedConstraintState(self.sequence, -1)
  
      return next_state
  
imports: from collections import Counter
  from typing import List, Optional, Set, Tuple
  import torch
label_desc: Use image node_id 15 for calling the OrderedConstraintState obj's underlying member method code with example usage: obj.advance(token) and returns: next_state