Exemplo n.º 1
0
PyObject *getTanimotoSimMat(python::object bitVectList) {
    // we will assume here that we have a either a list of ExplicitBitVectors or
    // SparseBitVects
    int nrows = python::extract<int>(bitVectList.attr("__len__")());
    CHECK_INVARIANT(nrows > 1, "");

    // First check what type of vector we have
    python::object v1 = bitVectList[0];
    python::extract<ExplicitBitVect> ebvWorks(v1);
    python::extract<SparseBitVect> sbvWorks(v1);
    if(!ebvWorks.check() && !sbvWorks.check()) {
        throw_value_error("GetTanimotoDistMat can only take a sequence of ExplicitBitVects or SparseBitvects");
    }

    npy_intp dMatLen = nrows*(nrows-1)/2;
    PyArrayObject *simRes = (PyArrayObject *)PyArray_SimpleNew(1, &dMatLen, NPY_DOUBLE);
    double *sMat = (double *)simRes->data;

    if (ebvWorks.check()) {
        PySequenceHolder<ExplicitBitVect> dData(bitVectList);
        MetricMatrixCalc<PySequenceHolder<ExplicitBitVect>, ExplicitBitVect> mmCalc;
        mmCalc.setMetricFunc(&TanimotoSimilarityMetric<ExplicitBitVect, ExplicitBitVect>);
        mmCalc.calcMetricMatrix(dData, nrows, 0, sMat);
    }
    else if (sbvWorks.check()) {
        PySequenceHolder<SparseBitVect> dData(bitVectList);
        MetricMatrixCalc<PySequenceHolder<SparseBitVect>, SparseBitVect> mmCalc;
        mmCalc.setMetricFunc(&TanimotoSimilarityMetric<SparseBitVect, SparseBitVect>);
        mmCalc.calcMetricMatrix(dData, nrows, 0, sMat);
    }
    return PyArray_Return(simRes);
}
Exemplo n.º 2
0
bool
PxrUsdMayaWriteUtil::ReadMayaAttribute(
        const MFnDependencyNode& depNode,
        const MString& name,
        VtVec3fArray* val)
{
    MStatus status;
    depNode.attribute(name, &status);

    if (status == MS::kSuccess) {
        MPlug plug = depNode.findPlug(name);
        MObject dataObj;

        if ( (plug.getValue(dataObj) == MS::kSuccess) &&
             (dataObj.hasFn(MFn::kVectorArrayData)) ) {

            MFnVectorArrayData dData(dataObj, &status);
            if (status == MS::kSuccess) {
                MVectorArray arrayValues = dData.array();
                size_t numValues = arrayValues.length();
                val->resize(numValues);
                for (size_t i = 0; i < numValues; ++i) {
                    (*val)[i].Set(
                            arrayValues[i][0],
                            arrayValues[i][1],
                            arrayValues[i][2]);
                }
                return true;
            }
        }
    }

    return false;
}
Exemplo n.º 3
0
 //  return a simulation data of the simulated path for the diffusion process
 Utilities::SimulationData DiffusionProcess::simulate(const std::vector<double> &dDates, std::size_t iNPaths) const
 {
     std::vector<std::vector<double> > dData(iNPaths, std::vector<double>(dDates.size(), 0.0));
     
     for (std::size_t iPath = 0 ; iPath < iNPaths ; ++iPath)
     {
         dData[iPath] = simulate1path(dDates);
     }
     
     Utilities::SimulationData result(dData, dDates);
     return result;
 }
Exemplo n.º 4
0
DungeonData MysteryDungeonMaker::DungeonData()
{
	::DungeonData dData(dungeonSize->DungeonHeight(), dungeonSize->DungeonWidth());

	const size_t rowNum = dungeonSize->DungeonHeight();
	const size_t columnNum = dungeonSize->DungeonWidth();
	for (size_t i = 0; i < rowNum; i++)
	{
		for (size_t j = 0; j < columnNum; j++)
		{
			dData.AddType(Component(i, j), tiles[i][j]);
		}
	}

	return dData;
}
Exemplo n.º 5
0
/*********************************
 * loadData関数
 * @param  string filename ファイル名
 * @param  char delim 分割文字列
 * @return dData データ
 * @note : 行の先頭が"#"の時は読み飛ばす
 *       : "@"から始まるデータはラベル
 ********************************/
