예제 #1
0
void FailureProcess::Behavior(void)
{
    Seize(oven_fac, 1);
    //std::cout << "PORUCHA PECE " << Time << std::endl;
    refuse_orders = true;
    Wait(Exponential(FAILURE_WAIT_TIME));
    Release(oven_fac);
    refuse_orders = false;
    //std::cout << "KONEC PORUCHY PECE " << Time << std::endl;
}
예제 #2
0
파일: batch.cpp 프로젝트: jwrona/IMS
void Batch::Behavior(void)
{
    std::vector<Order*>::iterator begin;
    std::vector<Order*>::iterator end;
    DEBUG("NEW BATCH:\t\t");

    assert(chef_fac.Busy());
    assert(chef_fac.in == this);

    /* facitily is allready seized by this process */
    //Seize(chef_fac);

    /* no need for high priority from now */
    Priority = DEFAULT_PRIORITY;

#ifndef NDEBUG_PRINT
    //prints IDs of order processes in this batch
    std::cout << "\tIDs: ";
    for(std::vector<Order*>::iterator it = orders.begin();
        it != orders.end(); ++it)
    {
        if ((*it)->get_batch() == nullptr)
           std::cout << (*it)->get_id() << "(D), ";
        else
           std::cout << (*it)->get_id() << ", ";
    }
    std::cout << std::endl;
#endif //NDEBUG_PRINT

    ////////////////////////////////////////////////////////////
    //preparation
    ////////////////////////////////////////////////////////////

    DEBUG("PREPARATION\t\t");
    /*
     * loop through all orders in batch to simulate
     * pizza preparation
     * duration: 2-3 minutes for each pizza
     */
    begin = orders.begin();
    end = orders.end();
    for(std::vector<Order*>::iterator it = begin; it != end; ++it)
    {  //for every pizza in batch
        if ((*it)->get_batch() == nullptr)
        {
            /* order no longer in batch because of timer
             * expiration (customer canceled order)
             */
        }
        else
        {
            /* order not canceled yet
             * going to wait (prepare pizza)
             * 4 to 5 minutes for every pizza
             */
            Wait(Uniform(PREP_TIME_FROM, PREP_TIME_TO));

            if ((*it)->get_batch() == nullptr)
            {
                /* order canceled durign waiting (preparation )*/
            }
            else
            {
                /* order was not canceled duritg preparation */
            }
        }
    }

    /*
     * release chef facility by batch
     * facility is now ready to be seized by first order
     * in its queue to create new batch
     */
    Release(chef_fac);
    DEBUG("PREPARATION DONE\t");


    /*
     * loop through all orders in batch to simulate
     * pizza preparation error rate
     */
    begin = orders.begin();
    end = orders.end();
    for(std::vector<Order*>::iterator it = begin; it != end; ++it)
    {  //for every pizza in batch
        if ((*it)->get_batch() != nullptr)
        {
            double rnd = Uniform(0.0, 100.0); // 0 - 100 %
            if (rnd <= PREP_ERR_RATE)
            {
                DEBUG("PREPARATION ERROR\t");
                /* there was an error, pizza have to be removed
                 * from batch, order will be canceled 
                 * (no reparation for now)
                 */
                assert((*it)->get_batch() == this);
                remove_order(*it);
            }
        }
    }

#ifndef NDEBUG
    begin = orders.begin();
    end = orders.end();
    for(std::vector<Order*>::iterator it = begin; it != end; ++it)
        assert((*it)->get_batch() == this || (*it)->get_batch() == nullptr);
#endif //NDEBUG

    ////////////////////////////////////////////////////////////
    //baking
    ////////////////////////////////////////////////////////////

    /* if batch is not empty, simulate pizza baking
     * duration: exactly 4 minutes for batch
     */
    if (!is_empty())
    {
        Seize(oven_fac);
        DEBUG("BAKING\t\t\t");
        Wait(BAKING_TIME);
        Release(oven_fac);
        DEBUG("BAKING DONE\t\t");

        /* simulate error in baking */
        double rnd = Uniform(0.0, 100.0); // 0 - 100 %
        if (rnd <= BAKING_ERR_RATE)
        {
            DEBUG("BAKING ERROR\t\t");
            /* there was an error in baking, batch and all its
             * orders will be canceled
             * (no reparation for now)
             */
            begin = orders.begin();
            end = orders.end();
            for(std::vector<Order*>::iterator it = begin;
                it != end; ++it)
            {  //for every pizza in batch
                if ((*it)->get_batch() != nullptr)
                {
                    assert((*it)->get_batch() == this);
                    remove_order(*it);
                }
            }
            assert(this->is_empty());
        }
    }

    ////////////////////////////////////////////////////////////
    //delivery
    ////////////////////////////////////////////////////////////

    /* if batch is not empty, simulate pizza delivery
     * duration: exactly 10 - 15 minutes for each pizza
     */
    if (!is_empty())
    {
        Enter(delivery_store);
        DEBUG("DELIVERY\t\t");

        begin = orders.begin();
        end = orders.end();
        for(std::vector<Order*>::iterator it = begin;
            it != end; ++it)
        {  //for every pizza in batch
            if ((*it)->get_batch() == nullptr)
            {
                /* order no longer in batch because of timer
                 * expiration (customer canceled order)
                 */
            }
            else
            {
                /* order not canceled yet */
                Wait(Uniform(DELIV_TIME_FROM, DELIV_TIME_TO));

                if ((*it)->get_batch() == nullptr)
                {
                    /* order canceled durign delivery */
                }
                else
                {
                    /* order was not canceled during delivery */
                }
            }
        }

        Leave(delivery_store);
        DEBUG("DELIVERY DONE\t\t");
    }

    ////////////////////////////////////////////////////////////
    //finishing process
    ////////////////////////////////////////////////////////////

    /*
     * loop through all orders in batch to
     * create statistics
     * (they are all passivated)
     */
    DEBUG("FINISHED BATCH:\t\t");
    //std::cout << "\tIDs: ";
    begin = orders.begin();
    end = orders.end();
    for(std::vector<Order*>::iterator it = begin; it != end; ++it)
    {  //for every pizza in batch
        if ((*it)->get_batch() == nullptr)
        { //deleted
           //std::cout << (*it)->get_id() << "(D), ";
           /*
            * timeout is allready canceled
            */
        }
        else
        { //finished
           //std::cout << (*it)->get_id() << ", ";

           /* cancel timeout, process succesfully finished */
           if ((*it)->t != nullptr)
               (*it)->t->Cancel();

           (*it)->t = nullptr;
        }
    }
    //std::cout << std::endl;
}
예제 #3
0
파일: simDemo2.cpp 프로젝트: olii/IMS
 void Behavior() {
     nalozenychKonvic = 0;
     Seize(rampa, SLOT(Auto::Behavior25)); // postavi se na rampu
 }
