Creates a dot graph for a process

@param StateCollection $stateCollection
@return string A dot graph
430808
public function renderDot(StateCollection $stateCollection)
    {
        // define the graph
        $graph = 'digraph ' . 'test'
            . ' { dpi="56";compound="true";fontname="Arial";margin="";nodesep="0.6";rankdir="TD";ranksep="0.4";'
            . PHP_EOL;

        // add all states to the graph
        foreach ($stateCollection as $state) {
            $nodeRenderer = $this->getNodeRendererByStateName($state->getKey());
            $graph .= ' ' . $nodeRenderer->render($state);
        }

        // add all transitions to the graph
        foreach ($stateCollection as $state) {
            $nodeRenderer = $this->getTransitionRendererByStateName($state->getKey());
            $graph .= ' ' . $nodeRenderer->render($state);
        }

        $graph .= '}' . PHP_EOL;


        return $graph;
    }
1355164
private function compileStaticPrefixCollection(StaticPrefixCollection $tree, \stdClass $state, int $prefixLen = 0): string
    {
        $code = '';
        $prevRegex = null;
        $routes = $tree->getRoutes();

        /**
         * @var Route $route
         */
        foreach ($routes as $i => $route) {
            if ($route instanceof StaticPrefixCollection) {
                $prevRegex = null;
                $prefix = substr($route->getPrefix(), $prefixLen);
                $state->mark += \strlen($rx = "|{$prefix}(?");
                $code .= "\n                .".self::export($rx);
                $state->regex .= $rx;
                $code .= $this->indent($this->compileStaticPrefixCollection($route, $state, $prefixLen + \strlen($prefix)));
                $code .= "\n                .')'";
                $state->regex .= ')';
                ++$state->markTail;
                continue;
            }

            list($name, $regex, $vars, $route) = $route;
            $compiledRoute = $route->compile();

            if ($compiledRoute->getRegex() === $prevRegex) {
                $state->switch = substr_replace($state->switch, $this->compileRoute($route, $name)."\n", -19, 0);
                continue;
            }

            $state->mark += 3 + $state->markTail + \strlen($regex) - $prefixLen;
            $state->markTail = 2 + \strlen($state->mark);
            $rx = sprintf('|%s(*:%s)', substr($regex, $prefixLen), $state->mark);
            $code .= "\n                    .".self::export($rx);
            $state->regex .= $rx;

            if (!\is_array($next = $routes[1 + $i] ?? null) || $regex !== $next[1]) {
                $prevRegex = null;
                $defaults = $route->getDefaults();

                $state->default .= sprintf(
                    "%s => array(%s, %s, %s),\n",
                    $state->mark,
                    self::export($name),
                    sprintf(
                        'new Route(%s, %s, %s, %s, %s)',
                        self::export($route->getPattern()),
                        self::export($route->getCallback()),
                        self::export($route->getDefaults() + $defaults),
                        self::export($route->getRequirements()),
                        self::export($route->getOptions())
                    ),
                    self::export($vars)
                );
            } else {
                $prevRegex = $compiledRoute->getRegex();
                $combine = '            $matches = array(';
                foreach ($vars as $j => $m) {
                    $combine .= sprintf('%s => $matches[%d] ?? null, ', self::export($m), 1 + $j);
                }
                $combine = $vars ? substr_replace($combine, ");\n\n", -2) : '';

                $state->switch .= <<<EOF
        case {$state->mark}:
{$combine}{$this->compileRoute($route, $name)}
            break;

EOF;
            }
        }

        return $code;
    }
1118710
public function postProcess(&$state)
    {

        $loneMarkers = [];
        $delimiters = &$state->delimiters;
        $max = count($state->delimiters);

        for ($i = 0; $i < $max; $i++) {
            $startDelim = &$delimiters[$i];

            if ($startDelim->marker !== '~') {
                continue;
            }

            if ($startDelim->end === -1) {
                continue;
            }

            $endDelim = $delimiters[$startDelim->end];

            $token         = $state->tokens[$startDelim->token];
            $token->type    = 's_open';
            $token->tag     = 's';
            $token->nesting = 1;
            $token->markup  = '~~';
            $token->content = '';

            $token         = $state->tokens[$endDelim->token];
            $token->type    = 's_close';
            $token->tag     = 's';
            $token->nesting = -1;
            $token->markup  = '~~';
            $token->content = '';

            if ($state->tokens[$endDelim->token - 1]->type === 'text' &&
                $state->tokens[$endDelim->token - 1]->content === '~') {

                $loneMarkers[] = $endDelim->token - 1;
            }
        }

        // If a marker sequence has an odd number of characters, it's splitted
        // like this: `~~~~~` -> `~` + `~~` + `~~`, leaving one marker at the
        // start of the sequence.
        //
        // So, we have to move all those markers after subsequent s_close tags.
        //
        while (count($loneMarkers)) {
            $i = array_pop($loneMarkers);
            $j = $i + 1;

            while ($j < count($state->tokens) && $state->tokens[$j]->type === 's_close') {
                $j++;
            }

            $j--;

            if ($i !== $j) {
                $token = $state->tokens[$j];
                $state->tokens[$j] = $state->tokens[$i];
                $state->tokens[$i] = $token;
            }
        }
    }