dData loadData(string filename, const char delim)
{
	ifstream ifs(filename.c_str());
	string line;
	stringstream ss;
	vector<string> strs;
	vector<string> label;
	bool setLabel;

	//
	int len;
	int dim;
	vector<double> dat;

	// ファイル読み込みを失敗した場合
	if (ifs.fail()) {
		cout << "File load error. (" << filename << ")" << endl;
		return dData();
	}

	// ファイルの中身を1行ずつ読み込み
	len = 0;
	while (getline(ifs, line)) {

		if ('#' == (line.c_str())[0] || line.size() < 1) {
			continue;
		}

		double val;

		strs = split(line, delim);
		dim = (int) strs.size();

		setLabel = false;
		for (int d = 0; d < (int) strs.size(); d++) {
			if ('@' == (strs[d].c_str())[0] && !setLabel) {
				setLabel = true;
				label.push_back(strs[d]);
				continue;
			}

			// 文字列から数値に変換
			ss << strs[d];
			ss >> val;

			dat.push_back(val);

			ss.clear(); // 状態をクリア.
			ss.str(""); // 文字列をクリア.
		}

		++len;
	}

	// 結果保存用
	double *res = new double[len * dim];
	for (int p = 0; p < len * dim; p++) {
		res[p] = dat[p];
	}
	if (setLabel) {
		--dim;
	}

	return dData(res, len, dim, label);
}
Exemplo n.º 6
0
int 
MeshRegion::recvSelf(int commitTag, Channel &theChannel, 
		 FEM_ObjectBroker &theBroker)
{
  // get my current database tag
  // NOTE - dbTag equals 0 if not sending to a database OR has not yet been sent
  int myDbTag = this->getDbTag();

  // into an ID we place all info needed to determine state of MeshRegion
  ID lpData(6);

  if (theChannel.recvID(myDbTag, commitTag, lpData) < 0) {
   opserr << "MeshRegion::recvSelf - channel failed to recv the initial ID\n";
    return -1;
  }

  // only recv the nodes & ele if not current
  if (currentGeoTag != lpData(0)) {

    currentGeoTag = lpData(0);
    this->setTag(lpData(1));

    int numEle = lpData(2);
    int numNod = lpData(3);
    if (theNodes != 0) {
      delete theNodes;
      theNodes = 0;
    }
    if (theElements != 0) {
      delete theElements;      
      theElements = 0;
    }

    if (numEle != 0)
      theElements = new ID(numEle); 
    if (numNod != 0)
      theNodes = new ID(numNod); 

    if (numNod != 0) 
      if (theChannel.recvID(dbNod, currentGeoTag, *theNodes) < 0) {
	opserr << "MeshRegion::sendSelf - channel failed to recv the nodes\n";
	return -1;
      }
    if (numEle != 0) 
      if (theChannel.recvID(dbEle, currentGeoTag, *theElements) < 0) {
	opserr << "MeshRegion::sendSelf - channel failed to recv the elements\n";
	return -1;
      }

    Vector dData(4);

    if (theChannel.sendVector(dbEle, currentGeoTag, dData) < 0) {
     opserr << "MeshRegion::sendSelf - channel failed to send the elements\n";
      return -1;
    }  
    alphaM = dData(0);
    betaK  = dData(1);
    betaK0 = dData(2);
    betaKc = dData(3);
  }


  this->setRayleighDampingFactors(alphaM, betaK, betaK0, betaKc);
  return 0;
}
Exemplo n.º 7
0
int 
MeshRegion::sendSelf(int commitTag, Channel &theChannel)
{
  // get my current database tag
  // NOTE - dbTag equals 0 if not sending to a database OR has not yet been sent
  int myDbTag = this->getDbTag();

  // into an ID we place all info needed to determine state of LoadPattern
  ID lpData(6);
  lpData(0) = currentGeoTag;
  lpData(1) = this->getTag();

  int numEle= theElements->Size();
  int numNod = theNodes->Size();

  lpData(2) = numEle;
  lpData(3) = numNod;

  if (dbNod == 0) {
    dbNod = theChannel.getDbTag();
    dbEle = theChannel.getDbTag();
  } 

  lpData(4) = dbNod;
  lpData(5) = dbEle;

  if (theChannel.sendID(myDbTag, commitTag, lpData) < 0) {
   opserr << "MeshRegion::sendSelf - channel failed to send the initial ID\n";
    return -1;
  }    


  // now check if data defining the objects in the LoadPAttern needs to be sent 
  // NOTE THIS APPROACH MAY NEED TO CHANGE FOR VERY LARGE PROBLEMS IF CHANNEL CANNOT
  // HANDLE VERY LARGE ID OBJECTS.
  if (lastGeoSendTag != currentGeoTag) {
    if (numNod != 0) 
      if (theChannel.sendID(dbNod, currentGeoTag, *theNodes) < 0) {
	opserr << "MeshRegion::sendSelf - channel failed to send the nodes\n";
	return -1;
      }
    if (numEle != 0) 
      if (theChannel.sendID(dbEle, currentGeoTag, *theElements) < 0) {
	opserr << "MeshRegion::sendSelf - channel failed to send the elements\n";
	return -1;
      }

    Vector dData(4);
    dData(0) = alphaM;
    dData(1) = betaK;
    dData(2) = betaK0;
    dData(3) = betaKc;

    if (theChannel.sendVector(dbEle, currentGeoTag, dData) < 0) {
     opserr << "MeshRegion::sendSelf - channel failed to send the elements\n";
      return -1;
    }  

    // set the lst send db tag so we don't have to send them again unless they change
    lastGeoSendTag = currentGeoTag;
  }    


  
  return 0;
}
Exemplo n.º 8
0
		void Record::Write( ISocket& socket ) const {
			socket.Send( &mType, sizeof( unsigned char ) );
			socket.Send( &mVersion.Major, sizeof( unsigned char ) );
			socket.Send( &mVersion.Minor, sizeof( unsigned char ) );
			
			if( mEncryption->Name() != "None" ) {
				std::vector<unsigned char> dData( mData.begin(), mData.end() );
				
				/* Calculate MAC */
				std::vector<unsigned char> signiture;
				Insert( signiture, htonll( RecordsSent ) );
				Insert( signiture, (unsigned char) mType );
				Insert( signiture, (unsigned char) mVersion.Major );
				Insert( signiture, (unsigned char) mVersion.Minor );
				Insert( signiture, htons( (unsigned short) mData.size() ) );
				signiture.insert( signiture.end(), mData.begin(), mData.end() );
				
				std::vector<unsigned char> hash = mEncryption->CalculateHash( signiture );
				RecordsSent++;
				
				dData.insert( dData.end(), hash.begin(), hash.end() );
				
				/* Calculate Padding */
				unsigned int size = dData.size();
				unsigned int remainder = 16 - (size - (16 * std::floor( dData.size() / 16.0 )));
				if( remainder != 0 ){
					remainder--;
					for( unsigned int i = 0; i < remainder; i++ ){
						dData.push_back( remainder );
					}
				}
				dData.push_back( remainder );
				
				std::vector<unsigned char> eData = mEncryption->Encrypt( dData );
				
				unsigned short length = htons( eData.size() );
				socket.Send( &length, sizeof( unsigned short ) );
				
				socket.Send( &eData[0], sizeof( unsigned char ) * eData.size() );
				
				//std::cout << "Encrypted: " << std::dec << (int)eData.size() << std::endl;
				//for( unsigned int i = 0 ; i < eData.size(); i++ ){
				//	std::cout << std::hex << std::setw( 2 ) << std::setfill('0') << (int) eData[i] << " ";;
				//	if( (i + 1) % 16 == 0 ) std::cout << std::endl;
				//}
				//std::cout << std::endl;
			}else{
				unsigned short length = htons( mLength );
				socket.Send( &length, sizeof( unsigned short ) );
				
				socket.Send( &mData[0], sizeof( unsigned char ) * mLength );
				
				//std::cout << "Sent: " << std::dec << (int)mData.size() << std::endl;
				//for( unsigned int i = 0 ; i < mData.size(); i++ ){
				//	std::cout << std::hex << std::setw( 2 ) << std::setfill('0') << (int) mData[i] << " ";;
				//	if( (i + 1) % 16 == 0 ) std::cout << std::endl;
				//}
				//std::cout << std::endl;
			}

			//std::cout << std::endl;
		}
