Beispiel #1
0
void Rame::avancer()
{
    pthread_mutex_lock(&mutex);
    if (this->position == 0 && this->sens == Rame::Retour) {
        qDebug() << "Changement";
        this->setPosition(0);
        this->sens = Rame::Aller;
        this->position++;
    } else if (this->position == this->ligne->getLongueur() && this->sens == Rame::Aller) {
        qDebug() << "Changement";
        this->setPosition(this->ligne->getLongueur());
        this->sens = Rame::Retour;
        this->position--;
    } else if (this->position < this->ligne->getLongueur()) {
        bool aller = true;
        if (this->sens == Rame::Retour) {
            aller = false;
        }
        Element * e = this->ligne->getElementAt(this->position, aller);

        qDebug() << "Rame " << this->numRame << " \t position : " << this->getPosition();

        if (e->getClasse() == "Feu") {
            Feux * f = dynamic_cast<Feux *>(e);
            f->addSignal(new Signals(this, Signals::Demande));
            qDebug() << "Rame " << this->numRame << " \t > envoi signal Feu" << f->getNum() << ".";
            if (this->listSignals.empty()) {
                qDebug() << "Rame " << this->numRame << " \t attend reponse Feu" << f->getNum() << ".";
            }
        } else if (e->getClasse() == "Station") {
            Station * s = dynamic_cast<Station *>(e);
            s->addSignal(new Signals(this, Signals::Demande));
            qDebug() << "Rame " << this->numRame << " \t arrive a station " << s->getNom();

        } else {
            bool obstacle = false;
            if (this->position < this->ligne->getLongueur() - 1) {
                Element * suivant;
                if (aller)
                    suivant = this->ligne->getElementAt(this->position + 1, aller);
                else
                    suivant = this->ligne->getElementAt(this->position - 1, aller);

                if (suivant->getClasse() == "Obstacle") {
                    obstacle = true;
                    qDebug() << "Rame " << this->numRame << " \t Obstacle détecté";
                }
            }
            if (!obstacle)
                if (this->sens == Rame::Aller) {
                    this->position++;
                } else {
                    this->position--;
                }
        }
    }

    pthread_mutex_unlock(&mutex);

}
Beispiel #2
0
void readFile(string filePath, Station *stations)
{
    fstream inputFile;
    inputFile.open(filePath.c_str(), fstream::in);

    if(inputFile.fail())
    {
        cerr << "no such file: " << filePath << endl;
        return;
    }

    string line = "";
    int counter = 0;

	Station *st;

    while(!inputFile.eof())
    {
        inputFile >> line;
        st = new Station(line);
        if(st->getTotalQuantity() >= 10.0)
        {
			stations[counter] = *st;
        }
        counter++;
    }

    inputFile.close();
}
Beispiel #3
0
unsigned long NetThread::userFunc(const LCreal dt)
{
   Station* station = (Station*) getParent();
   station->processNetworkInputTasks(dt);
   station->processNetworkOutputTasks(dt);
   return 0;
}
Beispiel #4
0
Station
DragMimeData::station() const
{
    Station station;
    station.setUrl( QString::fromUtf8( data( "item/station" ) ) );
    return station;
}
MoveHistory Station::moveTo(Station *destination, const MoveHistory &moveHistory) const
{
	// 목적지까지 도달함
	if (this == destination)
		return moveHistory;

	MoveHistory minHistory; // 초기셋, INT_MAX

	for (auto it = hoursMap.begin(); it != hoursMap.end(); it++) //모든 이웃한 역에 대하여
	{
		Station *neighbor = it->first;

		MoveHistory myHistory = moveHistory;

		// 해당 역으로의 이동이 유의미한지 검사
		if (myHistory.moveTo(neighbor) == false)
			continue;

		// 유의미하다면 이동을 실시
		myHistory = neighbor->moveTo(destination, myHistory);

		// 현재의 이동내역 소요시간이 최소인가?
		if (myHistory.hours < minHistory.hours)
			minHistory = myHistory;
	}

	return minHistory;
}
Beispiel #6
0
void
CashReconcile::slotShiftClose()
{
    QDate date = _date->getDate();
    Id station_id = stationId();
    Id employee_id = employeeId();

    // Posting time is current time if closing for today or 11:59:59 PM
    QTime time = QTime::currentTime();
    if (date != QDate::currentDate())
	time = QTime(23, 59, 59);

    QString name;
    if (station_id != INVALID_ID) {
	Station station;
	_quasar->db()->lookup(station_id, station);
	name = station.name();
    } else if (employee_id != INVALID_ID) {
	Employee employee;
	_quasar->db()->lookup(employee_id, employee);
	name = employee.nameFL();
    } else {
	name = "<None>";
    }
    if (name.isEmpty()) name = tr("<blank>");

    QString message = "Are you sure you want to ringoff \n\"" + name + "\"";
    int choice = QMessageBox::warning(this, tr("Ringoff?"), message,
				      tr("Yes"), tr("No"));
    if (choice != 0) return;

    // Create the shift
    Shift shift;
    shift.setStoreId(_store->getId());
    shift.setStationId(station_id);
    shift.setEmployeeId(employee_id);
    shift.setPostDate(date);
    shift.setPostTime(time);
    if (!_quasar->db()->create(shift)) {
	message = tr("Failed creating shift close transaction");
	QMessageBox::critical(this, tr("Error"), message);
	return;
    }

    QApplication::setOverrideCursor(waitCursor);
    qApp->processEvents();

    bool result = _quasar->db()->shiftClose(shift);
    QApplication::restoreOverrideCursor();

    if (!result) {
	message = tr("Failed setting shift in transactions");
	QMessageBox::critical(this, tr("Error"), message);
    } else {
	message = "The shift for \"" + name + "\"\nhas been closed";
	QMessageBox::information(this, tr("Information"), message);
	slotRefresh();
    }
}
Beispiel #7
0
void RockmaxServer::getTrack(const Station& station) {
    QNetworkReply* reply = manager->get(QNetworkRequest(QUrl(
	station.id() > 0 
	    ? QString("http://www.rockmax.cz/stream_%0/all_songs_%0.txt").arg(station.nick())
	    : QString("http://www.rockmax.cz/stream_live/all_songs.txt")
    )));
    connect(reply, SIGNAL(finished()), SLOT(processTrack()));
}
	void OnStopRecordStation(const Station& station)
	{
		streamrecorder_.StopRecording(station.GetId());

		pView_->ClearStationStatus(station.GetId());
		pView_->ClearStationTitle(station.GetId());
		pView_->DisableStopRecording();
	}
