Tick* Exchange::GenRandomTick(Tick* proto) { Tick* tick = new Tick(*proto); Poco::DateTime now; tick->DateTime = now; tick->LastPrice = RandomWalk(proto->LastPrice); return tick; }
std::pair<float, float> RandomWalk(unsigned iterations, float d, std::pair<float, float> const &start, std::pair<float, float> const &xBounds, std::pair<float, float> const &yBounds, std::function<float(float, float)> const &boundaryCondition) { return RandomWalk(0, iterations, d, start, xBounds, yBounds, boundaryCondition); }
CThostFtdcDepthMarketDataField* Exchange::GenTick() { Poco::DateTime now; string date = Poco::format("%02d%02d%02d", now.year(), now.month(), now.day()); string time = Poco::format("%02d:%02d:%02d", now.hour(), now.minute(), now.second()); strcpy(tick->TradingDay, date.c_str()); strcpy(tick->UpdateTime, time.c_str()); strcpy(tick->InstrumentID, INSTRUMENT); tick->UpdateMillisec = now.millisecond(); tick->LastPrice = RandomWalk(tick->LastPrice); tick->Volume = tick->Volume; return tick; }
bool gen_path(path_generator::generatePath::Request &req, path_generator::generatePath::Response &res) { path_navigator::Waypoints *w = NULL; if(req.type == 0) //generate dikstra's path { w = new path_navigator::Waypoints(); Dijkstras(gmap, req.init_pos, req.dst_pos, w); } else if(req.type == 1) { w = new path_navigator::Waypoints(); RandomWalk(gmap, req.init_pos, w, 10); //default: perform 10 steps before you stop } res.w = *w; return true; }
int GenerateLightSubpath( const Scene &scene, Sampler &sampler, MemoryArena &arena, int maxDepth, Float time, const Distribution1D &lightDistr, const std::unordered_map<const Light *, size_t> &lightToIndex, Vertex *path) { if (maxDepth == 0) return 0; // Sample initial ray for light subpath Float lightPdf; int lightNum = lightDistr.SampleDiscrete(sampler.Get1D(), &lightPdf); const std::shared_ptr<Light> &light = scene.lights[lightNum]; RayDifferential ray; Normal3f nLight; Float pdfPos, pdfDir; Spectrum Le = light->Sample_Le(sampler.Get2D(), sampler.Get2D(), time, &ray, &nLight, &pdfPos, &pdfDir); if (pdfPos == 0 || pdfDir == 0 || Le.IsBlack()) return 0; // Generate first vertex on light subpath and start random walk path[0] = Vertex::CreateLight(light.get(), ray, nLight, Le, pdfPos * lightPdf); Spectrum beta = Le * AbsDot(nLight, ray.d) / (lightPdf * pdfPos * pdfDir); VLOG(2) << "Starting light subpath. Ray: " << ray << ", Le " << Le << ", beta " << beta << ", pdfPos " << pdfPos << ", pdfDir " << pdfDir; int nVertices = RandomWalk(scene, ray, sampler, arena, beta, pdfDir, maxDepth - 1, TransportMode::Importance, path + 1); // Correct subpath sampling densities for infinite area lights if (path[0].IsInfiniteLight()) { // Set spatial density of _path[1]_ for infinite area light if (nVertices > 0) { path[1].pdfFwd = pdfPos; if (path[1].IsOnSurface()) path[1].pdfFwd *= AbsDot(ray.d, path[1].ng()); } // Set spatial density of _path[0]_ for infinite area light path[0].pdfFwd = InfiniteLightDensity(scene, lightDistr, lightToIndex, ray.d); } return nVertices + 1; }
int GenerateCameraSubpath(const Scene &scene, Sampler &sampler, MemoryArena &arena, int maxDepth, const Camera &camera, Point2f &pFilm, Vertex *path) { if (maxDepth == 0) return 0; // Sample initial ray for camera subpath CameraSample cameraSample; cameraSample.pFilm = pFilm; cameraSample.time = sampler.Get1D(); cameraSample.pLens = sampler.Get2D(); RayDifferential ray; Spectrum beta = camera.GenerateRayDifferential(cameraSample, &ray); ray.ScaleDifferentials(1 / std::sqrt(sampler.samplesPerPixel)); // Generate first vertex on camera subpath and start random walk Float pdfPos, pdfDir; path[0] = Vertex::CreateCamera(&camera, ray, beta); camera.Pdf_We(ray, &pdfPos, &pdfDir); return RandomWalk(scene, ray, sampler, arena, beta, pdfDir, maxDepth - 1, TransportMode::Radiance, path + 1) + 1; }