141254
public function logCollectorStates()
    {
        $url = self::makeUrl();
        $result = array();
        try {
            $response = $this->service->prepAndSend($url, array(200), "GET", null, true);
            $responseObject = json_decode($response);

            foreach ($responseObject->CollectorSettingsList as $lcs) {
                $result[] = LogCollectorSettings::createFromJSON($lcs);
            }

            /*
             * For now a facade has been created over this REST endpoint to return an empty array
             * in the case that we get a 404 with the message "Resource collectors not found"
             */
        } catch (RESTRequestException $e) {
            if ($e->message == "Resource collectors not found" && $e->statusCode == 404) {
                return $result;
            } else {
                throw $e;
            }
        }
        return $result;
    }
1129506
public static function create(RouteCollection $routes): self
    {
        $factory = new PathPatternFactory();
        $compiler = new MultiPatternCompiler($factory);

        return new self($routes, $compiler);
    }
553464
function ClientModelDocItemsController($state) {
    var vm = this;

    // the selected item id
    var curClientModelDocId = null;

    // check if this item is selected
    vm.isSelected = isSelected;
    // switch to the detail state
    vm.showInDetails = showInDetails;

    /**
     * Check if the passed item is the current selected item
     *
     * @param {Object} clientModelDoc - The object to check for selection
     */
    function isSelected(clientModelDoc) {
      return curClientModelDocId === clientModelDoc._id;
    }

    /**
     * Open the detail state with the selected item
     *
     * @param {Object} clientModelDoc - The clientModelDoc to edit
     */
    function showInDetails(clientModelDoc) {
      curClientModelDocId = clientModelDoc._id;
      $state.go('clientModelDoc.list.detail', {'id': curClientModelDocId});
    }
  }
547758
def dot(self):
        
        buff = "digraph graphname {"
        for fro in self.edges:
            for to in self.edges[fro]:
                buff += "%s -> %s;" % (fro, to)
        buff += "}"
        return buff
1309556
private function depthFirstScan(StateMap $states, StateInterface $state, StateSet $visited_states): StateSet
    {
        if ($visited_states->contains($state)) {
            return $visited_states;
        }
        $visited_states->add($state);
        $child_states = array_map(
            function (TransitionInterface $transition) use ($states): StateInterface {
                return $states->get($transition->getTo());
            },
            $this->get($state->getName())->toArray()
        );
        foreach ($child_states as $child_state) {
            $visited_states = $this->depthFirstScan($states, $child_state, $visited_states);
        }
        return $visited_states;
    }
337356
private function groupStaticRoutes(RouteCollection $collection): array
    {
        $staticRoutes = $dynamicRegex = [];
        $dynamicRoutes = new RouteCollection();

        foreach ($collection->all() as $name => $route) {
            $compiledRoute = $route->compile();
            $regex = $compiledRoute->getRegex();

            if (!$compiledRoute->getVariables()) {
                $pattern = $route->getPattern();

                foreach ($dynamicRegex as $rx) {
                    if (preg_match($rx, $pattern)) {
                        $dynamicRegex[] = $regex;
                        $dynamicRoutes->add($name, $route);
                        continue 2;
                    }
                }

                $staticRoutes[$pattern][$name] = $route;
            } else {
                $dynamicRegex[] = $regex;
                $dynamicRoutes->add($name, $route);
            }
        }

        return [$staticRoutes, $dynamicRoutes];
    }
1326579
private function getChildResult(GameState $stateAfterMove): TraversalResult
    {
        $nextPlayerIsFriendly = $stateAfterMove->getNextPlayer()->isFriendsWith($this->objectivePlayer);
        $nextDecisionPoint = new static(
            $this->objectivePlayer,
            $stateAfterMove,
            $this->depthLeft - 1,
            $nextPlayerIsFriendly ? NodeType::MAX() : NodeType::MIN(),
            clone $this->alphaBeta
        );
        return $nextDecisionPoint->traverseGameTree();
    }