Beispiel #9
0
int
station_get_name(LuaState* state)
{
  Station* station = rMain()->getMission()->getStation();
  wstring stationName = station->getName();
  state->PushWString(stationName.c_str());
  return 1;
}
Beispiel #10
0
void Car::addNewStation(QString name)
{
    Station *station = new Station(-1, name, this);
    _stationlist.append(station);
    qSort(_stationlist.begin(), _stationlist.end(), sortStationById);
    station->save();
    emit stationsChanged();
}
Beispiel #11
0
int
station_count_modules(LuaState* state)
{
  Station* station = rMain()->getMission()->getStation();
  if(station == NULL) return 0;
  state->PushInteger(station->getModuleCount());
  return 1;
}
// The simulation
Simulation* DataRecorder::getSimulationImp()
{
   if (sim == nullptr) {
      Station* p = getStation();
      if (p != nullptr) sim = p->getSimulation();
   }
   return sim;
}
Simulation* MultiActorAgent::getSimulation()
{
   Simulation* sim = nullptr;
   Station* s = getStation();
   if (s != nullptr) {
      sim = s->getSimulation();
   }
   return sim;
}
Beispiel #14
0
void
StationsPluginLondon::handleInfos(const QByteArray & data)
{
  QRegExp re_stations("station\\=\\{(.*)\\}\\;");
  QRegExp re_items("\\s*(\\w+)\\s*:(.*),");
  int ofs = 0;

  re_stations.setMinimal(true);
  re_items.setMinimal(true);

  while ((ofs = re_stations.indexIn(data, ofs)) >= 0) {
    bool ok;
    int id;
    QPointF pos;
    Station *station;
    QMap<QString, QString> values;

    ofs += re_stations.matchedLength();

    int station_ofs = 0;
    QString station_data = re_stations.capturedTexts().at(1);

    while ((station_ofs = re_items.indexIn(station_data, station_ofs)) >= 0) {
      QStringList capt = re_items.capturedTexts();

      if (capt.size() < 3)
	continue ;

      station_ofs += re_items.matchedLength();
      values[capt.at(1)] = capt.at(2);
      values[capt.at(1)].replace("\"", "");
    }

    id = values["id"].toInt(&ok);
    pos = QPointF(values["lat"].toDouble(),
		  values["long"].toDouble());

    if (!ok)
      continue ;

    station = getOrCreateStation(id);

    if (station->name().isEmpty())
      station->setName(values["name"]);
    if (station->pos().isNull())
      station->setPos(pos);
    station->setBikes(values["nbBikes"].toInt());
    station->setFreeSlots(values["nbEmptyDocks"].toInt());
    station->setTotalSlots(station->bikes() + station->freeSlots());

    storeOrDropStation(station);
  }

  emit stationsCreated(stations.values());
  emit stationsUpdated(stations.values());
}
 // write station data to xml streamgenerateBullets();
 foreach( QGraphicsItem*  item, items() )
 {
   Station*  station = dynamic_cast<Station*>( item );
   if ( station )
   {
     stream->writeEmptyElement( "station" );
     stream->writeAttribute( "x", QString("%1").arg(station->x()) );
     stream->writeAttribute( "y", QString("%1").arg(station->y()) );
   }
 }
