Beispiel #1
0
void DomainServer::nodeKilled(Node* node) {
    // if this node has linked data it was from an assignment
    if (node->getLinkedData()) {
        Assignment* nodeAssignment =  (Assignment*) node->getLinkedData();
        
        qDebug() << "Adding assignment" << *nodeAssignment << " back to queue.\n";
        
        // find this assignment in the static file
        for (int i = 0; i < MAX_STATIC_ASSIGNMENT_FILE_ASSIGNMENTS; i++) {
            if (_staticAssignments[i].getUUID() == nodeAssignment->getUUID()) {
                // reset the UUID on the static assignment
                _staticAssignments[i].resetUUID();
                
                // put this assignment back in the queue so it goes out
                _assignmentQueueMutex.lock();
                _assignmentQueue.push_back(&_staticAssignments[i]);
                _assignmentQueueMutex.unlock();
                
            } else if (_staticAssignments[i].getUUID().isNull()) {
                // we are at the blank part of the static assignments - break out
                break;
            }
        }
    }
    
}
Beispiel #2
0
void DomainServer::civetwebUploadHandler(struct mg_connection *connection, const char *path) {
    
    // create an assignment for this saved script, for now make it local only
    Assignment* scriptAssignment = new Assignment(Assignment::CreateCommand,
                                                  Assignment::AgentType,
                                                  NULL,
                                                  Assignment::LocalLocation);
    
    // check how many instances of this assignment the user wants by checking the ASSIGNMENT-INSTANCES header
    const char ASSIGNMENT_INSTANCES_HTTP_HEADER[] = "ASSIGNMENT-INSTANCES";
    const char* requestInstancesHeader = mg_get_header(connection, ASSIGNMENT_INSTANCES_HTTP_HEADER);
    
    if (requestInstancesHeader) {
        // the user has requested a number of instances greater than 1
        // so set that on the created assignment
        scriptAssignment->setNumberOfInstances(atoi(requestInstancesHeader));
    }
    
    QString newPath(ASSIGNMENT_SCRIPT_HOST_LOCATION);
    newPath += "/";
    // append the UUID for this script as the new filename, remove the curly braces
    newPath += uuidStringWithoutCurlyBraces(scriptAssignment->getUUID());
    
    // rename the saved script to the GUID of the assignment and move it to the script host locaiton
    rename(path, newPath.toLocal8Bit().constData());
    
    qDebug("Saved a script for assignment at %s\n", newPath.toLocal8Bit().constData());
    
    // add the script assigment to the assignment queue
    // lock the assignment queue mutex since we're operating on a different thread than DS main
    domainServerInstance->_assignmentQueueMutex.lock();
    domainServerInstance->_assignmentQueue.push_back(scriptAssignment);
    domainServerInstance->_assignmentQueueMutex.unlock();
}
Beispiel #3
0
void StatementList::makeIsect(StatementList &a, LocationSet &b)
{
    if (this == &a) { // *this = *this isect b
        for (auto it = a.begin(); it != a.end();) {
            assert((*it)->isAssignment());
            Assignment *as = static_cast<Assignment *>(*it);

            if (!b.contains(as->getLeft())) {
                it = m_list.erase(it);
            }
            else {
                it++;
            }
        }
    }
    else { // normal assignment
        clear();
        for (Statement *stmt : a) {
            assert(stmt->isAssignment());
            Assignment *as = static_cast<Assignment *>(stmt);

            if (b.contains(as->getLeft())) {
                append(as);
            }
        }
    }
}
Beispiel #4
0
Assignment get_merged_assignment(const Subset &s, const Assignment &ss0,
                                 const Ints &i0, const Assignment &ss1,
                                 const Ints &i1) {
  Ints ret(s.size(), -1);
  IMP_USAGE_CHECK(ss0.size() == i0.size(),
                  "The size of the subset and "
                      << "the index don't match: " << ss0.size() << " vs "
                      << i0.size());
  IMP_USAGE_CHECK(ss1.size() == i1.size(),
                  "The size of the subset and "
                      << "the index don't match: " << ss1.size() << " vs "
                      << i1.size());
  for (unsigned int i = 0; i < i0.size(); ++i) {
    ret[i0[i]] = ss0[i];
  }
  for (unsigned int i = 0; i < i1.size(); ++i) {
    ret[i1[i]] = ss1[i];
  }
  IMP_IF_CHECK(USAGE) {
    for (unsigned int i = 0; i < ret.size(); ++i) {
      IMP_USAGE_CHECK(ret[i] >= 0, "Not all set");
    }
  }
  return Assignment(ret);
}
Beispiel #5
0
 /// Check whether \a x is solution
 virtual bool solution(const Assignment& x) const {
   for (int i=0; i<x.size(); i++)
     for (int j=i+1; j<x.size(); j++)
       if (x[i]+i==x[j]+j)
         return false;
   return true;
 }