705523
private function renderTransitionEdges(StateMachineInterface $state_machine, Map $node_id_map): array
    {
        $edges = [];
        foreach ($state_machine->getStateTransitions() as $state_name => $state_transitions) {
            foreach ($state_transitions as $transition) {
                $from_node = $node_id_map->get($transition->getFrom());
                $to_node = $node_id_map->get($transition->getTo());
                $transition_label = (string)$transition;
                $attributes = sprintf('label="%s" ', trim(addslashes($transition_label)));
                $attributes .= 'fontname="Arial" fontsize="12" fontcolor="#7f8c8d" color="#2ecc71"';
                $edges[] = sprintf('%s -> %s [%s];', $from_node, $to_node, $attributes);
            }
        }
        return $edges;
    }
481579
def to_dot(self, path: str, title: Optional[str] = None):
        
        g = graphviz.Digraph(format='svg')
        g.node('fake', style='invisible')
        for state in self._states:
            if state == self._initial_state:
                if state in self._accepting_states:
                    g.node(str(state), root='true',
                           shape='doublecircle')
                else:
                    g.node(str(state), root='true')
            elif state in self._accepting_states:
                g.node(str(state), shape='doublecircle')
            else:
                g.node(str(state))

        g.edge('fake', str(self._initial_state), style='bold')
        for start in self._transition_function:
            for symbol, end in self._transition_function[start].items():
                g.edge(str(start),
                       str(end),
                       label=str(symbol))

        if title:
            g.attr(label=title)
            g.attr(fontsize='20')

        g.render(filename=path)
        return
1189063
public function dump(StateMachineEntity $stateMachine, array $options = []): string
    {
        $places = $this->findStates($stateMachine);
        $edges = $this->findEdges($stateMachine);

        $options = array_replace_recursive(self::$defaultOptions, $options);

        return $this->startDot($options)
            . $this->addStates($places)
            . $this->addEdges($edges)
            . $this->endDot();
    }
417248
public function generate(TerminalStateInterface $currentState, TerminalState $desiredState) {

        // get a state object with anything that is changing
        $changes = $currentState->findChanges($desiredState);

        // if an object is returned, then just positive changes are occurring
        if ($changes) {
            
            // if there are really no changes
            if ($changes->isClear()) {

                // return an empty string
                return "";
               
            // there are some changes
            } else {

                // generate the sequence for the things that are actually changing
                return $this->generateSequence($changes, false);

            }


        // if null is returned, then something is getting turned off
        } else {

            // must generate a sequence with a clear
            return $this->generateSequence($desiredState, true);
        }



    }
108390
public function createStatemachine($subject)
    {
        $process = $this->processDetector->detectProcess($subject);
        if ($this->stateNameDetector) {
            $stateName = $this->stateNameDetector->detectCurrentStateName($subject);
        } else {
            $stateName = null;
        }
        if ($this->mutexFactory) {
            $mutex = $this->mutexFactory->createMutex($subject);
        } else {
            $mutex = null;
        }

        $statemachine = new Statemachine($subject, $process, $stateName, $this->transitonSelector, $mutex);

        foreach ($this->statemachineObserver as $observer) {
            $statemachine->attach($observer);
        }

        return $statemachine;
    }
1104854
public String getAstDotGraph() throws IOException {
    if (jsRoot != null) {
      ControlFlowAnalysis cfa = new ControlFlowAnalysis(this, true, false);
      cfa.process(null, jsRoot);
      return DotFormatter.toDot(jsRoot, cfa.getCfg());
    } else {
      return "";
    }
  }
131150
protected function createState(array $state_definition)
    {
        $state_implementor = isset($state_definition['class']) ? $state_definition['class'] : State::CLASS;
        $this->loadStateImplementor($state_implementor);

        $state = $this->service_locator->make(
            $state_implementor,
            [
                ':name' => $state_definition['name'],
                ':type' => $state_definition['type'],
                ':options' => $state_definition['options'],
            ]
        );

        if (!$state instanceof StateInterface) {
            throw new RuntimeError(
                sprintf(
                    'Configured implementor "%s" for state "%s" must implement: %s',
                    $state_implementor,
                    $state_definition['name'],
                    StateInterface::CLASS
                )
            );
        }

        return $state;
    }