Example #1
0
  // Does some simple caching of prior results.
  void
  Cpp_interface::checkSat(const ASTVec & assertionsSMT2)
  {
    if (ignoreCheckSatRequest)
      return;

    bm.GetRunTimes()->stop(RunTimes::Parsing);

    checkInvariant();
    assert(assertionsSMT2.size() == cache.size());

    Entry& last_run = cache.back();
    if ((last_run.node_number != assertionsSMT2.back().GetNodeNum()) && (last_run.result == SOLVER_SATISFIABLE))
      {
        // extra asserts might have been added to it,
        // flipping from sat to unsat. But never from unsat to sat.
        last_run.result =  SOLVER_UNDECIDED;
      }

    // We might have run this query before, or it might already be shown to be unsat. If it was sat,
    // we've stored the result (but not the model), so we can shortcut and return what we know.
    if (!((last_run.result == SOLVER_SATISFIABLE) || last_run.result == SOLVER_UNSATISFIABLE))
        {
          resetSolver();

          ASTNode query;

          if (assertionsSMT2.size() > 1)
            query = nf->CreateNode(AND, assertionsSMT2);
          else if (assertionsSMT2.size() == 1)
            query = assertionsSMT2[0];
          else
            query = bm.ASTTrue;

          SOLVER_RETURN_TYPE last_result = GlobalSTP->TopLevelSTP(query, bm.ASTFalse);

          // Store away the answer. Might be timeout, or error though..
          last_run = Entry(last_result);
          last_run.node_number = assertionsSMT2.back().GetNodeNum();

          // It's satisfiable, so everything beneath it is satisfiable too.
          if (last_result == SOLVER_SATISFIABLE)
            {
              for (int i = 0; i < cache.size(); i++)
                {
                  assert(cache[i].result != SOLVER_UNSATISFIABLE);
                  cache[i].result = SOLVER_SATISFIABLE;
                }
            }
        }

    if (bm.UserFlags.quick_statistics_flag)
      {
        bm.GetRunTimes()->print();
      }

    (GlobalSTP->tosat)->PrintOutput(last_run.result);
    bm.GetRunTimes()->start(RunTimes::Parsing);
  }
Example #2
0
OnlineAstrometryParser::OnlineAstrometryParser() : AstrometryParser()
{
    job_retries=0;
    solver_retries=0;

    networkManager = new QNetworkAccessManager(this);

    connect(this, SIGNAL(authenticateFinished()), this, SLOT(uploadFile()));
    connect(this, SIGNAL(uploadFinished()), this, SLOT(getJobID()));
    connect(this, SIGNAL(jobIDFinished()), this, SLOT(checkJobs()));
    connect(this, SIGNAL(jobFinished()), this, SLOT(checkJobCalibration()));

    // Reset parity on solver failure
    connect(this, &OnlineAstrometryParser::solverFailed, this, [&]() { parity = -1;});

    connect(this, SIGNAL(solverFailed()), this, SLOT(resetSolver()));
    connect(this, SIGNAL(solverFinished(double,double,double, double)), this, SLOT(resetSolver()));

    downsample_factor = 0;
    isGenerated = true;

}
Example #3
0
bool SnoptSolver::solve() {
    resetSolver();

    int nVar = mTotalDofs;

    // RESET CONSTRAINTS AND OBJECTIVES
    //	mConstrBox->SetNumDofs(nVar);
    //	mObjBox->SetNumDofs(nVar);

    // RESET PROBLEM DIMENSION IN SNOPT
    int nConstr = conBox()->getNumTotalRows();

    mSnopt->resizeJacobian(nVar, nVar, nConstr, nConstr);

    // FILL IN BOUNDARIES
    double* coef_vals = new double[nVar + mSnopt->mNumConstr];
    double* lower_bounds = new double[nVar];
    double* upper_bounds = new double[nVar];


    std::vector<Var *>& vars(mProb->vars());
    for(int i = 0; i < nVar; i++){
        upper_bounds[i] = vars[i]->mUpper;
        lower_bounds[i] = vars[i]->mLower;
        coef_vals[i] = vars[i]->mVal;
    }

    int count = 0;
    // ASSIGN SLACK FOR EACH CONSTRAINT
    for(int i = 0; i < conBox()->getNumConstraints(); i++){
        Constraint* c = conBox()->getConstraint(i);
        for(int j = 0; j < c->mNumRows; j++)
            coef_vals[nVar + count + j] = c->mConstTerm[j];
        count += c->mNumRows;
    }

    // ASSIGN CONSTRINAT TYPE
    int counter = 0;
    // switch(constr_eqn)
    // case 0: [-constTerm, constTerm]
    // case 1: [constTerm, constTerm + 1e7] C>=0
    // case 2: [constTerm - 1e7, constTerm] C<=0
    // case 3:
    // case 4: [constTerm - 1e-2, constTerm + 1e-2]
    // case 5: [constTerm - 1e3, constTerm + 1e3]
    for(int i = 0; i < conBox()->getNumConstraints(); i++){
        Constraint* c = conBox()->getConstraint(i);
        for(int j=0; j< c->mNumRows; j++){
            if(c->mEquality == 1)
                mSnopt->mConstrEqns[counter++] = 1;
            else if(c->mEquality == -1)
                mSnopt->mConstrEqns[counter++] = 2;
            else if(c->mSlack) // allow slip
                mSnopt->mConstrEqns[counter++] = 5;
            else
                mSnopt->mConstrEqns[counter++] = 0;
        }
    }

    mOptCount++;
    // comment the following two lines for better performance
    mSnopt->mOutput = 9;
    // mSnopt->mSum = 6;

    SnoptInterface::Return ret = mSnopt->solve(coef_vals, lower_bounds, upper_bounds,mUnit);

    std::cout << "[VLOG(1)]" << "SnoptSolver " << mOptCount << " : ";
    std::cout << "[VLOG(1)]" << "obj = " << mSnopt->mReturnedObj << std::endl;

    delete[] coef_vals;
    delete[] lower_bounds;
    delete[] upper_bounds;

    if(ret == SnoptInterface::Solution) {
        return true;
    } else {
        return false;
    }
}