Beispiel #6
0
//! What is the probability of this type assignment ?
float SPGParser::proba(Assignment a)
{
    float prob = 1.0;
    for(Assignment::iterator it = a.begin();
            it != a.end(); it++)
        prob *= proba(*it);
    return prob;
}
Beispiel #7
0
bool Tuple::IsSubAssignmentOf(const Assignment &assignment) const {
  for (std::size_t i = 0; i < this->size(); ++i) {
    PVPair pvpair = (*this)[i];
    if (!assignment.IsContainParam(pvpair.pid_) || assignment.GetValue(pvpair.pid_) != pvpair.vid_) {
      return false;
    }
  }
  return true;
}
Beispiel #8
0
int main(int argc, char *argv[])
{
	// Uncomment this line to run the Rift/Connect/Physics demo as per 
	// http://www.youtube.com/watch?v=EEbVHxOkTxw
	Assignment game;
	game.Run();

	return 0;
}
/// searchForAssignment - Look for a cached solution for a query.
///
/// \param key - The query to look up.
/// \param result [out] - The cached result, if the lookup is succesful. This is
/// either a satisfying assignment (for a satisfiable query), or 0 (for an
/// unsatisfiable query).
/// \return - True if a cached result was found.
bool CexCachingSolver::searchForAssignment(KeyType &key, Assignment *&result) {
    Assignment * const *lookup = cache.lookup(key);
    if (lookup) {
        result = *lookup;
        return true;
    }

    if (CexCacheTryAll) {
        // Look for a satisfying assignment for a superset, which is trivially an
        // assignment for any subset.
        Assignment **lookup = cache.findSuperset(key, NonNullAssignment());

        // Otherwise, look for a subset which is unsatisfiable, see below.
        if (!lookup)
            lookup = cache.findSubset(key, NullAssignment());

        // If either lookup succeeded, then we have a cached solution.
        if (lookup) {
            result = *lookup;
            return true;
        }

        // Otherwise, iterate through the set of current assignments to see if one
        // of them satisfies the query.
        for (assignmentsTable_ty::iterator it = assignmentsTable.begin(),
                ie = assignmentsTable.end(); it != ie; ++it) {
            Assignment *a = *it;
            if (a->satisfies(key.begin(), key.end())) {
                result = a;
                return true;
            }
        }
    } else {
        // FIXME: Which order? one is sure to be better.

        // Look for a satisfying assignment for a superset, which is trivially an
        // assignment for any subset.
        Assignment **lookup = cache.findSuperset(key, NonNullAssignment());

        // Otherwise, look for a subset which is unsatisfiable -- if the subset is
        // unsatisfiable then no additional constraints can produce a valid
        // assignment. While searching subsets, we also explicitly the solutions for
        // satisfiable subsets to see if they solve the current query and return
        // them if so. This is cheap and frequently succeeds.
        if (!lookup)
            lookup = cache.findSubset(key, NullOrSatisfyingAssignment(key));

        // If either lookup succeeded, then we have a cached solution.
        if (lookup) {
            result = *lookup;
            return true;
        }
    }

    return false;
}
Beispiel #10
0
void XMLConverter::setAssignments(Assignments & assignments)
{
    for (Assignments::iterator i = assignments.begin(), e = assignments.end();
            i != e; i++)
    {
        Assignment * assignment = *i;
        RequestOverseer * overseer = getOverseerByRequest(assignment->getRequest());
        overseer->assign(assignment, *networkOverseer);
    }
}
Beispiel #11
0
//! Create the union with another set
Assignment Assignment::createUnion(const Assignment &rhs) const
{
    Assignment a(*this);

    for(Assignment::iterator it = rhs.begin();
            it != rhs.end(); it++)
        a.insert(*it);

    return a;
}
Beispiel #12
0
QDebug operator<<(QDebug debug, const Assignment &assignment) {
    debug.nospace() << "UUID: " << qPrintable(assignment.getUUID().toString()) <<
        ", Type: " << assignment.getType();
    
    if (!assignment.getPool().isEmpty()) {
        debug << ", Pool: " << assignment.getPool();
    }

    return debug.space();
}
Beispiel #13
0
// Special intersection method: this := a intersect b
void StatementList::makeIsect(StatementList& a, LocationSet& b)
{
    slist.clear();
    for (iterator it = a.slist.begin(); it != a.slist.end(); ++it)
        {
            Assignment* as = (Assignment*)*it;
            if (b.exists(as->getLeft()))
                slist.push_back(as);
        }
}
Beispiel #14
0
		virtual void Visit(Assignment& instruction)
		{
			Prefix(instruction);
			if (!instruction.First()->IsType(Expression::DUMMY))
			{
				instruction.First()->GenerateCode(mOut);
				mOut << " = ";
			}
			instruction.Second()->GenerateCode(mOut);
			mOut << ';' << std::endl;
		}
