/** * Function that computes the Keccak-f[1600] permutation on the given state. */ void KeccakF1600_StatePermute(void *state) { unsigned int round, x, y, j, t; UINT8 LFSRstate = 0x01; for(round=0; round<24; round++) { { /* === θ step (see [Keccak Reference, Section 2.3.2]) === */ tKeccakLane C[5], D; /* Compute the parity of the columns */ for(x=0; x<5; x++) C[x] = readLane(x, 0) ^ readLane(x, 1) ^ readLane(x, 2) ^ readLane(x, 3) ^ readLane(x, 4); for(x=0; x<5; x++) { /* Compute the θ effect for a given column */ D = C[(x+4)%5] ^ ROL64(C[(x+1)%5], 1); /* Add the θ effect to the whole column */ for (y=0; y<5; y++) XORLane(x, y, D); } } { /* === ρ and π steps (see [Keccak Reference, Sections 2.3.3 and 2.3.4]) === */ tKeccakLane current, temp; /* Start at coordinates (1 0) */ x = 1; y = 0; current = readLane(x, y); /* Iterate over ((0 1)(2 3))^t * (1 0) for 0 ≤ t ≤ 23 */ for(t=0; t<24; t++) { /* Compute the rotation constant r = (t+1)(t+2)/2 */ unsigned int r = ((t+1)*(t+2)/2)%64; /* Compute ((0 1)(2 3)) * (x y) */ unsigned int Y = (2*x+3*y)%5; x = y; y = Y; /* Swap current and state(x,y), and rotate */ temp = readLane(x, y); writeLane(x, y, ROL64(current, r)); current = temp; } } { /* === χ step (see [Keccak Reference, Section 2.3.1]) === */ tKeccakLane temp[5]; for(y=0; y<5; y++) { /* Take a copy of the plane */ for(x=0; x<5; x++) temp[x] = readLane(x, y); /* Compute χ on the plane */ for(x=0; x<5; x++) writeLane(x, y, temp[x] ^((~temp[(x+1)%5]) & temp[(x+2)%5])); } } { /* === ι step (see [Keccak Reference, Section 2.3.5]) === */ for(j=0; j<7; j++) { unsigned int bitPosition = (1<<j)-1; /* 2^j-1 */ if (LFSR86540(&LFSRstate)) XORLane(0, 0, (tKeccakLane)1<<bitPosition); } } } }
static void permute(KeccakContext* ctx) { uint8_t LFSRstate = 0x01; for (uint8_t round = 0; round < 24; ++round) { { // Theta step (see [Keccak Reference, Section 2.3.2]) uint64_t C[5], D; for (uint8_t x = 0; x < 5; ++x) { C[x] = readLane(x, 0) ^ readLane(x, 1) ^ readLane(x, 2) ^ readLane(x, 3) ^ readLane(x, 4); } for (uint8_t x = 0; x < 5; ++x) { D = C[(x+4)%5] ^ rol64(C[(x+1)%5], 1); for (uint8_t y = 0; y < 5; ++y) { XORLane(x, y, D); } } } { // p and Pi steps (see [Keccak Reference, Sections 2.3.3 and 2.3.4]) uint8_t x = 1, y = 0; uint64_t current = readLane(x, y); for (uint8_t t = 0; t < 24; ++t) { uint8_t r = ((t + 1) * (t + 2) / 2) % 64; uint8_t Y = (2*x + 3*y) % 5; x = y; y = Y; uint64_t temp = readLane(x, y); writeLane(x, y, rol64(current, r)); current = temp; } } { // X step (see [Keccak Reference, Section 2.3.1]) for (uint8_t y = 0; y < 5; ++y) { uint64_t temp[5]; for (uint8_t x = 0; x < 5; ++x) { temp[x] = readLane(x, y); } for (uint8_t x = 0; x < 5; ++x) { writeLane(x, y, temp[x] ^((~temp[(x+1)%5]) & temp[(x+2)%5])); } } } { // i step (see [Keccak Reference, Section 2.3.5]) for (uint8_t j = 0; j < 7; ++j) { if (LFSR86540(LFSRstate)) { uint64_t bitPos = (1<<j) - 1; XORLane(0, 0, (uint64_t)1 << bitPos); } } } } }
void MSFullExport::writeEdge(OutputDevice& of) { of.openTag("edges") << ">\n"; MSEdgeControl& ec = MSNet::getInstance()->getEdgeControl(); const std::vector<MSEdge*>& edges = ec.getEdges(); for (std::vector<MSEdge*>::const_iterator e = edges.begin(); e != edges.end(); ++e) { MSEdge& edge = **e; of.openTag("edge") << " id=\"" << edge.getID() << "\" traveltime=\"" << edge.getCurrentTravelTime() << "\">\n"; const std::vector<MSLane*>& lanes = edge.getLanes(); for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) { writeLane(of, **lane); } of.closeTag(); } of.closeTag(); }
void MSQueueExport::writeEdge(OutputDevice& of) { of.openTag("lanes"); MSEdgeControl& ec = MSNet::getInstance()->getEdgeControl(); const MSEdgeVector& edges = ec.getEdges(); for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) { MSEdge& edge = **e; const std::vector<MSLane*>& lanes = edge.getLanes(); for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) { writeLane(of, **lane); } } of.closeTag(); }
void NWWriter_SUMO::writeEdge(OutputDevice& into, const NBEdge& e, bool noNames, bool origNames) { // write the edge's begin into.openTag(SUMO_TAG_EDGE).writeAttr(SUMO_ATTR_ID, e.getID()); into.writeAttr(SUMO_ATTR_FROM, e.getFromNode()->getID()); into.writeAttr(SUMO_ATTR_TO, e.getToNode()->getID()); if (!noNames && e.getStreetName() != "") { into.writeAttr(SUMO_ATTR_NAME, StringUtils::escapeXML(e.getStreetName())); } into.writeAttr(SUMO_ATTR_PRIORITY, e.getPriority()); if (e.getTypeID() != "") { into.writeAttr(SUMO_ATTR_TYPE, e.getTypeID()); } if (e.isMacroscopicConnector()) { into.writeAttr(SUMO_ATTR_FUNCTION, EDGEFUNC_CONNECTOR); } // write the spread type if not default ("right") if (e.getLaneSpreadFunction() != LANESPREAD_RIGHT) { into.writeAttr(SUMO_ATTR_SPREADTYPE, e.getLaneSpreadFunction()); } if (e.hasLoadedLength()) { into.writeAttr(SUMO_ATTR_LENGTH, e.getLoadedLength()); } if (!e.hasDefaultGeometry()) { into.writeAttr(SUMO_ATTR_SHAPE, e.getGeometry()); } // write the lanes const std::vector<NBEdge::Lane>& lanes = e.getLanes(); SUMOReal length = e.getLoadedLength(); if (OptionsCont::getOptions().getBool("no-internal-links") && !e.hasLoadedLength()) { // use length to junction center even if a modified geometry was given PositionVector geom = e.cutAtIntersection(e.getGeometry()); geom.push_back_noDoublePos(e.getToNode()->getCenter()); geom.push_front_noDoublePos(e.getFromNode()->getCenter()); length = geom.length(); } if (length <= 0) { length = POSITION_EPS; } for (unsigned int i = 0; i < (unsigned int) lanes.size(); i++) { const NBEdge::Lane& l = lanes[i]; writeLane(into, e.getID(), e.getLaneID(i), l.speed, l.permissions, l.preferred, l.endOffset, l.width, l.shape, l.origID, length, i, origNames); } // close the edge into.closeTag(); }
void NWWriter_SUMO::writeEdge(OutputDevice& into, const NBEdge& e, bool noNames, bool origNames) { // write the edge's begin into.openTag(SUMO_TAG_EDGE).writeAttr(SUMO_ATTR_ID, e.getID()); into.writeAttr(SUMO_ATTR_FROM, e.getFromNode()->getID()); into.writeAttr(SUMO_ATTR_TO, e.getToNode()->getID()); if (!noNames && e.getStreetName() != "") { into.writeAttr(SUMO_ATTR_NAME, StringUtils::escapeXML(e.getStreetName())); } into.writeAttr(SUMO_ATTR_PRIORITY, e.getPriority()); if (e.getTypeName() != "") { into.writeAttr(SUMO_ATTR_TYPE, e.getTypeName()); } if (e.isMacroscopicConnector()) { into.writeAttr(SUMO_ATTR_FUNCTION, EDGEFUNC_CONNECTOR); } // write the spread type if not default ("right") if (e.getLaneSpreadFunction() != LANESPREAD_RIGHT) { into.writeAttr(SUMO_ATTR_SPREADTYPE, e.getLaneSpreadFunction()); } if (e.hasLoadedLength()) { into.writeAttr(SUMO_ATTR_LENGTH, e.getLoadedLength()); } if (!e.hasDefaultGeometry()) { into.writeAttr(SUMO_ATTR_SHAPE, e.getGeometry()); } // write the lanes const std::vector<NBEdge::Lane>& lanes = e.getLanes(); SUMOReal length = e.getLoadedLength(); if (length <= 0) { length = (SUMOReal) .1; } for (unsigned int i = 0; i < (unsigned int) lanes.size(); i++) { writeLane(into, e.getID(), e.getLaneID(i), lanes[i], length, i, origNames); } // close the edge into.closeTag(); }
void WSMSGridder::predictMeasurementSet(MSData &msData) { msData.msProvider->ReopenRW(); const MultiBandData selectedBandData(msData.SelectedBand()); _gridder->PrepareBand(selectedBandData); size_t rowsProcessed = 0; ao::lane<PredictionWorkItem> calcLane(_laneBufferSize+_cpuCount), writeLane(_laneBufferSize); lane_write_buffer<PredictionWorkItem> bufferedCalcLane(&calcLane, _laneBufferSize); boost::thread writeThread(&WSMSGridder::predictWriteThread, this, &writeLane, &msData); boost::thread_group calcThreads; for(size_t i=0; i!=_cpuCount; ++i) calcThreads.add_thread(new boost::thread(&WSMSGridder::predictCalcThread, this, &calcLane, &writeLane)); /* Start by reading the u,v,ws in, so we don't need IO access * from this thread during further processing */ std::vector<double> us, vs, ws; std::vector<size_t> rowIds, dataIds; msData.msProvider->Reset(); while(msData.msProvider->CurrentRowAvailable()) { size_t dataDescId; double uInMeters, vInMeters, wInMeters; msData.msProvider->ReadMeta(uInMeters, vInMeters, wInMeters, dataDescId); const BandData& curBand(selectedBandData[dataDescId]); const double w1 = wInMeters / curBand.LongestWavelength(), w2 = wInMeters / curBand.SmallestWavelength(); if(_gridder->IsInLayerRange(w1, w2)) { us.push_back(uInMeters); vs.push_back(vInMeters); ws.push_back(wInMeters); dataIds.push_back(dataDescId); rowIds.push_back(msData.msProvider->RowId()); ++rowsProcessed; } msData.msProvider->NextRow(); } for(size_t i=0; i!=us.size(); ++i) { PredictionWorkItem newItem; newItem.u = us[i]; newItem.v = vs[i]; newItem.w = ws[i]; newItem.dataDescId = dataIds[i]; newItem.data = new std::complex<float>[selectedBandData[dataIds[i]].ChannelCount()]; newItem.rowId = rowIds[i]; bufferedCalcLane.write(newItem); } if(Verbose()) std::cout << "Rows that were required: " << rowsProcessed << '/' << msData.matchingRows << '\n'; msData.totalRowsProcessed += rowsProcessed; bufferedCalcLane.write_end(); calcThreads.join_all(); writeLane.write_end(); writeThread.join(); }
bool NWWriter_SUMO::writeInternalEdges(OutputDevice& into, const NBNode& n, bool origNames) { bool ret = false; const EdgeVector& incoming = n.getIncomingEdges(); for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) { const std::vector<NBEdge::Connection>& elv = (*i)->getConnections(); if (elv.size() > 0) { bool haveVia = false; NBEdge* toEdge = 0; std::string internalEdgeID = ""; // first pass: compute average lengths of non-via edges std::map<NBEdge*, SUMOReal> lengthSum; std::map<NBEdge*, int> numLanes; for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) { lengthSum[(*k).toEdge] += MAX2((*k).shape.length(), POSITION_EPS); numLanes[(*k).toEdge] += 1; } // second pass: write non-via edges for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) { if ((*k).toEdge == 0) { assert(false); // should never happen. tell me when it does continue; } if (toEdge != (*k).toEdge) { internalEdgeID = (*k).id; if (toEdge != 0) { // close the previous edge into.closeTag(); } toEdge = (*k).toEdge; into.openTag(SUMO_TAG_EDGE); into.writeAttr(SUMO_ATTR_ID, internalEdgeID); into.writeAttr(SUMO_ATTR_FUNCTION, EDGEFUNC_INTERNAL); // open a new edge } // to avoid changing to an internal lane which has a successor // with the wrong permissions we need to inherit them from the successor const NBEdge::Lane& successor = (*k).toEdge->getLanes()[(*k).toLane]; const SUMOReal length = lengthSum[toEdge] / numLanes[toEdge]; // @note the actual length should be used once sumo supports lanes of // varying length within the same edge //const SUMOReal length = MAX2((*k).shape.length(), POSITION_EPS); writeLane(into, internalEdgeID, (*k).getInternalLaneID(), (*k).vmax, successor.permissions, successor.preferred, NBEdge::UNSPECIFIED_OFFSET, successor.width, (*k).shape, (*k).origID, length, (*k).internalLaneIndex, origNames, &n); haveVia = haveVia || (*k).haveVia; } ret = true; into.closeTag(); // close the last edge // third pass: write via edges if (haveVia) { for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) { if (!(*k).haveVia) { continue; } if ((*k).toEdge == 0) { assert(false); // should never happen. tell me when it does continue; } const NBEdge::Lane& successor = (*k).toEdge->getLanes()[(*k).toLane]; into.openTag(SUMO_TAG_EDGE); into.writeAttr(SUMO_ATTR_ID, (*k).viaID); into.writeAttr(SUMO_ATTR_FUNCTION, EDGEFUNC_INTERNAL); writeLane(into, (*k).viaID, (*k).viaID + "_0", (*k).viaVmax, SVCAll, SVCAll, NBEdge::UNSPECIFIED_OFFSET, successor.width, (*k).viaShape, (*k).origID, MAX2((*k).viaShape.length(), POSITION_EPS), // microsim needs positive length 0, origNames, &n); into.closeTag(); } } } } // write pedestrian crossings const std::vector<NBNode::Crossing>& crossings = n.getCrossings(); for (std::vector<NBNode::Crossing>::const_iterator it = crossings.begin(); it != crossings.end(); it++) { into.openTag(SUMO_TAG_EDGE); into.writeAttr(SUMO_ATTR_ID, (*it).id); into.writeAttr(SUMO_ATTR_FUNCTION, EDGEFUNC_CROSSING); into.writeAttr(SUMO_ATTR_CROSSING_EDGES, (*it).edges); writeLane(into, (*it).id, (*it).id + "_0", 1, SVC_PEDESTRIAN, 0, NBEdge::UNSPECIFIED_OFFSET, (*it).width, (*it).shape, "", (*it).shape.length(), 0, false, &n); into.closeTag(); } // write pedestrian walking areas const std::vector<NBNode::WalkingArea>& WalkingAreas = n.getWalkingAreas(); for (std::vector<NBNode::WalkingArea>::const_iterator it = WalkingAreas.begin(); it != WalkingAreas.end(); it++) { const NBNode::WalkingArea& wa = *it; into.openTag(SUMO_TAG_EDGE); into.writeAttr(SUMO_ATTR_ID, wa.id); into.writeAttr(SUMO_ATTR_FUNCTION, EDGEFUNC_WALKINGAREA); writeLane(into, wa.id, wa.id + "_0", 1, SVC_PEDESTRIAN, 0, NBEdge::UNSPECIFIED_OFFSET, wa.width, wa.shape, "", wa.length, 0, false, &n); into.closeTag(); } return ret; }
void MSXMLRawOut::writeEdge(OutputDevice& of, const MSEdge& edge, SUMOTime timestep) { //en bool dump = !MSGlobals::gOmitEmptyEdgesOnDump; if (!dump) { #ifdef HAVE_INTERNAL if (MSGlobals::gUseMesoSim) { MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(edge); while (seg != 0) { if (seg->getCarNumber() != 0) { dump = true; break; } seg = seg->getNextSegment(); } } else { #endif const std::vector<MSLane*>& lanes = edge.getLanes(); for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) { if (((**lane).getVehicleNumber() != 0)) { dump = true; break; } } #ifdef HAVE_INTERNAL } #endif } //en const std::vector<MSPerson*>& persons = edge.getSortedPersons(timestep); if (dump || persons.size() > 0) { of.openTag("edge") << " id=\"" << edge.getID() << "\""; if (dump) { #ifdef HAVE_INTERNAL if (MSGlobals::gUseMesoSim) { MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(edge); while (seg != 0) { seg->writeVehicles(of); seg = seg->getNextSegment(); } } else { #endif const std::vector<MSLane*>& lanes = edge.getLanes(); for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) { writeLane(of, **lane); } #ifdef HAVE_INTERNAL } #endif } // write persons for (std::vector<MSPerson*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) { of.openTag(SUMO_TAG_PERSON); of.writeAttr(SUMO_ATTR_ID, (*it_p)->getID()); of.writeAttr(SUMO_ATTR_POSITION, (*it_p)->getEdgePos()); of.writeAttr(SUMO_ATTR_ANGLE, (*it_p)->getAngle()); of.writeAttr("stage", (*it_p)->getCurrentStageDescription()); of.closeTag(); } of.closeTag(); } }