bool CDropManager::loadDropData(MYSQL * _dataDB)
{
	CDBCmd cmdHead;
	cmdHead.Init(_dataDB);

	std::string sql = "SELECT * FROM t_drop_item_head ORDER BY a_drop_idx";

	cmdHead.SetQuery(sql);

	if( !cmdHead.Open() || !cmdHead.MoveFirst() )
	{
		GAMELOG << init("EVENT_AUTOMATION_WARN") << "NO EXIST TABLE DROP ITEM HEAD" << end;
		return false;\
	}

	if( cmdHead.m_nrecords < 1 )
	{
		GAMELOG << init("EVENT_AUTOMATION_WARN") << "EMPTY TABLE DROP ITEM HEAD" << end;
		return false;
	}

	CDBCmd cmdData;
	cmdData.Init(_dataDB);

	int dropIndex=0, dropType=0, levelmini=0, levelMaxi=0, dropProb=0, probPerLevel=0, party=1, boss=1;
	CLCString npclist;
	CLCString levelsection(256);
	do
	{
		if(    !cmdHead.GetRec("a_drop_idx",		dropIndex)
				|| !cmdHead.GetRec("a_drop_type",		dropType)
				|| !cmdHead.GetRec("a_level_mini",		levelmini)
				|| !cmdHead.GetRec("a_level_maxi",		levelMaxi)
				|| !cmdHead.GetRec("a_prob",			dropProb)
				|| !cmdHead.GetRec("a_prob_level",		probPerLevel)
				|| !cmdHead.GetRec("a_npc_type_party",	party)
				|| !cmdHead.GetRec("a_npc_type_boss",	boss)
				|| !cmdHead.GetRec("a_npc",				npclist)
				|| !cmdHead.GetRec("a_level_section",	levelsection)
		  )
		{
			GAMELOG << init("EVENT_AUTOMATION_WARN") << "NOT MATCHING FIELD IN TABLE DROP ITEM HEAD" << end;
			return false;
		}

		std::string select_drop_item_data_sql = boost::str(boost::format("SELECT * FROM t_drop_item_data WHERE a_drop_idx=%d ") % dropIndex);
		cmdData.SetQuery( select_drop_item_data_sql );

		if( !cmdData.Open()  )
		{
			GAMELOG << init("EVENT_AUTOMATION_WARN") << "NO EXIST TABLE DROP ITEM DATA" << end;
			return false;
		}

		if( !cmdData.MoveFirst() )
			continue;

		if( cmdData.m_nrecords < 1 )
			continue;

		CDropInfo dData(dropIndex, dropType, levelmini, levelMaxi, dropProb, probPerLevel, party, boss);

		const char* pArg = npclist;
		char buf[8]= {0,};
		int npcIndex=0;
		while (*pArg)
		{
			pArg = AnyOneArg(pArg, buf);
			npcIndex = atoi(buf);
			if( npcIndex > 0 )
				dData.addNpc( npcIndex);
		}

		pArg = levelsection;
		int lvlstart, lvlend, lvlprob;
		while (*pArg)
		{
			pArg = AnyOneArg(pArg, buf);
			lvlstart	= atoi(buf);
			pArg = AnyOneArg(pArg, buf);
			lvlend		= atoi(buf);
			pArg = AnyOneArg(pArg, buf);
			lvlprob		= atoi(buf);

			if( lvlprob > 0 )
			{
				CProbByLevelSection ls(lvlstart, lvlend, lvlprob);
				dData.addLevelSection( ls );
			}
		}

		int index=0, plus=0, flag=0, prob=0, jobFlag =0;
		LONGLONG count=0;

		do
		{
			if(	   !cmdData.GetRec("a_item_idx",	index)
					|| !cmdData.GetRec("a_plus",		plus)
					|| !cmdData.GetRec("a_flag",		flag)
					|| !cmdData.GetRec("a_count",		count)
					|| !cmdData.GetRec("a_prob",		prob)
					|| !cmdData.GetRec("a_job_flag",	jobFlag)
			  )
			{
				GAMELOG << init("EVENT_AUTOMATION_WARN") << "NOT MATCHING FIELD IN TABLE DROP ITEM DATA" << end;
				return false;
			}

			CDropItemData diData(index, plus, flag, count, prob, jobFlag );
			dData.addItem( diData );
		}
		while( cmdData.MoveNext() );

		m_dataList.insert( std::map<int,CDropInfo>::value_type( dropIndex, dData ) );
	}
	while( cmdHead.MoveNext() );

	return true;
}