bool Why3Translator::visit(Assignment const& _node)
{
	if (_node.assignmentOperator() != Token::Assign)
		error(_node, "Compound assignment not supported.");

	_node.leftHandSide().accept(*this);

	add(m_currentLValueIsRef ? " := " : " <- ");
	_node.rightHandSide().accept(*this);

	return false;
}
Beispiel #16
0
bool SPARCSignature::argumentCompare(const Assignment &a, const Assignment &b) const
{
    SharedConstExp la = a.getLeft();
    SharedConstExp lb = b.getLeft();
    // %o0-$o5 (r8-r13) are the preferred argument locations
    int ra = 0, rb = 0;

    if (la->isRegOf()) {
        int r = la->access<Const, 1>()->getInt();

        if ((r >= REG_SPARC_O0) && (r <= REG_SPARC_O5)) {
            ra = r;
        }
    }

    if (lb->isRegOf()) {
        int r = lb->access<Const, 1>()->getInt();

        if ((r >= REG_SPARC_O0) && (r <= REG_SPARC_O5)) {
            rb = r;
        }
    }

    if (ra && rb) {
        return ra < rb; // Both r8-r13: compare within this set
    }

    if (ra && (rb == 0)) {
        return true; // r8-r13 less than anything else
    }

    if (rb && (ra == 0)) {
        return false; // Nothing else is less than r8-r13
    }

    const int ma = Util::getStackOffset(la, REG_SPARC_FP);
    const int mb = Util::getStackOffset(lb, REG_SPARC_FP);

    if (ma && mb) {
        return ma < mb; // Both m[sp + K]: order by memory offset
    }

    if (ma && !mb) {
        return true; // m[sp+K] less than anything left
    }

    if (mb && !ma) {
        return false; // nothing left is less than m[sp+K]
    }

    return *la < *lb; // Else order arbitrarily
}
Beispiel #17
0
bool CexCachingSolver::computeValue(const Query& query,
                                    ref<Expr> &result) {
  TimerStatIncrementer t(stats::cexCacheTime);

  Assignment *a;
  if (!getAssignment(query.withFalse(), a))
    return false;
  assert(a && "computeValue() must have assignment");
  result = a->evaluate(query.expr);  
  assert(isa<ConstantExpr>(result) && 
         "assignment evaluation did not result in constant");
  return true;
}
Beispiel #18
0
bool CexCachingSolver::computeValidity(const Query& query,
                                       Solver::Validity &result) {
  TimerStatIncrementer t(stats::cexCacheTime);
  Assignment *a;

  // Given query of the form antecedent -> consequent, here we try to
  // decide if antecedent was satisfiable by attempting to get an
  // assignment from the validity proof of antecedent -> false.
  if (!getAssignment(query.withFalse(), a))
    return false;

  // Logically, antecedent must be satisfiable, as we eagerly terminate a
  // path upon the discovery of unsatisfiability.
  assert(a && "computeValidity() must have assignment");
  ref<Expr> q = a->evaluate(query.expr);
  assert(isa<ConstantExpr>(q) && 
         "assignment evaluation did not result in constant");

  if (cast<ConstantExpr>(q)->isTrue()) {
    // Antecedent is satisfiable, and its model is also a model of the
    // consequent, which means that the query: antecedent -> consequent
    // is potentially valid.
    //
    // We next try to establish the validity of the query
    // antecedent -> consequent itself, and when this was proven invalid,
    // gets the solution to "antecedent and not consequent", i.e.,
    // the counterexample, in a.
    if (!getAssignment(query, a))
      return false;                  // Return false in case of solver error

    // Return Solver::True in result in case validity is established:
    // Solver::Unknown otherwise. Solver::Unknown is actually conservative,
    // as the solver by returning a solution may have decided invalidity.
    result = !a ? Solver::True : Solver::Unknown;
  } else {
    // The computed model of the antecedent is not a model of the consequent.
    // It is possible that the query is false under any interpretation. Here
    // we try to prove antecedent -> not consequent given the original
    // query antecedent -> consequent.
    if (!getAssignment(query.negateExpr(), a))
      return false;

    // If there was no solution, this means that antecedent -> not consequent
    // is valid, and therefore the original query antecedent -> consequent has
    // no model. Otherwise, we do not know.
    result = !a ? Solver::False : Solver::Unknown;
  }
  
  return true;
}
Beispiel #19
0
 void MatchingSolver::readVars(SolutionCollector *collector) {

	m_result = NULL;
	if (collector->solution_count() == 0) {
		return;
	}
	m_result = new SeatToSpeakerMapper(this);
	Assignment *assignment = collector->solution(0);
	for (int i = 0; i < m_speakers.size(); i++) {
		SpeakerModel* speakerModel = m_speakers[i];
		int j = assignment->Value(m_speakerVars[i]);
		RoleLink *link = m_links[j];
		m_result->addMapping(link->debate, link->group, link->seatIndex, speakerModel);
	}
}
Beispiel #20
0
bool TableFunction::SetVal(const Assignment &a, double val) {
    int idx = a.GetIndex();
    if (idx < 0 || idx == UNKNOWN_VAL || idx >= (int) values.size())
        return false;
    values[idx] = val;
    return true;
}
Beispiel #21
0
 /// %Test whether \a x is solution
 virtual MaybeType solution(const Assignment& x) const {
   if (x.size() == 1) {
     return cmp(x[0],frt,c);
   } else {
     return cmp(x[0],frt,c) & cmp(x[1],frt,c);
   }
 }