Beispiel #16
0
int
station_add_module(LuaState* state)
{
  Station* station = rMain()->getMission()->getStation();
  if(station == NULL) return 0;
  Module* newModule = scriptGetItem<Module>(state, 1);
  if(newModule == NULL) return 0;
  station->addModule(newModule);
  return 0;
}
Beispiel #17
0
Velocity PlanningProblem::getControl(uint i)
{
    Velocity c;
    if(i < trajec.length()) {
        Station st = trajec.getStation(i);
        c = st.getVelocity();
    }
    else
        c.setZero();
    return c;
}
Beispiel #18
0
void Dijstra::findRoute(Station start, Station end){
  graph costs;
  std::priority_queue<pp, std::vector<pp>, Prioritize> queue;

  // all the stations have int_max as cost
  for(graph::iterator it=g.begin(); it!=g.end(); it++) {
    costs[it->first][it->first] = INT_MAX;

    for(distance::iterator jt=it->second.begin(); jt!=it->second.end(); ++jt){
      costs[jt->first][jt->first] = INT_MAX;
    }
  }

  // set first station to cost 0
  costs[start][start] = 0;
  queue.push(pp(start, 0));
  while(!queue.empty()) {
    // get the station with the lowest cost
    Station station = queue.top().first;
    queue.pop();

    for(graph::iterator it=costs.begin(); it!=costs.end(); ++it) {
      int cost = costs[it->first].begin()->second;

      // go through all stations and get edge cost
      if(g[station].find(it->first) != g[station].end())
        cost = g[station][it->first];
      else if(g[it->first].find(station) != g[it->first].end())
        cost = g[it->first][station];

      // check for a cheaper option
      if (costs[it->first].begin()->second > costs[station].begin()->second + cost) {

        Station old = costs[it->first].begin()->first;
        costs[it->first].erase(old);

        costs[it->first][station] = costs[station].begin()->second + cost;
        queue.push(pp(it->first, costs[it->first].begin()->second));
      }
    }
  }

  std::cout<<"cost "<<costs[end].begin()->second<<"\n";
  std::cout<<"station "<<end.getName()<<"\n";

  Station station = costs[end].begin()->first;

  while(costs[station].begin()->second != 0){
    std::cout<<"station "<<station.getName()<<"\n";
    station = costs[station].begin()->first;
  }

  std::cout<<"station "<<start.getName()<<"\n";
};
Beispiel #19
0
void av::daemon::DeviceService::setLED(const char* station_name, int which, bool value)
{
    if(mStationSegment)
    {
        Station* station = lookupCachedStation(station_name);

        if(station)
            station->setLED(which, value);
    }
    else
        logger.warn() << "setLED(): no station segment initialized.";
}
Beispiel #20
0
bool PlanningProblem::pathHasCollision(Station &from, Station &to, const Obstacle &ob)
{
    b2PolygonShape road_from_to;
    Vector2D center((from.getPosition() + to.getPosition()).to2D() /2.0);
    Vector2D half_diff((to.getPosition() - from.getPosition()).to2D() /2.0);
    float safet_latera_bound = 0.1;
    road_from_to.SetAsBox(agent->radius() * (1 + safet_latera_bound), half_diff.lenght() + agent->radius(),
                          center.toB2vec2(), M_PI_2 + half_diff.arctan());

//    if(ob == NULL)
//        continue;
    return b2TestOverlap(ob.shape, 0, &road_from_to, 1, ob.transform, identity_trans);
}
Beispiel #21
0
PlanningProblem::ExtendResult PlanningProblem::RRTStep(float extension_len, float max_len)
{
    ExtendResult result;
    try {
        Station rand_st;
        float toss = uni_rand(0, 1);
        if(toss < GOAL_PROB)
            rand_st.set(goal.goal_point);
        else
        {
            if(max_len < INFINITY) {
                Vector2D rand_point = randomSampleFromEllipse(initialState.getPosition().to2D(),
                                                              goal.goal_point.getPosition().to2D(),
                                                              max_len);
                Station temp;
                temp.setPosition(Vector3D(rand_point, uni_rand(-M_PI, M_PI)));
                rand_st.set(temp);

            }
            else {
                Station temp = SampleStateUniform();
                rand_st.set(temp);
            }
        }

        if(!rand_st.isValid())
            throw "can not sampled!";
        SpatialVertex* near_ver = randomTree.getNearestVertex(rand_st);

        //    if(near_ver->state.isValid())
        if(near_ver == NULL)
            throw "can not find nearest!";

        Station new_st = RRTExtend((near_ver->state), rand_st, extension_len);
        if(!new_st.isValid())
        {
            result = eTrapped;
            throw "can not extend tree!";
        }
        if(goal.minDistTo(new_st) < agent->radius() * 1)
            result = eReached;
        else
            result = eAdvanced;
        randomTree.appendNewStation(near_ver, new_st);

    } catch (const char* msg)
    {
//        cerr << "Exception in RRTStep: " << msg << endl;
    }
    return result;
}
Station *
StationsPluginSimple::getOrCreateStation(int id)
{
  Station *station;

  if (stations.contains(id))
    station = stations[id];
  else {
    station = new Station(this);
    station->setId(id);
  }

  return station;
}
Beispiel #23
0
int
station_save_group(LuaState* state)
{
  wstring fileName = wstringFromLuaObject(state->Stack(1));
  if(fileName == L"") return 0;
  
  Station* station = rMain()->getMission()->getStation();
  DataFile* groupFile = new DataFile();
  Group* group = station->groupFromStation(groupFile);
  groupFile->setRootItem(group);
  groupFile->save(fileName);
  delete groupFile;
  return 0;
}
Beispiel #24
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool Comment::attachTo(PublicObject* parent) {
	if ( parent == NULL ) return false;

	// check all possible parents
	MomentTensor* momentTensor = MomentTensor::Cast(parent);
	if ( momentTensor != NULL )
		return momentTensor->add(this);
	FocalMechanism* focalMechanism = FocalMechanism::Cast(parent);
	if ( focalMechanism != NULL )
		return focalMechanism->add(this);
	Amplitude* amplitude = Amplitude::Cast(parent);
	if ( amplitude != NULL )
		return amplitude->add(this);
	Magnitude* magnitude = Magnitude::Cast(parent);
	if ( magnitude != NULL )
		return magnitude->add(this);
	StationMagnitude* stationMagnitude = StationMagnitude::Cast(parent);
	if ( stationMagnitude != NULL )
		return stationMagnitude->add(this);
	Pick* pick = Pick::Cast(parent);
	if ( pick != NULL )
		return pick->add(this);
	Event* event = Event::Cast(parent);
	if ( event != NULL )
		return event->add(this);
	Origin* origin = Origin::Cast(parent);
	if ( origin != NULL )
		return origin->add(this);
	Parameter* parameter = Parameter::Cast(parent);
	if ( parameter != NULL )
		return parameter->add(this);
	ParameterSet* parameterSet = ParameterSet::Cast(parent);
	if ( parameterSet != NULL )
		return parameterSet->add(this);
	Stream* stream = Stream::Cast(parent);
	if ( stream != NULL )
		return stream->add(this);
	SensorLocation* sensorLocation = SensorLocation::Cast(parent);
	if ( sensorLocation != NULL )
		return sensorLocation->add(this);
	Station* station = Station::Cast(parent);
	if ( station != NULL )
		return station->add(this);
	Network* network = Network::Cast(parent);
	if ( network != NULL )
		return network->add(this);

	SEISCOMP_ERROR("Comment::attachTo(%s) -> wrong class type", parent->className());
	return false;
}
Beispiel #25
0
Trajectory PlanningProblem::GRRTsolve()
{
    this->planningResult = false;
    randomTree.clear();
    float start_time = currentTimeMSec();
    int tryExtensionCounter = 0;
    randomTree.appendNewStation(NULL, initialState);

    for(int step=0; step < MAX_RRT_STEP_TRY/5; step++)
    {
        Station target;
        float toss = uni_rand(0, 1);
        if(toss < GOAL_PROB)
            target.setPosition(goal.goal_point.getPosition());
        else {
            Station tempSt = SampleStateUniform();
            target.setPosition(tempSt.getPosition());
        }

        if( !target.isValid() )
            continue;
//            throw "can not sampled!";
        SpatialVertex* near_ver = randomTree.getNearestVertex(target);
        if(near_ver == NULL)
            continue;

        int greedyCounter = 0;
        while(greedyCounter < 5){
            tryExtensionCounter ++;
            Station extended = RRTExtend(near_ver->state, target, agent->radius() * 2);
            if(!extended.isValid())
                break;
            randomTree.appendNewStation(near_ver, extended);
            if(Station::dubinDistance(extended, target) < agent->radius() ) {
                if((target.getPosition() - goal.goal_point.getPosition()).lenght2D() < agent->radius() /2)
                    planningResult = true;
                break;
            }
//            if(target != goal.goal_point)  break;
            greedyCounter ++;
        }

        cout << "Step = " << step << endl;

    }

    if(planningResult)
    {
        float finish_time = currentTimeMSec();
        this->planningTime = finish_time - start_time;
//        cout << "Greedy RRT Planning succeed in " << planningTime << "mili seconds" << endl;
        return buildTrajectoryFromRandomTree();
    }
    return Trajectory();
}
void Ratp::retrieveJourneysFromStation(const QString &request, const Station &station, int limit)
{
    Q_UNUSED(limit)
    QString fileName = QString(":/data/backward/%1.xml").arg(station.name().at(0).toLower());

    QVariantMap disambiguation;
    disambiguation.insert("id", "org.SfietKonstantin.publictransportation.ratp");

    Company company (disambiguation, "RATP", QVariantMap());

    bool ok;
    QString error;

    QList<InfoJourneys> infoJourneysList =
            OfflineXmlJourneysFromStationHelper::journeysFromStation(fileName, station,
                                                                     disambiguation, company,
                                                                     &ok, &error);

    if (!ok) {
        emit errorRetrieved(request, BACKEND_WARNING, error);
        return;
    }

    debug("ratp-plugin") << infoJourneysList.count();
    emit journeysFromStationRetrieved(request, infoJourneysList);
}
	void OnRecordStation(const Station& station)
	{
		pView_->DisableRecording();

		EventHandler eventHandler(station.GetId());
		streamrecorder_.StartRecording(station, eventHandler);
	}
