bool xRedisClient::smove(const RedisDBIdx& dbi,  const KEY& srckey, const KEY& deskey,  const VALUE& member) {
	if (0 == srckey.length()) {
		return false;
	}
	SETDEFAULTIOTYPE(MASTER);
	return command_bool(dbi, "SMOVE %s", srckey.c_str(), deskey.c_str(), member.c_str());
}
bool xRedisClient::spop(const RedisDBIdx& dbi,  const KEY& key, VALUE& member) {
	if (0 == key.length()) {
		return false;
	}
	SETDEFAULTIOTYPE(MASTER);
	return command_string(dbi, member, "SPOP %s", key.c_str());
}
bool xRedisClient::smembers(const RedisDBIdx& dbi,  const KEY& key, VALUES& vValue) {
	if (0 == key.length()) {
		return false;
	}
	SETDEFAULTIOTYPE(SLAVE);
	return command_list(dbi, vValue, "SMEMBERS %s", key.c_str());
}
Example #4
0
void KMplex::greedy(KEY& T, KEY& S)
{
    while(T.size() > 0)
    {
        S.push_back(T.back());
        T.pop_back();
    }
    return;
}
bool xRedisClient::srandmember(const RedisDBIdx& dbi,  const KEY& key, VALUES& members, int count) {
	if (0 == key.length()) {
		return false;
	}
	SETDEFAULTIOTYPE(SLAVE);
	if (0 == count) {
		return command_list(dbi, members, "SRANDMEMBER %s", key.c_str());
	}
	return command_list(dbi, members, "SRANDMEMBER %s %d", key.c_str(), count);
}
Example #6
0
// Returns list of key values of x NOT in y (i.e. set_difference)
const KEY difference(const KEY& x, const KEY& y)
{
    KEY difference;
    KEY::const_iterator xi = x.begin(), yi = y.begin();
    for(; xi != x.end(); ++xi)
    {
        if(*xi == *yi) // Found yi in x, move to next yi to look for;
            ++yi;
        else 
            difference.push_back(*xi);     
    }
    return difference;
}
Example #7
0
// Returns systematic sample of k-th value of x, where k is determined
// by the fraction argument (k = 1/f). 
const KEY sample(const KEY& x, const double fraction)
{
    KEY sample;
    double interval = 1.0 / fraction;
    // Randomly select starting location on interval [0, m]
    // where m ~ interval size.
    unsigned m = (unsigned)ceil(interval);
    double location = uniform((unsigned)0, m);
    for(; location < x.size() - 1; location += interval)
    {
        // For non-integer locations, round up to next integer value k
        unsigned k = (unsigned)ceil(location);
        // Take k-th sample
        sample.push_back(x[k]);          
    }
    return sample;
}
bool xRedisClient::srem(const RedisDBIdx& dbi,  const KEY& key, const VALUES& vmembers, int64_t& count) {
	if (0 == key.length()) {
		return false;
	}
	SETDEFAULTIOTYPE(MASTER);
	VDATA vCmdData;
	vCmdData.push_back("SREM");
	vCmdData.push_back(key);
	addparam(vCmdData, vmembers);
	return commandargv_integer(dbi, vCmdData, count);
}
Example #9
0
  void Locality_Splitter::finalize_sub_plan (
      Deployment::DeploymentPlan &sub_plan,
      KEY &sub_plan_key)
  {
    DANCEX11_LOG_TRACE ("Locality_Splitter::finalize_sub_plan");

    // check for availability of LocalityManager instance
    if (!sub_plan_key.has_locality_manager ())
      {
        // add minimal default LocalityManager instance to sub plan
        uint32_t impl_index = sub_plan.implementation ().size ();
        sub_plan.implementation ().push_back (::Deployment::MonolithicDeploymentDescription ());
        uint32_t inst_index = sub_plan.instance ().size ();
        sub_plan.instance ().push_back (::Deployment::InstanceDeploymentDescription ());
        sub_plan.instance ().back ().implementationRef (impl_index);

        // set correct implementation type
        Deployment::Property exec_property;
        exec_property.name (IMPL_TYPE);
        exec_property.value () <<= DANCE_LOCALITYMANAGER;
        sub_plan.implementation ().back ().execParameter ().push_back (exec_property);

        // create unique name for Locality Manager
        ACE_Utils::UUID uuid;
        ACE_Utils::UUID_GENERATOR::instance ()->generate_UUID (uuid);
        std::string lm_name ("Locality Manager [");
        lm_name += uuid.to_string ()->c_str ();
        lm_name += "]";
        sub_plan.instance ().back ().name (lm_name);

        DANCEX11_LOG_TRACE ("Locality_Splitter::finalize_sub_plan - " <<
                            "No locality manager found, created a default locality named<" <<
                            sub_plan.instance ().back ().name () << ">");

        // add instance to sub plan key
        sub_plan_key.add_instance (inst_index);
        // mark as locality manager
        sub_plan_key.locality_manager_instance (
          sub_plan_key.instances ().size () - 1);
      }
  }