Beispiel #22
0
 void AOCMGraph::GenerateGraph() {
     stack<AOCMGraphNode*> stk;       
     int root = pt->GetRoot();
     int rootDomainSize;
     if (pt->HasDummy()) {
         rootDomainSize = 1;
     }
     else {
         rootDomainSize = m->GetDomains()[root];
     }
     Assignment a;
     a.AddVar(root,1);
     a.SetVal(root,0);
     
     stk.push(new AOCMGraphNode(root,a,OR,1.0));
 }
Beispiel #23
0
 /// %Test whether \a x is solution
 virtual bool solution(const Assignment& x) const {
   int m = 0;
   for (int i=x.size(); i--; )
     if ((x[i] >= -1) && (x[i] <= 1))
       m++;
   return cmp(m,irt,2);
 }
Beispiel #24
0
void NodeList::sendAssignment(Assignment& assignment) {
    unsigned char assignmentPacket[MAX_PACKET_SIZE];
    
    PACKET_TYPE assignmentPacketType = assignment.getCommand() == Assignment::CreateCommand
        ? PACKET_TYPE_CREATE_ASSIGNMENT
        : PACKET_TYPE_REQUEST_ASSIGNMENT;
    
    int numHeaderBytes = populateTypeAndVersion(assignmentPacket, assignmentPacketType);
    int numAssignmentBytes = assignment.packToBuffer(assignmentPacket + numHeaderBytes);
    
    sockaddr* assignmentServerSocket = (_assignmentServerSocket == NULL)
        ? (sockaddr*) &DEFAULT_LOCAL_ASSIGNMENT_SOCKET
        : _assignmentServerSocket;
    
    _nodeSocket.send(assignmentServerSocket, assignmentPacket, numHeaderBytes + numAssignmentBytes);
}
Beispiel #25
0
 /// %Test whether \a x is solution
 virtual bool solution(const Assignment& x) const {
   int m = 0;
   for (int i=x.size(); i--; )
     if (x[i] == 0)
       m += 2;
   return cmp(m,irt,4);
 }
