void WorldSQP::initializeClosedLoopStepper(World* start, vector<vector<World*> >& target) { VectorXd state; world_to_state(start, state); resize_controller(target[0].size() + 1, state.size(), target.size()); current_states.resize(target.size()); current_jacobians.resize(target.size()); current_controls.resize(target[0].size()); #pragma omp parallel for for (int i = 0; i < target.size(); i++) { current_states[i].resize(target[i].size()); current_jacobians[i].resize(target[i].size()); for (int j = 0; j < target[i].size(); j++) { current_states[i][j] = new World(*target[i][j]); current_jacobians[i][j] = MatrixXd(); } } for (int k = 0; k < target[0].size(); k++) { current_controls[k].resize(2); for (int j = 0; j < 2; j++) { //hack current_controls[k][j] = new Control(); } } pushStart(start); }
void WorldSQP::pushStart(World* state) { #if COLOCATION_METHOD vector<World*> start_states; for (int i = 0; i < current_states.size(); i++) { start_states.push_back(state); //other method handles memory } pushStart(start_states); #else assert(false); #endif }
int main(int argc, char *argv[]) { char *me, *err; hestOpt *hopt=NULL; airArray *mop; char *outS[3]; char *gravStr, *gravGradStr, *seedStr; pushContext *pctx; Nrrd *_nin, *nin, *nPosIn, *nPosOut, *nTenOut, *nEnrOut; NrrdKernelSpec *ksp00, *ksp11, *ksp22; pushEnergySpec *ensp; int E; me = argv[0]; mop = airMopNew(); pctx = pushContextNew(); airMopAdd(mop, pctx, (airMopper)pushContextNix, airMopAlways); hestOptAdd(&hopt, "i", "nin", airTypeOther, 1, 1, &_nin, NULL, "input volume to filter", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "np", "# points", airTypeUInt, 1, 1, &(pctx->pointNum), "1000", "number of points to use in simulation"); hestOptAdd(&hopt, "pi", "npos", airTypeOther, 1, 1, &nPosIn, "", "positions to start at (overrides \"-np\")", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "step", "step", airTypeDouble, 1, 1, &(pctx->stepInitial), "1", "step size for gradient descent"); hestOptAdd(&hopt, "scl", "scale", airTypeDouble, 1, 1, &(pctx->scale), "1500", "scaling from tensor size to glyph size"); hestOptAdd(&hopt, "wall", "wall", airTypeDouble, 1, 1, &(pctx->wall), "0.0", "spring constant of containing walls"); hestOptAdd(&hopt, "cnts", "scale", airTypeDouble, 1, 1, &(pctx->cntScl), "0.0", "scaling of containment force"); hestOptAdd(&hopt, "limit", "frac", airTypeDouble, 1, 1, &(pctx->deltaLimit), "0.3", "speed limit on particles' motion"); hestOptAdd(&hopt, "dfmin", "frac", airTypeDouble, 1, 1, &(pctx->deltaFracMin), "0.2", "decrease step size if deltaFrac goes below this"); hestOptAdd(&hopt, "esf", "frac", airTypeDouble, 1, 1, &(pctx->energyStepFrac), "0.9", "when energy goes up instead of down, fraction by " "which to scale step size"); hestOptAdd(&hopt, "dfsf", "frac", airTypeDouble, 1, 1, &(pctx->deltaFracStepFrac), "0.5", "when deltaFrac goes below deltaFracMin, fraction by " "which to scale step size"); hestOptAdd(&hopt, "eimin", "frac", airTypeDouble, 1, 1, &(pctx->energyImprovMin), "0.01", "convergence threshold: stop when fracional improvement " "(decrease) in energy dips below this"); hestOptAdd(&hopt, "detr", NULL, airTypeBool, 0, 0, &(pctx->detReject), NULL, "do determinant-based rejection of initial sample locations"); hestOptAdd(&hopt, "rng", "seed", airTypeUInt, 1, 1, &(pctx->seedRNG), "42", "seed value for RNG which determines initial point locations"); hestOptAdd(&hopt, "nt", "# threads", airTypeUInt, 1, 1, &(pctx->threadNum), "1", "number of threads to run"); hestOptAdd(&hopt, "nprob", "# iters", airTypeDouble, 1, 1, &(pctx->neighborTrueProb), "1.0", "do full neighbor traversal with this probability"); hestOptAdd(&hopt, "pprob", "# iters", airTypeDouble, 1, 1, &(pctx->probeProb), "1.0", "do field probing with this probability"); hestOptAdd(&hopt, "maxi", "# iters", airTypeUInt, 1, 1, &(pctx->maxIter), "0", "if non-zero, max # iterations to run"); hestOptAdd(&hopt, "snap", "iters", airTypeUInt, 1, 1, &(pctx->snap), "0", "if non-zero, # iterations between which a snapshot " "is saved"); hestOptAdd(&hopt, "grv", "item", airTypeString, 1, 1, &gravStr, "none", "item to act as gravity"); hestOptAdd(&hopt, "grvgv", "item", airTypeString, 1, 1, &gravGradStr, "none", "item to act as gravity gradient"); hestOptAdd(&hopt, "grvs", "scale", airTypeDouble, 1, 1, &(pctx->gravScl), "nan", "magnitude and scaling of gravity vector"); hestOptAdd(&hopt, "grvz", "scale", airTypeDouble, 1, 1, &(pctx->gravZero), "nan", "height (WRT gravity) of zero potential energy"); hestOptAdd(&hopt, "seed", "item", airTypeString, 1, 1, &seedStr, "none", "item to act as seed threshold"); hestOptAdd(&hopt, "seedth", "thresh", airTypeDouble, 1, 1, &(pctx->seedThresh), "nan", "seed threshold threshold"); hestOptAdd(&hopt, "energy", "spec", airTypeOther, 1, 1, &ensp, "cotan", "specification of energy function to use", NULL, NULL, pushHestEnergySpec); hestOptAdd(&hopt, "nobin", NULL, airTypeBool, 0, 0, &(pctx->binSingle), NULL, "turn off spatial binning (which prevents multi-threading " "from being useful), for debugging or speed-up measurement"); hestOptAdd(&hopt, "k00", "kernel", airTypeOther, 1, 1, &ksp00, "tent", "kernel for tensor field sampling", NULL, NULL, nrrdHestKernelSpec); hestOptAdd(&hopt, "k11", "kernel", airTypeOther, 1, 1, &ksp11, "fordif", "kernel for finding containment gradient from mask", NULL, NULL, nrrdHestKernelSpec); hestOptAdd(&hopt, "k22", "kernel", airTypeOther, 1, 1, &ksp22, "cubicdd:1,0", "kernel for 2nd derivatives", NULL, NULL, nrrdHestKernelSpec); hestOptAdd(&hopt, "o", "nout", airTypeString, 3, 3, outS, "p.nrrd t.nrrd e.nrrd", "output files to save position and tensor info into"); hestParseOrDie(hopt, argc-1, argv+1, NULL, me, info, AIR_TRUE, AIR_TRUE, AIR_TRUE); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); nPosOut = nrrdNew(); airMopAdd(mop, nPosOut, (airMopper)nrrdNuke, airMopAlways); nTenOut = nrrdNew(); airMopAdd(mop, nTenOut, (airMopper)nrrdNuke, airMopAlways); nEnrOut = nrrdNew(); airMopAdd(mop, nEnrOut, (airMopper)nrrdNuke, airMopAlways); if (3 == _nin->spaceDim && AIR_EXISTS(_nin->measurementFrame[0][0])) { nin = nrrdNew(); airMopAdd(mop, nin, (airMopper)nrrdNuke, airMopAlways); if (tenMeasurementFrameReduce(nin, _nin)) { airMopAdd(mop, err = biffGetDone(TEN), airFree, airMopAlways); fprintf(stderr, "%s: trouble undoing measurement frame:\n%s", me, err); airMopError(mop); exit(1); } } else { nin = _nin; } pctx->nin = nin; pctx->npos = nPosIn; pctx->verbose = 0; pctx->binIncr = 84; /* random small-ish value */ pushEnergySpecSet(pctx->ensp, ensp->energy, ensp->parm); nrrdKernelSpecSet(pctx->ksp00, ksp00->kernel, ksp00->parm); nrrdKernelSpecSet(pctx->ksp11, ksp11->kernel, ksp11->parm); nrrdKernelSpecSet(pctx->ksp22, ksp22->kernel, ksp22->parm); if (strcmp("none", gravStr)) { pctx->gravItem = airEnumVal(tenGage, gravStr); if (tenGageUnknown == pctx->gravItem) { fprintf(stderr, "%s: couldn't parse \"%s\" as a %s (gravity)\n", me, gravStr, tenGage->name); airMopError(mop); return 1; } pctx->gravGradItem = airEnumVal(tenGage, gravGradStr); if (tenGageUnknown == pctx->gravGradItem) { fprintf(stderr, "%s: couldn't parse \"%s\" as a %s (gravity grad)\n", me, gravGradStr, tenGage->name); airMopError(mop); return 1; } } else { pctx->gravItem = tenGageUnknown; pctx->gravGradItem = tenGageUnknown; pctx->gravZero = AIR_NAN; pctx->gravScl = AIR_NAN; } if (strcmp("none", seedStr)) { pctx->seedThreshItem = airEnumVal(tenGage, seedStr); if (tenGageUnknown == pctx->seedThreshItem) { fprintf(stderr, "%s: couldn't parse \"%s\" as a %s (seedthresh)\n", me, seedStr, tenGage->name); airMopError(mop); return 1; } } else { pctx->seedThreshItem = 0; pctx->seedThresh = AIR_NAN; } E = 0; if (!E) E |= pushStart(pctx); if (!E) E |= pushRun(pctx); if (!E) E |= pushOutputGet(nPosOut, nTenOut, nEnrOut, pctx); if (!E) E |= pushFinish(pctx); if (E) { airMopAdd(mop, err = biffGetDone(PUSH), airFree, airMopAlways); fprintf(stderr, "%s: trouble:\n%s\n", me, err); airMopError(mop); return 1; } fprintf(stderr, "%s: time for %d iterations= %g secs\n", me, pctx->iter, pctx->timeRun); if (nrrdSave(outS[0], nPosOut, NULL) || nrrdSave(outS[1], nTenOut, NULL) || nrrdSave(outS[2], nEnrOut, NULL)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: couldn't save output:\n%s\n", me, err); airMopError(mop); return 1; } airMopOkay(mop); return 0; }
void Pult::connects() { connect(bnStart, SIGNAL(pressed()), this, SLOT(pushStart())); connect(bnLeft, SIGNAL(pressed()), this, SLOT(pushLeft())); connect(bnRight, SIGNAL(pressed()), this, SLOT(pushRight())); }