Example #10
0
void KMplex::initialise(KEY& T, KEY& S)
{
    if(T.size() <= 2)
    {
        greedy(T, S);
        return;
    }

    KEY::iterator a;
    KEY::iterator b;
    double dab = 0.0;

    for(KEY::iterator t = T.begin(); t != T.end(); ++t)
        for(KEY::iterator tt = t + 1; tt != T.end(); ++tt)
        {
            if(D_[*t][*tt] > dab)
            {
                dab = D_[*t][*tt];
                a = t;
                b = tt;
            }
        }

    // Copy object indices a and b into sample key S
    S.push_back(*a);
    S.push_back(*b);

    // Remove object indices from key T
    T.erase(b);
    T.erase(a);
}
Example #11
0
void KMplex::sample(KEY& T, KEY& S)
{
    if(T.size() <= 2)
    {
        greedy(T, S);
        return;
    }
    // NOTE: Cannot sample for two or less data, so copy any data to S

    // Indices of points a and b
    KEY::iterator a;
    KEY::iterator b;

    // Corresponding distances to points a and b, from c(S)
    double da = 0.0;
    double db = 0.0;
    for(KEY::iterator t = T.begin(); t != T.end(); ++t)
    {
        // Find shortest distance d(t,s)
        double d = large();
        for(KEY::iterator s = S.begin(); s != S.end(); ++s)
        {
            if(D_[*t][*s] < d)
                d = D_[*t][*s];
        }

        // Retain t if corresponds to first or second farthest from S
        if(d >= da)
        {
            b = a;		// Farthest object moves to second farthest
            db = da;
            a = t;		// New object t is farthest from s in S
            da = d;
        }
        else if(d >= db)	// New object t is second farthest from s in S
        {
            b = t;
            db = d;
        }
        else
        {
            ; 			// Do nothing
        }
    }

    // Indices a and b are moved to sample, S
    S.push_back(*a);
    S.push_back(*b);

    // Erase items a and b, starting with last in sequence
    if(a > b)
    {
        T.erase(a);
        T.erase(b);
    }
    else
    {
        T.erase(b);
        T.erase(a);
    }
}
Example #12
0
 bool operator <( int rhs ) { return key.getKey() < rhs; }
Example #13
0
void KMplex::merge(KEY& S, KEY& T)
{
    for(KEY::iterator s = S.begin(); s != S.end(); ++s)
        T.push_back(*s);
}
Example #14
0
 bool operator <=( int rhs ) { return key.getKey() <= rhs; }
Example #15
0
 void setKey( int k ) { key.setKey( k ); }
Example #16
0
bool xRedisClient::srandmember(const RedisDBIdx& dbi,  const KEY& key, VALUES& members, int count) {
    if (0==count) {
        return command_list(dbi, members, "SRANDMEMBER %s", key.c_str());
    }
    return command_list(dbi, members, "SRANDMEMBER %s %d", key.c_str(), count);
}
Example #17
0
 // and constructor, mutator/observer methods for the list element fields
 ListElement( int k, string &n ) { key.setKey( k ); name = n; }
Example #18
0
 bool operator()( const KEY& lhs, const KEY& rhs ) const
 {
     boost::shared_ptr<KEY::element_type> shared_lhs = lhs.lock();
     boost::shared_ptr<KEY::element_type> shared_rhs = rhs.lock();   
     return *shared_lhs < *shared_rhs;
 }
Example #19
0
 size_t operator()( const KEY& key ) const
 {
     boost::shared_ptr<KEY::element_type> shared_key = key.lock();   
     return static_cast<size_t>( *shared_key );
 }
Example #20
0
 // very simple callback method for linked list's print list method's use
 void PrintCallback( void ) { cout << key.getKey() << '\t' << name << endl; }
Example #21
0
 int getKey( void ) { return key.getKey(); }