예제 #4
0
void FGTurbine::Calculate(void)
{
  double thrust;

  RunPreFunctions();

  ThrottlePos = in.ThrottlePos[EngineNumber];

  if (ThrottlePos > 1.0) {
    AugmentCmd = ThrottlePos - 1.0;
    ThrottlePos -= AugmentCmd;
  } else {
    AugmentCmd = 0.0;
  }

  // When trimming is finished check if user wants engine OFF or RUNNING
  if ((phase == tpTrim) && (in.TotalDeltaT > 0)) {
    if (Running && !Starved) {
      phase = tpRun;
      N1_factor = MaxN1 - IdleN1;
      N2_factor = MaxN2 - IdleN2;      
      N2 = IdleN2 + ThrottlePos * N2_factor;
      N1 = IdleN1 + ThrottlePos * N1_factor;
      OilTemp_degK = 366.0;
      Cutoff = false;
    } else {
      phase = tpOff;
      Cutoff = true;
      EGT_degC = in.TAT_c;
    }
  }

  if (!Running && Cutoff && Starter) {
     if (phase == tpOff) phase = tpSpinUp;
  }

  // start
  if ((Starter == true) || (in.qbar > 30.0)) {
    if (!Running && !Cutoff && (N2 > 15.0)) phase = tpStart;
  }

  if (Cutoff && (phase != tpSpinUp)) phase = tpOff;
  if (in.TotalDeltaT == 0) phase = tpTrim;
  if (Starved) phase = tpOff;
  if (Stalled) phase = tpStall;
  if (Seized) phase = tpSeize;

  switch (phase) {
    case tpOff:    thrust = Off(); break;
    case tpRun:    thrust = Run(); break;
    case tpSpinUp: thrust = SpinUp(); break;
    case tpStart:  thrust = Start(); break;
    case tpStall:  thrust = Stall(); break;
    case tpSeize:  thrust = Seize(); break;
    case tpTrim:   thrust = Trim(); break;
    default: thrust = Off();
  }

  Thruster->Calculate(thrust); // allow thruster to modify thrust (i.e. reversing)

  RunPostFunctions();
}