Beispiel #1
0
Expression::Expression(std::unique_ptr<Expression> A,
                       ExpressionType type,
                       NfaStates& states)
{
  //   m_Type = type;
  m_Left = std::move(A);
  m_Right = nullptr;

  if (type == ExpressionTypeZeroOrMore)
  {
    m_StartState = states.New();
    m_EndState = states.New();
    AddTransition(m_StartState, m_Left->m_StartState);
    AddTransition(m_StartState, m_EndState);
    AddTransition(m_Left->m_EndState, m_Left->m_StartState);
    AddTransition(m_Left->m_EndState, m_EndState);
    /// A*
    ///                    e
    ///              |----------|
    ///              |          |
    ///           |--|----------|--|
    ///        e  |  V     A    |  |   e
    ///  ( )------->( ) -----> ( )-------(O)
    ///   |       |----------------|      ^
    ///   |                               |
    ///   |--------------------------------
  }
  else if (type == ExpressionTypeOptional)
  {
    m_StartState = states.New();
    m_EndState = states.New();
    AddTransition(m_StartState, m_Left->m_StartState);
    AddTransition(m_StartState, m_EndState);
    AddTransition(m_Left->m_EndState, m_EndState);
  }
  else if (type == ExpressionTypeOneOrMore)
  {
    m_StartState = states.New();
    m_EndState = states.New();
    AddTransition(m_StartState, m_Left->m_StartState);
    AddTransition(m_EndState, m_Left->m_StartState);
    AddTransition(m_Left->m_EndState, m_EndState);
    //revisar
  }
  else
  {
    assert(false);
  }
}
Beispiel #2
0
Expression::Expression(const std::wstring& s, NfaStates& states, TransitionSet& symbols) : m_ch(0)
{
  m_LiteralString = s;

  //  m_Type = ExpressionTypeSingle;
  m_Left = nullptr;
  m_Right = nullptr;

  //(start) -a-> () -b-> ....() -c-> (end)
  //cria uma cadeia de "ands" com cada caracteres o start e end sao as extremidades

  m_StartState = states.New();
  m_EndState = 0;
  NfaState* state = m_StartState;

  for (size_t i = 0 ; i < s.size(); i++)
  {
    if (i == 0)
      m_ch = Transition(s[i]);

    NfaState* pNew = states.New();
    Transition ch(s[i]);
    symbols.insert(ch);
    AddTransition(state, ch, pNew);
    state = pNew;
  }

  m_EndState = state;
  //AddTransition(state, m_EndState);

}
TFiniteAutomaton& TFiniteAutomaton::Iterate() {
    // FIXME: expected exactly one final state
    const size_t mySize = Size(), myFinal = *FinalStates.begin();
    Resize(mySize + 2);

    AddTransition(mySize, StartState);
    AddTransition(myFinal, mySize + 1);
    AddTransition(myFinal, StartState);
    AddTransition(mySize, mySize + 1);

    SetStartState(mySize);
    SetFinalState(myFinal, false);
    SetFinalState(mySize + 1);

    return *this;
}
TFiniteAutomaton& TFiniteAutomaton::operator += (const TFiniteAutomaton& rhs) {
    // FIXME: expected exactly one final state
    const size_t mySize = Size(), myFinal = *FinalStates.begin();
    Import(rhs);  // import final states along with transitions
    AddTransition(myFinal, mySize + rhs.StartState);
    SetFinalState(myFinal, false);
    return *this;
}
TFiniteAutomaton& TFiniteAutomaton::operator |= (const TFiniteAutomaton& rhs) {
    // FIXME: expected exactly one final state from both the automata
    const size_t mySize = Size(), myFinal = *FinalStates.begin();
    Import(rhs);
    const size_t newSize = Size();
    Resize(newSize + 2);

    AddTransition(newSize, StartState);
    AddTransition(newSize, mySize + rhs.StartState);
    AddTransition(myFinal, newSize + 1);
    AddTransition(mySize + *rhs.FinalStates.begin(), newSize + 1);

    SetStartState(newSize);
    SetFinalState(myFinal, false);
    SetFinalState(mySize + *rhs.FinalStates.begin(), false);
    SetFinalState(newSize + 1);

    return *this;
}
Beispiel #6
0
	void CSimPetriDoc::CreateOMPDoc(CString pathToFile)
	{
		ompMode = TRUE;
		delete stepper;

		//Créer le squelette
		const std::wstring pathName(pathToFile);
		const wchar_t *separator = _T(";");
		omp::Reader dataReader(pathName, separator);
		omp::PetriOMP omp(dataReader, skeleton);

		//Créer le stepper
		stepper = new pm::TrackableStepper(&skeleton, &timer);

		//Ajouter les places
		double radiusPlaces = ((double)(3)/4) * min(size.cx/2, size.cy/2);
		pm::Places places = skeleton.getPlaces();
		unsigned index = 0;
		for(auto it=places.begin(); it!=places.end(); ++it)
		{
			int x(size.cx/2 + radiusPlaces*std::cos(((double)(index)/places.size())*2*3.14));
			int y(-size.cy/2 + radiusPlaces*std::sin(((double)(index)/places.size())*2*3.14));
			shapesMap.insert(std::make_pair(*it, AddPlace(Point(x,y), *it)));
			++index;
		}

		//Ajouter les transitions
		double radiusTrans = ((double)(1)/2) * min(size.cx/2, size.cy/2);
		pm::Transitions transitions = skeleton.getTransitions();
		index = 0;
		for(auto it=transitions.begin(); it!=transitions.end(); ++it)
		{
			Point source = shapesMap.at((*it)->getInputArcs().front()->getSourceNode())->GetPosition();
			Point end = shapesMap.at((*it)->getOutputArcs().front()->getEndNode())->GetPosition();
			//int x(size.cx/2 + radiusTrans*std::cos(((double)(index)/transitions.size())*2*3.14));
			//int y(-size.cy/2 + radiusTrans*std::sin(((double)(index)/transitions.size())*2*3.14));
			shapesMap.insert(std::make_pair(*it, AddTransition(Geometry::MiddlePoint(source, end), *it)));
			++index;
		}

		//Ajouter les arcs
		pm::Arcs arcs = skeleton.getArcs();
		std::vector<Point> nullVector;
		for(auto it=arcs.begin(); it!=arcs.end(); ++it)
			AddArc(shapesMap.at((*it)->getSourceNode()),
			shapesMap.at((*it)->getEndNode()),
			nullVector,
			*it);
	}