void AssignmentList::insert(Assignment inputAssignment)
{

    if (!obtainSize()) // If the list is empty.
        theData.push_front(inputAssignment);

    else
    {

        for (AssignmentIterator = theData.begin();
            AssignmentIterator != theData.end();
            AssignmentIterator++)
        {

            // If we find an assignment with a later due date, insert this
                // assignment before it and exit the function.
            if (inputAssignment.obtainDueDate() <= AssignmentIterator->obtainDueDate())
            {
                theData.insert(AssignmentIterator, inputAssignment);
                // Reference: "std::list::insert." _cplusplus.com_.
                    // cplusplus.com, 2015. Web. 2 Oct. 2015.
                    // <http://www.cplusplus.com/reference/list/list/insert/>.
                return;
            }

        }

        theData.push_back(inputAssignment);
        // If we have not found an assignment with a later due date, place
            // this assignment at the end of the list.

    }

}
Beispiel #27
0
bool ASTPrinter::visit(Assignment const& _node)
{
	writeLine(string("Assignment using operator ") + Token::toString(_node.getAssignmentOperator()));
	printType(_node);
	printSourcePart(_node);
	return goDeeper();
}
Beispiel #28
0
bool CexCachingSolver::getAssignment(const Query& query, Assignment *&result) {
  KeyType key;

  if (lookupAssignment(query, key, result))
    return true;

  std::vector<const Array*> objects;
  findSymbolicObjects(key.begin(), key.end(), objects);

  std::vector< std::vector<unsigned char> > values;
  bool hasSolution;
  if (!solver->impl->computeInitialValues(query, objects, values, 
                                          hasSolution))
    return false;
    
  AssignmentCacheWrapper *bindingWrapper;
  Assignment *binding;
  if (hasSolution) {
    binding = new Assignment(objects, values);

    // Memoize the result.
    std::pair<assignmentsTable_ty::iterator, bool>
      res = assignmentsTable.insert(binding);
    if (!res.second) {
      delete binding;
      binding = *res.first;
    }
    
    if (DebugCexCacheCheckBinding)
      if (!binding->satisfies(key.begin(), key.end())) {
        query.dump();
        binding->dump();
        klee_error("Generated assignment doesn't match query");
      }

    bindingWrapper = new AssignmentCacheWrapper(binding);
  } else {
    unsatCore = solver->impl->getUnsatCore();
    binding = (Assignment *) 0;
    bindingWrapper = new AssignmentCacheWrapper(unsatCore);
  }
  
  result = binding;
  cache.insert(key, bindingWrapper);

  return true;
}
Beispiel #29
0
 /// %Test whether \a x is solution
 virtual MaybeType solution(const Assignment& x) const {
   if (max < min)
     return MT_FALSE;
   for (int i=x.size(); i--; )
     if ((x[i].max() > max) || (x[i].min() < min))
       return MT_FALSE;
   return MT_TRUE;
 }
Beispiel #30
0
    EBTStatus AssignmentTask::update(Agent* pAgent, EBTStatus childStatus)
    {
        BEHAVIAC_ASSERT(childStatus == BT_RUNNING);

        BEHAVIAC_ASSERT(Assignment::DynamicCast(this->GetNode()));
        Assignment* pAssignmentNode = (Assignment*)(this->GetNode());

        EBTStatus result = BT_SUCCESS;
        bool bValid = Assignment::EvaluteAssignment(pAgent, pAssignmentNode->m_opl, pAssignmentNode->m_opr, pAssignmentNode->m_opr_m);

        if (!bValid)
        {
            result = pAssignmentNode->update_impl(pAgent, childStatus);
        }

        return result;
    }