예제 #1
0
store::IndexCondition_t IndexImpl::createCondition(store::IndexCondition::Kind k)
{
  if (!isSorted() &&
      (k == store::IndexCondition::BOX_VALUE || 
       k == store::IndexCondition::BOX_GENERAL))
  {
    RAISE_ERROR_NO_LOC(zerr::ZSTR0007_INDEX_UNSUPPORTED_PROBE_CONDITION,
    ERROR_PARAMS(IndexConditionImpl::getKindString(k), getName()->getStringValue()));
  }

  if (isGeneral())
  {
    return new GeneralIndexCondition(this, k);
  }
  else if (k == store::IndexCondition::POINT_VALUE)
  {
    return new IndexPointCondition(this, k);
  }
  else if (k == store::IndexCondition::BOX_VALUE)
  {
    return new IndexBoxValueCondition(this, k);
  }
  else
  {
    RAISE_ERROR_NO_LOC(zerr::ZSTR0007_INDEX_UNSUPPORTED_PROBE_CONDITION,
    ERROR_PARAMS(IndexConditionImpl::getKindString(k), getName()->getStringValue()));

    ZORBA_ASSERT(false);
  }
}
예제 #2
0
//------------
// Constructor
//------------
XEMModel::XEMModel(XEMModelType * modelType, int64_t  nbCluster, XEMData *& data, XEMPartition *& knownPartition) {
    int64_t  k;
    int64_t  i;
    _deleteData = false;
    _nbCluster     = nbCluster;
    _data          = data;
    _nbSample      = _data->_nbSample;
    _algoName = UNKNOWN_ALGO_NAME;

    _tabFik = new double*[_nbSample];
    _tabCik = new double*[_nbSample];
    _tabSumF = new double[_nbSample];
    _tabTik = new double*[_nbSample];
    _tabZikKnown = new int64_t *[_nbSample];
    _tabZiKnown = new bool[_nbSample];
    _tabNk = new double[_nbCluster];

    for (i=0; i<_nbSample; i++) {
        _tabFik[i] = new double[_nbCluster];
        _tabTik[i] = new double[_nbCluster];
        _tabZikKnown[i] = new int64_t [_nbCluster];
        _tabCik[i] = new double[_nbCluster];
        for (k=0; k<_nbCluster; k++) {
            _tabFik[i][k] = 0.0;
            _tabTik[i][k] = 0.0;
            _tabZikKnown[i][k] = 0;
            _tabCik[i][k] = 0.0;
        }
        _tabZiKnown[i] = false;
        _tabSumF[i]     = 0.0;
    }

    // _tabNk[k] = 0 even if knownPartition because this partition could be partial
    for (k=0; k<_nbCluster; k++) {
        _tabNk[k] = 0.0;
    }

    FixKnownPartition(knownPartition);
    XEMModelName modelName = modelType->_nameModel;
    // create Param
    if (isSpherical(modelName)) {
        _parameter = new XEMGaussianSphericalParameter(this, modelType);
    }
    if (isDiagonal(modelName)) {
        _parameter = new XEMGaussianDiagParameter(this, modelType);
    }
    if (isGeneral(modelName)) {
        _parameter = new XEMGaussianGeneralParameter(this, modelType);
    }


    //HDDA models
    if (isHD(modelName)) {
        _parameter = new XEMGaussianHDDAParameter(this, modelType);
    }


    switch(modelName) {
    // Binary models //
    case (Binary_p_E):
        _parameter = new XEMBinaryEParameter(this, modelType, ((XEMBinaryData*)data)->getTabNbModality());
        break;
    case (Binary_p_Ek):
        _parameter = new XEMBinaryEkParameter(this, modelType, ((XEMBinaryData*)data)->getTabNbModality());
        break;
    case (Binary_p_Ej):
        _parameter = new XEMBinaryEjParameter(this, modelType, ((XEMBinaryData*)data)->getTabNbModality());
        break;
    case (Binary_p_Ekj):
        _parameter = new XEMBinaryEkjParameter(this, modelType, ((XEMBinaryData*)data)->getTabNbModality());
        break;
    case (Binary_p_Ekjh):
        _parameter = new XEMBinaryEkjhParameter(this, modelType, ((XEMBinaryData*)data)->getTabNbModality());
        break;
    case (Binary_pk_E):
        _parameter = new XEMBinaryEParameter(this, modelType, ((XEMBinaryData*)data)->getTabNbModality());
        break;
    case (Binary_pk_Ek):
        _parameter = new XEMBinaryEkParameter(this, modelType, ((XEMBinaryData*)data)->getTabNbModality());
        break;
    case (Binary_pk_Ej):
        _parameter = new XEMBinaryEjParameter(this, modelType, ((XEMBinaryData*)data)->getTabNbModality());
        break;
    case (Binary_pk_Ekj):
        _parameter = new XEMBinaryEkjParameter(this, modelType, ((XEMBinaryData*)data)->getTabNbModality());
        break;
    case (Binary_pk_Ekjh):
        _parameter = new XEMBinaryEkjhParameter(this, modelType, ((XEMBinaryData*)data)->getTabNbModality());
        break;
    }
}
예제 #3
0
int main(int args, char* argv[]) {
	bool loyal;
	char hostfile[50];
	char command[100];
	char line[50];
	struct mesgPackage mesg;
	FILE* fr;

	pthread_mutex_init(&mutex, NULL);
	gethostname(localhostname, 30);
	checkAndPopulateArgs(args, argv, &loyal, &port, hostfile, command);


	if (strlen(command) != 0) {
		if (strcmp(command, "attack")==0) {
			mesg.message = 1;
		} else if (strcmp(command, "retreat")==0) {
			mesg.message = 0;
		}
	}

	fr = fopen(hostfile, "r");
	if (fr == NULL) {
		perror("file not found: ");
		exit(1);
	}

	while (fgets(line, 30, fr) != NULL) {
		hostnames[++num_hosts] = new char[30];
		strncpy(hostnames[num_hosts], line, strlen(line)-1);

		if (strncmp(line, localhostname, strlen(localhostname))== 0) {
			localhostindex = num_hosts;
		}
	}
	printf("localhostindex = %d\n", localhostindex);
	if (isGeneral(command)) {
		for(int i=1;i<NPROC;i++){
			mesg.pid[i]=0;
		}
		char keyfile[100];
		strcpy(keyfile, "./keys/");
		strcat(keyfile, hostnames[1]);
		strcat(keyfile, ".key");
		for (int i = 1; i <= num_hosts; i++) {
			if (strcmp(hostnames[i], localhostname) != 0) {
				printf("Signing message\n");
				signMessage(mesg.message, keyfile, mesg.signatures[1]);
				mesg.pid[1] = 1;
				sendMessage(mesg, hostnames[i], port);
			}
		}
	} else {
		waitAndProcessMessages(threads, port);
	}
	/*
	 char mesg[30];
	 strcpy(mesg, "rajul");
	 gethostname(myhostname, 30);
	 if(strcmp(argv[1],"server")==0){
	 waitAndProcessMessages(threads, 8080);
	 }else if(strcmp(argv[1],"client")==0){
	 sendMessage(myhostname, mesg, "xinu01.cs.purdue.edu", 8080);
	 }
	 */
	pthread_mutex_destroy(&mutex);
}