Beispiel #7
0
Expression::Expression(const Transition& ch, NfaStates& states) : m_ch(ch)
{
  //   m_Type = ExpressionTypeSingle;
  m_Left = nullptr;
  m_Right = nullptr;
  /// e
  /// |----------------|
  /// |        e       |
  /// | ( ) -----> (O) |
  /// |----------------|
  /// A
  /// |----------------|
  /// |        A       |
  /// | ( ) -----> (O) |
  /// |----------------|
  m_StartState = states.New();
  m_EndState = states.New();
  AddTransition(m_StartState, ch, m_EndState);
}
Beispiel #8
0
CNetClient::CNetClient(CGame* game) :
	m_Session(NULL),
	m_UserName(L"anonymous"),
	m_GUID(ps_generate_guid()), m_HostID((u32)-1), m_ClientTurnManager(NULL), m_Game(game),
	m_GameAttributes(game->GetSimulation2()->GetScriptInterface().GetContext()),
	m_LastConnectionCheck(0)
{
	m_Game->SetTurnManager(NULL); // delete the old local turn manager so we don't accidentally use it

	void* context = this;

	JS_AddExtraGCRootsTracer(GetScriptInterface().GetJSRuntime(), CNetClient::Trace, this);

	// Set up transitions for session
	AddTransition(NCS_UNCONNECTED, (uint)NMT_CONNECT_COMPLETE, NCS_CONNECT, (void*)&OnConnect, context);

	AddTransition(NCS_CONNECT, (uint)NMT_SERVER_HANDSHAKE, NCS_HANDSHAKE, (void*)&OnHandshake, context);

	AddTransition(NCS_HANDSHAKE, (uint)NMT_SERVER_HANDSHAKE_RESPONSE, NCS_AUTHENTICATE, (void*)&OnHandshakeResponse, context);

	AddTransition(NCS_AUTHENTICATE, (uint)NMT_AUTHENTICATE_RESULT, NCS_INITIAL_GAMESETUP, (void*)&OnAuthenticate, context);

	AddTransition(NCS_INITIAL_GAMESETUP, (uint)NMT_GAME_SETUP, NCS_PREGAME, (void*)&OnGameSetup, context);

	AddTransition(NCS_PREGAME, (uint)NMT_CHAT, NCS_PREGAME, (void*)&OnChat, context);
	AddTransition(NCS_PREGAME, (uint)NMT_READY, NCS_PREGAME, (void*)&OnReady, context);
	AddTransition(NCS_PREGAME, (uint)NMT_GAME_SETUP, NCS_PREGAME, (void*)&OnGameSetup, context);
	AddTransition(NCS_PREGAME, (uint)NMT_PLAYER_ASSIGNMENT, NCS_PREGAME, (void*)&OnPlayerAssignment, context);
	AddTransition(NCS_PREGAME, (uint)NMT_KICKED, NCS_PREGAME, (void*)&OnKicked, context);
	AddTransition(NCS_PREGAME, (uint)NMT_CLIENT_TIMEOUT, NCS_PREGAME, (void*)&OnClientTimeout, context);
	AddTransition(NCS_PREGAME, (uint)NMT_CLIENT_PERFORMANCE, NCS_PREGAME, (void*)&OnClientPerformance, context);
	AddTransition(NCS_PREGAME, (uint)NMT_GAME_START, NCS_LOADING, (void*)&OnGameStart, context);
	AddTransition(NCS_PREGAME, (uint)NMT_JOIN_SYNC_START, NCS_JOIN_SYNCING, (void*)&OnJoinSyncStart, context);

	AddTransition(NCS_JOIN_SYNCING, (uint)NMT_CHAT, NCS_JOIN_SYNCING, (void*)&OnChat, context);
	AddTransition(NCS_JOIN_SYNCING, (uint)NMT_GAME_SETUP, NCS_JOIN_SYNCING, (void*)&OnGameSetup, context);
	AddTransition(NCS_JOIN_SYNCING, (uint)NMT_PLAYER_ASSIGNMENT, NCS_JOIN_SYNCING, (void*)&OnPlayerAssignment, context);
	AddTransition(NCS_JOIN_SYNCING, (uint)NMT_CLIENT_TIMEOUT, NCS_JOIN_SYNCING, (void*)&OnClientTimeout, context);
	AddTransition(NCS_JOIN_SYNCING, (uint)NMT_CLIENT_PERFORMANCE, NCS_JOIN_SYNCING, (void*)&OnClientPerformance, context);
	AddTransition(NCS_JOIN_SYNCING, (uint)NMT_GAME_START, NCS_JOIN_SYNCING, (void*)&OnGameStart, context);
	AddTransition(NCS_JOIN_SYNCING, (uint)NMT_SIMULATION_COMMAND, NCS_JOIN_SYNCING, (void*)&OnInGame, context);
	AddTransition(NCS_JOIN_SYNCING, (uint)NMT_END_COMMAND_BATCH, NCS_JOIN_SYNCING, (void*)&OnJoinSyncEndCommandBatch, context);
	AddTransition(NCS_JOIN_SYNCING, (uint)NMT_LOADED_GAME, NCS_INGAME, (void*)&OnLoadedGame, context);

	AddTransition(NCS_LOADING, (uint)NMT_CHAT, NCS_LOADING, (void*)&OnChat, context);
	AddTransition(NCS_LOADING, (uint)NMT_GAME_SETUP, NCS_LOADING, (void*)&OnGameSetup, context);
	AddTransition(NCS_LOADING, (uint)NMT_PLAYER_ASSIGNMENT, NCS_LOADING, (void*)&OnPlayerAssignment, context);
	AddTransition(NCS_LOADING, (uint)NMT_CLIENT_TIMEOUT, NCS_LOADING, (void*)&OnClientTimeout, context);
	AddTransition(NCS_LOADING, (uint)NMT_CLIENT_PERFORMANCE, NCS_LOADING, (void*)&OnClientPerformance, context);
	AddTransition(NCS_LOADING, (uint)NMT_LOADED_GAME, NCS_INGAME, (void*)&OnLoadedGame, context);

	AddTransition(NCS_INGAME, (uint)NMT_REJOINED, NCS_INGAME, (void*)&OnRejoined, context);
	AddTransition(NCS_INGAME, (uint)NMT_KICKED, NCS_INGAME, (void*)&OnKicked, context);
	AddTransition(NCS_INGAME, (uint)NMT_CLIENT_TIMEOUT, NCS_INGAME, (void*)&OnClientTimeout, context);
	AddTransition(NCS_INGAME, (uint)NMT_CLIENT_PERFORMANCE, NCS_INGAME, (void*)&OnClientPerformance, context);
	AddTransition(NCS_INGAME, (uint)NMT_CHAT, NCS_INGAME, (void*)&OnChat, context);
	AddTransition(NCS_INGAME, (uint)NMT_GAME_SETUP, NCS_INGAME, (void*)&OnGameSetup, context);
	AddTransition(NCS_INGAME, (uint)NMT_PLAYER_ASSIGNMENT, NCS_INGAME, (void*)&OnPlayerAssignment, context);
	AddTransition(NCS_INGAME, (uint)NMT_SIMULATION_COMMAND, NCS_INGAME, (void*)&OnInGame, context);
	AddTransition(NCS_INGAME, (uint)NMT_SYNC_ERROR, NCS_INGAME, (void*)&OnInGame, context);
	AddTransition(NCS_INGAME, (uint)NMT_END_COMMAND_BATCH, NCS_INGAME, (void*)&OnInGame, context);

	// Set first state
	SetFirstState(NCS_UNCONNECTED);
}
Beispiel #9
0
Expression::Expression(std::unique_ptr<Expression> A,
                       std::unique_ptr<Expression> B,
                       ExpressionType type,
                       NfaStates& states,
                       TransitionSet& symbols)
{
  //  m_Type = type;
  m_Left = std::move(A);
  m_Right = std::move(B);

  if (type == ExpressionTypeAnd)
  {
    /// AB
    /// |----------------|       |-----------------|
    /// |        A       |   e   |        B        |
    /// | ( ) -----> ( )---------->(  ) -----> (O) |
    /// |----------------|       |-----------------|
    AddTransition(m_Left->m_EndState, m_Right->m_StartState);
    m_StartState = m_Left->m_StartState;
    m_EndState = m_Right->m_EndState;
  }
  else if (type == ExpressionTypeOr)
  {
    /// A|B
    ///           |----------------|
    ///      e    |        A       |   e
    ///   --------->( ) -----> ( )---------
    ///   |       |----------------|      |
    ///   |                               v
    ///  ( )                             (O)
    ///   |                               ^
    ///   |       |----------------|      |
    ///   |       |        B       |      |
    ///   --------->( ) -----> ( )---------
    ///     e     |----------------|   e
    m_StartState = states.New();
    m_EndState = states.New();
    AddTransition(m_StartState, m_Left->m_StartState);
    AddTransition(m_StartState, m_Right->m_StartState);
    AddTransition(m_Left->m_EndState, m_EndState);
    AddTransition(m_Right->m_EndState, m_EndState);
  }
  else if (type == ExpressionTypeRange)
  {
    m_StartState = states.New();
    m_EndState = states.New();
    AddTransition(m_StartState, m_Left->m_StartState);
    AddTransition(m_StartState, m_Right->m_StartState);

    for (wchar_t ch = m_Left->m_ch.m_ch + 1 ; ch < m_Right->m_ch.m_ch; ch++)
    {
      symbols.insert(Transition(ch));
      std::unique_ptr<Expression> pNew(new Expression(Transition(ch), states));
      AddTransition(m_StartState, pNew->m_StartState);
      AddTransition(pNew->m_EndState, m_EndState);
    }

    AddTransition(m_Left->m_EndState, m_EndState);
    AddTransition(m_Right->m_EndState, m_EndState);
  }
  else
  {
    assert(false);
  }
}