Example #22
0
void KMplex::resample()
{
    std::cout << "KMplex::resample" << std::endl;

    // Build dissimilarity matrix for clustered data X
    const MATRIX& X(*(kmeans_->X_));
    D_.resize(X.rows(), X.rows());

    std::cout << "\nKMplex: (Allocation rule: "
              << (unsigned)alloc_ << ")" << std::endl;
    for(unsigned i = 0; i < kmeans_->K(); ++i)
    {
        const KMeans::Cluster& cluster(kmeans_->cluster(i));

        if(cluster.size() > 0)
        {
            unsigned NTr = trainingQuota(cluster);
            unsigned NTe = testingQuota(cluster);
            unsigned NVa = validatingQuota(cluster);

            std::cout << "Cluster (" << i << ") N: " << cluster.size() <<
                      " NTr: " << NTr <<
                      " NTe: " << NTe <<
                      " NVa: " << NVa << std::endl;

            // Calculate intra-cluster distances
            KEY indices = kmeans_->cluster(i).indices();
            for(KEY::iterator a = indices.begin(); a != indices.end(); ++a)
                for(KEY::iterator b = a + 1; b != indices.end(); ++b)
                {
                    D_[*a][*b] = euclidean(X[*a], X[*b]);
                    D_[*b][*a] = D_[*a][*b];
                }

            // Initialise samples
            KEY training, testing, validating;
            if(NTr > 0)
                initialise(indices, training);

            if(NTe > 0)
                initialise(indices, testing);

            if(NVa > 0)
                initialise(indices, validating);

            // Sample remaining points using Duplex sampling
            while(indices.size() > 0)
            {
                if(training.size() < NTr)
                    sample(indices, training);

                if(testing.size() < NTe)
                    sample(indices, testing);

                if(validating.size() < NVa)
                    sample(indices, validating);
            }

            // Add intra-cluster samples to respective global samples
            if(training.size() > 0)
                merge(training, trainingKey_);

            if(testing.size() > 0)
                merge(testing, testingKey_);

            if(validating.size() > 0)
                merge(validating, validatingKey_);
        }
    }

    allocate(trainingKey_, training_);
    allocate(testingKey_, testing_);
    allocate(validatingKey_, validating_);
}
Example #23
0
 bool operator >=( int rhs ) { return key.getKey() >= rhs; }
Example #24
0
 ListElement() { key.setKey( defaultKey ); name = ""; }
Example #25
0
bool xRedisClient::spop(const RedisDBIdx& dbi,  const KEY& key, VALUE& member) {
    return command_string(dbi, member, "SPOP %s", key.c_str());
}
Example #26
0
bool xRedisClient::smember(const RedisDBIdx& dbi,  const KEY& key, VALUES& vValue) {
    return command_list(dbi, vValue, "SMEMBER %s", key.c_str());
}
Example #27
0
bool xRedisClient::sismember(const RedisDBIdx& dbi,  const KEY& key,   const VALUE& member) {
    return command_bool(dbi, "SISMEMBER %s %s", key.c_str(), member.c_str());
}
Example #28
0
 // also, since the key is an int, define operators on int keys
 bool operator >( int rhs ) { return key.getKey() > rhs; }
Example #29
0
bool xRedisClient::smove(const RedisDBIdx& dbi,  const KEY& srckey, const KEY& deskey,  const VALUE& member) {
    return command_bool(dbi, "SMOVE %s", srckey.c_str(), deskey.c_str(), member.c_str());
}
Example #30
0
  void Locality_Splitter::prepare_sub_plan (
      uint32_t instance,
      Deployment::DeploymentPlan &sub_plan,
      KEY &sub_plan_key)
  {
    DANCEX11_LOG_TRACE ("Locality_Splitter::prepare_sub_plan");

    // first time?
    if (sub_plan_key.uuid ().empty ())
      {
        // use UUID to uniquely identify sub plan key
        sub_plan_key.uuid (sub_plan.UUID ());
      }
    if (sub_plan_key.node () != this->plan_.instance ()[instance].node ())
      {
        // set sub plan key to node name for instance
        sub_plan_key.node (this->plan_.instance ()[instance].node ());
      }
    if (!sub_plan_key.has_instance (instance))
      {
        sub_plan_key.add_instance (instance);

        if (!sub_plan_key.has_locality_manager ())
          {
            // check if this is the LocalityManager instance
            uint32_t impl_idx =
              this->plan_.instance ()[instance].implementationRef ();

            if (impl_idx >= this->plan_.implementation ().size ())
              {
                DANCEX11_LOG_ERROR ("Locality_Splitter::prepare_sub_plan - " <<
                                    "Invalid implementation index");
              }
            else
              {
                const std::string instance_type =
                  DAnCE::Utility::get_instance_type (
                    plan_.implementation ()[impl_idx].execParameter ());
                if (!instance_type.empty ())
                  {
                    if (instance_type == DANCE_LOCALITYMANAGER)
                      {
                        // mark locality manager instance offset
                        sub_plan_key.locality_manager_instance (
                          sub_plan_key.instances ().size () - 1);

                        DANCEX11_LOG_TRACE ("Locality_Splitter::prepare_sub_plan - " <<
                                            "Found locality manager instance " <<
                                            instance << ":" << plan_.instance ()[instance].name ());
                      }
                  }
              }
          }
      }
    if (sub_plan.label ().empty ())
      {
        // derive descriptive label
        std::string sub_label ("Split plan from ");
        if (!this->plan_.label ().empty ())
          {
            sub_label += this->plan_.label ();
          }
        else
          {
            sub_label += this->plan_.UUID ();
          }
        sub_label += " for a Locality on Node ";
        sub_label += sub_plan_key.node ();
        sub_plan.label (sub_label);
      }
  }