Beispiel #28
0
int main(int argc, const char **argv) {
    
    if (argc != 5)
        my_error(" R/S INTERFACE ROUTE_TABLE HOST_NAME");

    bool is_router = false;
    if (std::string(argv[1]).compare(std::string("-route")) == 0)
        is_router = true;
    
    Station *s = new Station(argv[2], argv[3], argv[4], is_router);
    s->start();
    
    delete s;
    
    return 0;
}
Beispiel #29
0
QList<Station>
LastFmUserSettings::recentStations()
{
    MyQSettings s( this );

    s.beginGroup( "RecentStations" );
    QStringList const keys = s.childKeys();
    s.endGroup();

    QMap<int, Station> stations;
    foreach (QString key, keys) {
        Station station;
        station.setUrl( s.value( "RecentStations/" + key ).toString() );
        station.setName( s.value( "StationNames/" + station.url() ).toString() );
        stations[key.toInt()] = station;
    }
Beispiel #30
0
void av::daemon::DeviceService::setMatrix(const char* station_name, const ::gua::math::mat4& value)
{
    if(mStationSegment)
    {
        Station* station = lookupCachedStation(station_name);

        if(station)
        {
            station->setMatrix(value);
            logger.info() << "setMatrix(): " << this << " succeeded for station " << station_name;
        }
        else
            logger.warn() << "setMatrix(): " << this << " failed for station " << station_name << " (no station)";
    }
    else
        logger.warn() << "setMatrix(): " << this << " failed for station " << station_name << " (no segment)";
}