void CGameLogic_G::InitMap(CGraph &g) { int nRows = CGameControl_G::s_nRows; int nCols = CGameControl_G::s_nCols; for (int i = 0;i < nRows;i++) { for (int j = 0;j < nCols;j++) { g.m_Vertices[i*nCols + j] = j; } } srand((int)time(NULL)); int nVertexNum = nRows*nCols; for (int i = 0;i < nVertexNum;i++) { int nIndex1 = rand() % nVertexNum; int nIndex2 = rand() % nVertexNum; int nTmp = g.GetVertex(nIndex1); g.SetVertex(nIndex1,g.GetVertex(nIndex2)); g.SetVertex(nIndex2, nTmp); } for (int i = 0;i < 100;i++) { for (int j = 0;j < 100;j++) { g.m_AdjMatrix[i][j] = 1; } } }
void CDynamicGraphicalModel::FindInterfaceNodes() { int i, j; CGraph *graph = m_pGrModel->GetGraph(); int nnodes = graph->GetNumberOfNodes(); int numberOfNeighbors; const int *neighbors; const ENeighborType *orientation; for( i = 0; i < nnodes/2; i++ ) { graph->GetNeighbors(i, &numberOfNeighbors, &neighbors, &orientation); for( j = 0; j < numberOfNeighbors; j++ ) { if( neighbors[j] >= nnodes/2 ) { m_InterfaceNodes.push_back(i); break; } } } }
void CGraphPersistence::Save(CPNLBase *pObj, CContextSave *pContext) { CGraph *pG = dynamic_cast<CGraph*>(pObj); std::stringstream buf; PNL_CHECK_IS_NULL_POINTER(pG); int nNode = pG->GetNumberOfNodes(); intVector neig; neighborTypeVector neigType; pContext->AddAttribute("SavingType", "ByEdges"); { char buf2[12]; sprintf(buf2, "%i", nNode); pContext->AddAttribute("NumberOfNodes", buf2); } for(int i = 0; i < nNode; ++i) { pG->GetNeighbors(i, &neig, &neigType); buf << i << ":"; for(int j = neig.size(); --j >= 0;) { buf << neig[j] << "_(" << neighTypeSymbols[neigType[j]] << ") "; } buf << '\n'; } pContext->AddText(buf.str().c_str()); }
bool GameLogic::SearchValidPath(CGraph& graph) { //得到顶点数 int nVexnum = graph.GetVexnum(); for (int i = 0; i < nVexnum; i++) { //得到第一个非空顶点 //遍历得到第二个同色顶点 for (int j = 0; j < nVexnum; j++) { if (i != j) { //如果i和j同色 int nInfo1 = graph.GetVertex(i); int nInfo2 = graph.GetVertex(j); if (nInfo1 == nInfo2 && nInfo1 != BLANK && nInfo2 != BLANK) { //压入第一个顶点 PushVertex(i); //搜寻两个点之间的连通路径 if (SearchPath2(graph, i, j)) { return true; } PopVertex(); } } } } return false; }
bool GameLogic::SearchPath2(CGraph &graph, int nV0, int nV1) { //得到顶点数 int nVexnum = graph.GetVexnum(); //遍历图中nV0行,从0列到nVexnum列,值为true的点 for (int nVi = 0; nVi < nVexnum; nVi++) { if (graph.GetArc(nV0, nVi) && !IsExist(nVi)) { //压入当前顶点。假设为路径的一个有效顶点 PushVertex(nVi); if (m_nCorner > 2) { PopVertex(); continue; } if (nVi != nV1) { //当中间顶点为空时,表示该条路径不通 if (graph.GetVertex(nVi) != BLANK) { PopVertex(); continue; } //如果nVi是一个已消除的点,则判断(nVi,nV1)是否连通 if (SearchPath2(graph, nVi, nV1)) { return true; } } else { return true; } PopVertex(); } } return false; }
std::vector<size_t> CPathFinder::findPath(CAlgorithm alhorithm) const { std::vector<size_t> path; path.reserve(pointsAmount); switch (alhorithm) { case kruskalMST: { CGraph minimumSpanningTree = kruskalFindMST(); path = minimumSpanningTree.rebuildWay(); break; } case bruteForce: { std::vector<bool> visited(pointsAmount, false); std::vector<size_t> way; way.reserve(pointsAmount); double bestLength = -1; double currentLength = 0; bruteForceSearch(visited, way, currentLength, path, bestLength); break; } default: assert(false); } std::cout << "Length is " << checkPath(path) << '\n'; return path; }
// ======================================== Graph Extensions ======================================== void testGraphExtension(CGraphExt& graphExt, CGraph& graph) { const byte nStates = graph.getNumStates(); Size graphSize = Size(random::u<int>(10, 100), random::u<int>(10, 100)); graphExt.buildGraph(graphSize); ASSERT_EQ(graphSize, graphExt.getSize()); ASSERT_EQ(graphSize.width * graphSize.height, graph.getNumNodes()); graphSize = Size(random::u<int>(10, 100), random::u<int>(10, 100)); Mat pots = random::U(graphSize, CV_32FC(nStates)); graphExt.setGraph(pots); ASSERT_EQ(graphSize, graphExt.getSize()); Mat test_pots; graph.getNodes(0, 0, test_pots); test_pots = test_pots.clone().reshape(graph.getNumStates(), graphSize.height); ASSERT_EQ(pots.rows, test_pots.rows); for (int y = 0; y < test_pots.rows; y++) { float *pPots = pots.ptr<float>(y); float *pTestPots = test_pots.ptr<float>(y); for (int x = 0; x < test_pots.cols; x++) for (int c = 0; c < test_pots.channels(); c++) ASSERT_EQ(pPots[x * nStates + c], pTestPots[x * nStates + c]); } // void addDefaultEdgesModel(float val, float weight = 1.0f); // void addDefaultEdgesModel(const Mat &featureVectors, float val, float weight); // void addDefaultEdgesModel(const vec_mat_t &featureVectors, float val, float weight); }
bool GameLogic::IsBlank(CGraph &graph) { for (int i = 0; i < graph.GetVexnum(); i++) { if (graph.GetVertex(i) != BLANK) { return false; } } return true; }
CBNet* CreateTwoNodeExDiscrete(void) { const int numOfNds = 2; int numOfNbrs[numOfNds] = { 1, 1 }; int nbrs0[] = { 1 }; int nbrs1[] = { 0 }; ENeighborType nbrsTypes0[] = { ntChild }; ENeighborType nbrsTypes1[] = { ntParent }; int *nbrs[] = { nbrs0, nbrs1 }; ENeighborType *nbrsTypes[] = { nbrsTypes0, nbrsTypes1 }; CGraph* pGraph = CGraph::Create( numOfNds, numOfNbrs, nbrs, nbrsTypes ); // 2) Creation of the Model Domain. CModelDomain* pMD; nodeTypeVector variableTypes; int nVariableTypes = 1; variableTypes.resize( nVariableTypes ); variableTypes[0].SetType( 1, 2 ); // discrete, 2 states intVector variableAssociation; int nnodes = pGraph->GetNumberOfNodes(); variableAssociation.assign(nnodes, 1); variableAssociation[0] = 0; variableAssociation[1] = 0; pMD = CModelDomain::Create( variableTypes, variableAssociation ); // 2) Creation base for BNet using Graph, and Model Domain CBNet *pBNet = CBNet::Create(pGraph, pMD); // 3)Allocation space for all factors of the model pBNet->AllocFactors(); int nnodes0 = 1; int domain0[] = { 0 }; float table0[] = { 0.3f, 0.7f}; CTabularCPD *pCPD0 = CTabularCPD::Create( domain0, nnodes0, pMD, table0 ); pCPD0->AllocMatrix(table0, matTable); pBNet->AttachParameter(pCPD0); int nnodes1 = 2; int domain1[] = { 0, 1 }; float table1[] = { 0.3f, 0.7f, 0.3f, 0.7f}; CTabularCPD *pCPD1 = CTabularCPD::Create( domain1, nnodes1, pMD, table1 ); pCPD1->AllocMatrix(table1, matTable); pBNet->AttachParameter(pCPD1); return pBNet; }
CGraph* CreateGraphWithPyramidSpecific(int& num_nodes, int num_indep_nodes, int num_layers) { PNL_CHECK_LEFT_BORDER( num_indep_nodes, 1 ); PNL_CHECK_LEFT_BORDER( num_layers, 1 ); int i, j, k; CGraph *pGraph = CGraph::Create(0, NULL, NULL, NULL); PNL_CHECK_IF_MEMORY_ALLOCATED( pGraph ); srand((unsigned int)time(NULL)); num_nodes = num_indep_nodes; int num_nodes_into_curr_layer = num_indep_nodes; for (i = 0; i < num_layers - 1; i++) { num_nodes += num_nodes_into_curr_layer * 2 + 1; num_nodes_into_curr_layer = num_nodes_into_curr_layer * 2 + 1; } pGraph->AddNodes(num_nodes); int StartParent = 0, EndParent = num_indep_nodes - 1, StartCurrLayer, EndCurrLayer; int Child1, Child2, Child3; int NumParents; for (int layer = 0; layer < num_layers - 1; layer++ ) { StartCurrLayer = EndParent + 1; EndCurrLayer = StartCurrLayer + 2 * (EndParent - StartParent + 1); NumParents = 0; for (j = StartParent; j <= EndParent; j++ ) { Child1 = EndParent + NumParents * 2 + 1; Child2 = EndParent + NumParents * 2 + 2; Child3 = EndParent + NumParents * 2 + 3; pGraph->AddEdge(j, Child1, 1); pGraph->AddEdge(j, Child2, 1); pGraph->AddEdge(j, Child3, 1); NumParents++; } StartParent = StartCurrLayer; EndParent = EndCurrLayer; } return pGraph; }
void updateGraph () { if (!ShowGraph) return; FpsGraph.render (); SpfGraph.render (); DownloadGraph.render (); UploadGraph.render (); }
CGraph *C1_5SliceInfEngine::Create1_5SliceGraph() { int node, i, j; CGraph *graph = GrModel()->GetGraph(); int nnodesInDBN = graph->GetNumberOfNodes(); int numberOfInterfaceNodes; const int *interfaceNodes; GrModel()->GetInterfaceNodes(&numberOfInterfaceNodes, &interfaceNodes); int nnodes = nnodesInDBN/2 + numberOfInterfaceNodes; CGraph *pFinalGraph = CGraph::Create( nnodes, NULL, NULL, NULL ); PNL_CHECK_IF_MEMORY_ALLOCATED( pFinalGraph ); int numberOfNeighbors; const int *neighbors; const ENeighborType *orientation; int newNumber; intVector FinalNeighbors; pnlVector<ENeighborType> FinalOrientation; intVector newIntNodes( numberOfInterfaceNodes ); int numberOfNonIntNodes = nnodesInDBN/2 - numberOfInterfaceNodes; for ( node = 0; node < numberOfInterfaceNodes; node++ ) { newIntNodes[node] = interfaceNodes[node] - numberOfNonIntNodes; } for( i = nnodesInDBN/2; i < nnodesInDBN; i++ ) { graph->GetNeighbors(i, &numberOfNeighbors, &neighbors, &orientation); FinalNeighbors.resize(numberOfNeighbors); for ( j = 0; j < numberOfNeighbors; j++ ) { newNumber = neighbors[j] - numberOfNonIntNodes; FinalNeighbors[j] = ( newNumber < numberOfInterfaceNodes ) ? ( std::find( newIntNodes.begin(), newIntNodes.end(), newNumber) - newIntNodes.begin() ) : newNumber; } pFinalGraph->SetNeighbors( i - numberOfNonIntNodes, numberOfNeighbors, &(FinalNeighbors.front()), orientation ); } return pFinalGraph; }
void addGraph( CGraph &graph ) { // Frist check that all the node types in the graph have been added to the training dataset std::vector<CNodeTypePtr> v_nodeTypes = graph.getNodeTypes(); bool found = true; size_t i = 0; while ( found && (i < v_nodeTypes.size() ) ) { size_t j = 0; while ( (j < m_nodeTypes.size()) && v_nodeTypes[i]->getID() != m_nodeTypes[j]->getID() ) j++; if ( j == m_nodeTypes.size() ) found = false; i++; } if ( !found ) cerr << " [ERROR] Included a graph with node types that have not been included in the training dataset" << endl; m_graphs.push_back( graph ); }
void UPGMpp::getRandomAssignation(CGraph &graph, map<size_t,size_t> &assignation, TInferenceOptions &options ) { static boost::mt19937 rng1; static bool firstExecution = true; if ( firstExecution ) { rng1.seed(std::time(0)); firstExecution = false; } vector<CNodePtr> &nodes = graph.getNodes(); for ( size_t node = 0; node < nodes.size(); node++ ) { // TODO: Check if a node has a fixed value and consider it size_t N_classes = nodes[node]->getType()->getNumberOfClasses(); boost::uniform_int<> generator(0,N_classes-1); int state = generator(rng1); assignation[nodes[node]->getID()] = state; } /*map<size_t,size_t>::iterator it; for ( it = assignation.begin(); it != assignation.end(); it++ ) cout << "[" << it->first << "] " << it->second << endl;*/ }
void GameLogic::InitMap(CGraph &graph) { int anTemp[MAX_VERTEX_NUM]; for (int i = 0; i < REPEAT_NUM; i++) { for (int j = 0; j < MAX_PIC_NUM; j++) { anTemp[i * MAX_PIC_NUM + j] = j; } } srand((int)time(NULL)); for (int i = 0; i < MAX_VERTEX_NUM; i++) { int nIndex1 = rand() % MAX_VERTEX_NUM; int nIndex2 = rand() % MAX_VERTEX_NUM; int nTemp = anTemp[nIndex1]; anTemp[nIndex1] = anTemp[nIndex2]; anTemp[nIndex2] = nTemp; } for (int i = 0; i < MAX_ROW; i++) { for (int j = 0; j < MAX_COL; j++) { graph.AddVertex(anTemp[i * MAX_PIC_NUM + j]); UpdateArc(graph, i, j); } } }
CGraph* CreateCompleteGraph(int num_nodes) { PNL_CHECK_LEFT_BORDER( num_nodes, 1 ); int i, j, k; CGraph *pGraph = CGraph::Create(0, NULL, NULL, NULL); PNL_CHECK_IF_MEMORY_ALLOCATED( pGraph ); srand((unsigned int)time(NULL)); pGraph->AddNodes(num_nodes); for (j = 1; j < num_nodes; j++ ) for (i = 0; i < j; i++ ) pGraph->AddEdge(i, j, 1); return pGraph; }
void GameLogic::Clear(CGraph &graph, Vertex v1, Vertex v2) { int nV1Index = v1.row * MAX_PIC_NUM + v1.col; int nV2Index = v2.row * MAX_PIC_NUM + v2.col; graph.UpdateVertex(nV1Index, BLANK); graph.UpdateVertex(nV2Index, BLANK); UpdateArc(graph, v1.row, v1.col); UpdateArc(graph, v2.row, v2.col); }
/* ~~~ FUNCTION (public) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * This function computes the route to the next vertex to explore. * * INPUTS: * currentVertex - The current vertex in the maze. * * OUTPUTS: * outputRoute - This will be populated with a fastest route from the current vertex to the next * vertex to explore. * * RETURNS: * A boolean value. * If true then there remain vertices to explore and outputRoute is outputted as above. * If false then there are no more vertices to explore and outputRoute is set to empty. * */ bool CMazeMapper::ComputeNextVertex(const int& currentVertex, std::vector<int>& outputRoute) { DEBUG_METHOD(); // Generate graph from the CMap // TODO: Fix this when you now how you will generate the graph / receive the map vector< vector<double> > distanceMatrix; vector<int> vertexLabels; CGraph currentGraph { distanceMatrix, vertexLabels }; // Check there remain vertices to explore if (m_vertsToExplore.size() > 0) return false; // Find closest of the vertices left to explore int nextVertex { m_vertsToExplore[0] }; double currentFastestDist = currentGraph.ShortestDistance(currentVertex, m_vertsToExplore[0], true, outputRoute); for (unsigned int i = 1; i < m_vertsToExplore.size(); ++i) { vector<int> newOutputRoute; double newDist = currentGraph.ShortestDistance(currentVertex, m_vertsToExplore[i], true, newOutputRoute); if (newDist < currentFastestDist) { currentFastestDist = newDist; outputRoute = newOutputRoute; nextVertex = m_vertsToExplore[i]; } else if (newDist == currentFastestDist && VertexScore(m_vertsToExplore[i]) < VertexScore(nextVertex)) { // If there is a tie in distances, choose the one which is closest to the bottom left of the maze // If this is also a tie then do not update nextVertex. This is equivalent to choosing the vertex // which is closer to the top left. outputRoute = newOutputRoute; nextVertex = m_vertsToExplore[i]; } } return true; }
CGraph* CreateRandomGraphWithToyQMRSpecific(int num_nodes, int num_indep_nodes, int max_size_family) { PNL_CHECK_LEFT_BORDER( num_nodes, 10 ); PNL_CHECK_RANGES( num_indep_nodes, 1, num_nodes-1 ); PNL_CHECK_RANGES( max_size_family, 2, num_nodes ); int i, j, k; CGraph *pGraph = CGraph::Create(0, NULL, NULL, NULL); PNL_CHECK_IF_MEMORY_ALLOCATED( pGraph ); srand((unsigned int)time(NULL)); pGraph->AddNodes(num_nodes); int num_parents; int ind_parent; intVector prev_nodes(0); for ( i = num_indep_nodes; i < num_nodes; i++) { prev_nodes.resize(0); for ( j = 0; j < num_indep_nodes; j++) prev_nodes.push_back(j); num_parents = rand() % (max_size_family - 1); num_parents += 1; num_parents = (num_parents > i) ? i : num_parents; for ( j = 0; j < num_parents; j++) { ind_parent = rand() % prev_nodes.size(); pGraph->AddEdge(prev_nodes[ind_parent], i, 1); prev_nodes.erase(prev_nodes.begin() + ind_parent); } } return pGraph; }
void cbInfo (CMessage &msgin, TSockId from, CCallbackNetBase &netbase) { string line; msgin.serial (line); InfoLog->displayRawNL ("%s", line.c_str()); #ifdef USE_3D string token = "MeanPongTime "; uint pos=line.find (token); uint pos2=line.find (" ", pos+token.size()); uint32 val = atoi(line.substr (pos+token.size(), pos2-pos-token.size()).c_str()); LagGraph.addOneValue ((float)val); #endif }
CGraph* CreateGraphWithRegularGridSpecific(int& num_nodes, int width, int height, int num_layers) { PNL_CHECK_LEFT_BORDER( width, 2 ); PNL_CHECK_LEFT_BORDER( height, 2 ); PNL_CHECK_LEFT_BORDER( num_layers, 1 ); int i, j, k; CGraph *pGraph = CGraph::Create(0, NULL, NULL, NULL); PNL_CHECK_IF_MEMORY_ALLOCATED( pGraph ); srand((unsigned int)time(NULL)); int num_nodes_one_layer = width * height; num_nodes = num_nodes_one_layer * num_layers; pGraph->AddNodes(num_nodes); for (i = 0; i < num_layers; i++) { for (j = 1; j < width; j++) pGraph->AddEdge( i * num_nodes_one_layer + j - 1, i * num_nodes_one_layer + j, 1); for (k = 1; k < height; k++) pGraph->AddEdge( i * num_nodes_one_layer + (k - 1) * width, i * num_nodes_one_layer + k * width, 1); for (j = 1; j < width; j++) for (k = 1; k < height; k++) { pGraph->AddEdge( i * num_nodes_one_layer + (k - 1) * width + j, i * num_nodes_one_layer + k * width + j, 1); pGraph->AddEdge( i * num_nodes_one_layer + k * width + j - 1, i * num_nodes_one_layer + k * width + j, 1); } if (i) { for (j = 0; j < width; j++) for (k = 0; k < height; k++) pGraph->AddEdge( (i - 1) * num_nodes_one_layer + k * width + j, i * num_nodes_one_layer + k * width + j, 1); } } return pGraph; }
void GameLogic::ResetGraph(CGraph& graph) { //随机交换顶点数组中两个顶点的值 srand((int)time(NULL)); for (int i = 0; i < MAX_VERTEX_NUM; i++) { int nIndex1 = rand() % MAX_VERTEX_NUM; int nIndex2 = rand() % MAX_VERTEX_NUM; graph.changeInfo(nIndex1, nIndex2); } for (int i = 0; i < MAX_ROW; i++) { for (int j = 0; j < MAX_COL; j++) { UpdateArc(graph, i, j); } } }
void GameLogic::UpdateArc(CGraph &graph, int nRow, int nCol) { int nV1Index = nRow * MAX_PIC_NUM + nCol; if (nCol > 0) { int nV2Index = nV1Index - 1; int nInfo1 = graph.GetVertex(nV1Index); int nInfo2 = graph.GetVertex(nV2Index); //TODO:判断与左边相邻的是否有关系 if (nInfo1 == nInfo2 || nInfo1 == BLANK || nInfo2 == BLANK) { graph.AddArc(nV1Index, nV2Index); } } if (nCol < MAX_COL - 1) { int nV2Index = nV1Index + 1; //TODO:判断与右边相邻的是否有关系 int nInfo1 = graph.GetVertex(nV1Index); int nInfo2 = graph.GetVertex(nV2Index); if (nInfo1 == nInfo2 || nInfo1 == BLANK || nInfo2 == BLANK) { graph.AddArc(nV1Index, nV2Index); } } if (nRow > 0) { int nV2Index = nV1Index - MAX_PIC_NUM; //TODO:判断与正上方是否有关系 int nInfo1 = graph.GetVertex(nV1Index); int nInfo2 = graph.GetVertex(nV2Index); if (nInfo1 == nInfo2 || nInfo1 == BLANK || nInfo2 == BLANK) { graph.AddArc(nV1Index, nV2Index); } } if (nRow < MAX_ROW - 1) { int nV2Index = nV1Index + MAX_PIC_NUM; //TODO:判断与正下方是否有关系 int nInfo1 = graph.GetVertex(nV1Index); int nInfo2 = graph.GetVertex(nV2Index); if (nInfo1 == nInfo2 || nInfo1 == BLANK || nInfo2 == BLANK) { graph.AddArc(nV1Index, nV2Index); } } }
void UPGMpp::getMostProbableNodeAssignation( CGraph &graph, map<size_t,size_t> &assignation, TInferenceOptions &options) { vector<CNodePtr> &nodes = graph.getNodes(); size_t N_nodes = nodes.size(); // Choose as initial class for all the nodes their more probable class // according to the node potentials for ( size_t index = 0; index < N_nodes; index++ ) { size_t nodeMAP; size_t ID = nodes[index]->getID(); nodes[index]->getPotentials( options.considerNodeFixedValues ).maxCoeff(&nodeMAP); assignation[ID] = nodeMAP; } }
void UPGMpp::applyMaskToPotentials(CGraph &graph, map<size_t,vector<size_t> > &mask ) { vector<CNodePtr> &nodes = graph.getNodes(); for ( size_t node_index = 0; node_index < nodes.size(); node_index++ ) { CNodePtr nodePtr = nodes[node_index]; size_t nodeID = nodePtr->getID(); if ( mask.count(nodeID) ) { Eigen::VectorXd nodePot = nodePtr->getPotentials(); Eigen::VectorXd potMask( nodePot.rows() ); potMask.fill(0); for ( size_t mask_index = 0; mask_index < mask[nodeID].size(); mask_index++ ) potMask(mask[nodeID][mask_index]) = 1; nodePot = nodePot.cwiseProduct(potMask); nodePtr->setPotentials( nodePot ); } } }
void CWorld :: Precache( void ) { g_pLastSpawn = NULL; CVAR_SET_STRING("sv_gravity", "800"); // 67ft/sec CVAR_SET_STRING("sv_stepsize", "18"); CVAR_SET_STRING("room_type", "0"); // clear DSP // Create all the arenas for (int i = 0; i < MAX_ARENAS; i++) { g_pArenaList[i] = GetClassPtr( ( CDiscArena *)NULL ); g_pArenaList[i]->Spawn(); } // Set up game rules if (g_pGameRules) { delete g_pGameRules; } g_pGameRules = InstallGameRules( ); //!!!UNDONE why is there so much Spawn code in the Precache function? I'll just keep it here ///!!!LATER - do we want a sound ent in deathmatch? (sjb) //pSoundEnt = CBaseEntity::Create( "soundent", g_vecZero, g_vecZero, edict() ); pSoundEnt = GetClassPtr( ( CSoundEnt *)NULL ); pSoundEnt->Spawn(); if ( !pSoundEnt ) { ALERT ( at_console, "**COULD NOT CREATE SOUNDENT**\n" ); } InitBodyQue(); // init sentence group playback stuff from sentences.txt. // ok to call this multiple times, calls after first are ignored. SENTENCEG_Init(); // init texture type array from materials.txt TEXTURETYPE_Init(); // the area based ambient sounds MUST be the first precache_sounds // player precaches W_Precache (); // get weapon precaches ClientPrecache(); // sounds used from C physics code PRECACHE_SOUND("common/null.wav"); // clears sound channels PRECACHE_SOUND( "items/suitchargeok1.wav" );//!!! temporary sound for respawning weapons. PRECACHE_SOUND( "items/gunpickup2.wav" );// player picks up a gun. PRECACHE_SOUND( "common/bodydrop3.wav" );// dead bodies hitting the ground (animation events) PRECACHE_SOUND( "common/bodydrop4.wav" ); PRECACHE_SOUND( "r_tele1.wav" ); // respawn sound PRECACHE_SOUND( "scream1.wav" ); // falling scream sound PRECACHE_SOUND( "scream2.wav" ); // falling scream sound PRECACHE_SOUND( "scream3.wav" ); // falling scream sound PRECACHE_SOUND( "decap.wav" ); // decapitation sound PRECACHE_SOUND( "shatter.wav" ); // freeze decapitation sound PRECACHE_MODEL( "models/head.mdl" ); // head g_Language = (int)CVAR_GET_FLOAT( "sv_language" ); if ( g_Language == LANGUAGE_GERMAN ) { PRECACHE_MODEL( "models/germangibs.mdl" ); } else { PRECACHE_MODEL( "models/hgibs.mdl" ); PRECACHE_MODEL( "models/agibs.mdl" ); } PRECACHE_SOUND ("weapons/ric1.wav"); PRECACHE_SOUND ("weapons/ric2.wav"); PRECACHE_SOUND ("weapons/ric3.wav"); PRECACHE_SOUND ("weapons/ric4.wav"); PRECACHE_SOUND ("weapons/ric5.wav"); // // Setup light animation tables. 'a' is total darkness, 'z' is maxbright. // // 0 normal LIGHT_STYLE(0, "m"); // 1 FLICKER (first variety) LIGHT_STYLE(1, "mmnmmommommnonmmonqnmmo"); // 2 SLOW STRONG PULSE LIGHT_STYLE(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba"); // 3 CANDLE (first variety) LIGHT_STYLE(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg"); // 4 FAST STROBE LIGHT_STYLE(4, "mamamamamama"); // 5 GENTLE PULSE 1 LIGHT_STYLE(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj"); // 6 FLICKER (second variety) LIGHT_STYLE(6, "nmonqnmomnmomomno"); // 7 CANDLE (second variety) LIGHT_STYLE(7, "mmmaaaabcdefgmmmmaaaammmaamm"); // 8 CANDLE (third variety) LIGHT_STYLE(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa"); // 9 SLOW STROBE (fourth variety) LIGHT_STYLE(9, "aaaaaaaazzzzzzzz"); // 10 FLUORESCENT FLICKER LIGHT_STYLE(10, "mmamammmmammamamaaamammma"); // 11 SLOW PULSE NOT FADE TO BLACK LIGHT_STYLE(11, "abcdefghijklmnopqrrqponmlkjihgfedcba"); // 12 UNDERWATER LIGHT MUTATION // this light only distorts the lightmap - no contribution // is made to the brightness of affected surfaces LIGHT_STYLE(12, "mmnnmmnnnmmnn"); // styles 32-62 are assigned by the light program for switchable lights // 63 testing LIGHT_STYLE(63, "a"); for ( i = 0; i < ARRAYSIZE(gDecals); i++ ) gDecals[i].index = DECAL_INDEX( gDecals[i].name ); // init the WorldGraph. WorldGraph.InitGraph(); // make sure the .NOD file is newer than the .BSP file. if ( !WorldGraph.CheckNODFile ( ( char * )STRING( gpGlobals->mapname ) ) ) {// NOD file is not present, or is older than the BSP file. WorldGraph.AllocNodes (); } else {// Load the node graph for this level if ( !WorldGraph.FLoadGraph ( (char *)STRING( gpGlobals->mapname ) ) ) {// couldn't load, so alloc and prepare to build a graph. ALERT ( at_console, "*Error opening .NOD file\n" ); WorldGraph.AllocNodes (); } else { ALERT ( at_console, "\n*Graph Loaded!\n" ); } } if ( pev->speed > 0 ) CVAR_SET_FLOAT( "sv_zmax", pev->speed ); else CVAR_SET_FLOAT( "sv_zmax", 4096 ); if ( pev->netname ) { ALERT( at_aiconsole, "Chapter title: %s\n", STRING(pev->netname) ); CBaseEntity *pEntity = CBaseEntity::Create( "env_message", g_vecZero, g_vecZero, NULL ); if ( pEntity ) { pEntity->SetThink( SUB_CallUseToggle ); pEntity->pev->message = pev->netname; pev->netname = 0; pEntity->pev->nextthink = gpGlobals->time + 0.3; pEntity->pev->spawnflags = SF_MESSAGE_ONCE; } } if ( pev->spawnflags & SF_WORLD_DARK ) CVAR_SET_FLOAT( "v_dark", 1.0 ); else CVAR_SET_FLOAT( "v_dark", 0.0 ); if ( pev->spawnflags & SF_WORLD_TITLE ) gDisplayTitle = TRUE; // display the game title if this key is set else gDisplayTitle = FALSE; if ( pev->spawnflags & SF_WORLD_FORCETEAM ) { CVAR_SET_FLOAT( "mp_defaultteam", 1 ); } else { CVAR_SET_FLOAT( "mp_defaultteam", 0 ); } // Discwar if ( g_iPlayersPerTeam < 1 ) g_iPlayersPerTeam = CVAR_GET_FLOAT("rc_playersperteam"); }
void displayStreamingDebug () { // Yoyo: display with getPerformanceTime() for better precision. static TTicks oldTick = CTime::getPerformanceTime(); TTicks newTick = CTime::getPerformanceTime(); double deltaTime = CTime::ticksToSecond (newTick-oldTick); oldTick = newTick; static NLMISC::CValueSmoother smooth; smooth.addValue((float)deltaTime); deltaTime = deltaTime * 5.0f / 6.0f; float deltaTimeSmooth = smooth.getSmoothValue () * 5.0f / 6.0f; if (!FreezeGraph) { // Vram delta static uint32 lastVRAMUsed = Driver->profileAllocatedTextureMemory(); uint32 VRAMUsed = Driver->profileAllocatedTextureMemory(); sint value = (sint)VRAMUsed-(sint)lastVRAMUsed; if (value>=0) { VRAMUpGraph.addOneValue ((float)value/(1024.f*1024.f)); VRAMDownGraph.addOneValue (0); } else { VRAMDownGraph.addOneValue ((float)(-value)/(1024.f*1024.f)); VRAMUpGraph.addOneValue (0); } lastVRAMUsed = VRAMUsed; // File opened delta static uint32 lastFileOpened = CIFile::getNumFileOpen(); uint32 fileOpened = CIFile::getNumFileOpen(); OpenedFileGraph.addOneValue((float)(fileOpened-lastFileOpened)); lastFileOpened=fileOpened; // Byte read delta static uint32 lastByteRead = CIFile::getReadFromFile(); uint32 byteRead = CIFile::getReadFromFile(); ByteReadGraph.addOneValue((float)CIFile::getReadingFromFile()/1024.f); ByteReadGraphInstant.addOneValue((float)(byteRead-lastByteRead)/1024.f); lastByteRead=byteRead; // Byte read delta static uint32 lastFileRead = CIFile::getNumFileRead(); uint32 fileRead = CIFile::getNumFileRead(); FileReadGraph.addOneValue((float)(fileRead-lastFileRead)); lastFileRead=fileRead; // MS per frame SpfGraph.addOneValue (1000.f*(float)deltaTime); // lua memory LuaMemGraph.addOneValue(CInterfaceManager::getInstance()->getLuaState()->getGCCount() / 1024.f); // Count of waitinf instance CurrentTaskGraph.addOneValue (CAsyncFileManager::getInstance().isTaskRunning()?1.f:0.f); } // Add graph value if(ShowInfos == 3) { float lineStep = ClientCfg.DebugLineStep; float line; // Initialize Pen // //----------------// // Create a shadow when displaying a text. TextContext->setShaded(true); // Set the font size. TextContext->setFontSize(ClientCfg.DebugFontSize); // Set the text color TextContext->setColor(ClientCfg.DebugFontColor); // TOP LEFT // //----------// TextContext->setHotSpot(UTextContext::TopLeft); // FPS and Ms per frame line = 0.99f; TextContext->printfAt(0.01f, line, "STREAMING INFORMATION"); if(deltaTimeSmooth != 0.f) TextContext->printfAt(0.8f, line,"%.1f fps", 1.f/deltaTimeSmooth); else TextContext->printfAt(0.8f, line,"%.1f fps", 0.f); TextContext->printfAt(0.9f, line, "%d ms", (uint)(deltaTimeSmooth*1000)); // Dump the task array line = 0.90f; TextContext->printfAt(0.3f, line,"Task manager:"); line -= lineStep; static vector<string> names; CAsyncFileManager::getInstance().dump(names); uint i; for (i=0; i<names.size (); i++) { TextContext->printfAt(0.3f, line, " %s", names[i].c_str()); line -= lineStep; } // Dump the opened file array line = 0.90f; TextContext->printfAt(0.65f, line,"Files opened:"); line -= lineStep; CIFile::dump(names); for (i=0; i<names.size (); i++) { TextContext->printfAt(0.65f, line, " %s", names[i].c_str()); line -= lineStep; } // No more shadow when displaying a text. TextContext->setShaded(false); } }
CIDNet* CreateRandomIDNet(int num_nodes, int num_indep_nodes, int max_size_family, int num_decision_nodes, int max_num_states_chance_nodes, int max_num_states_decision_nodes, int min_utility, int max_utility, bool is_uniform_start_policy) { PNL_CHECK_RANGES(num_decision_nodes, 1, num_nodes-1); PNL_CHECK_LEFT_BORDER(max_num_states_chance_nodes, 1); PNL_CHECK_LEFT_BORDER(max_num_states_decision_nodes, 1); PNL_CHECK_LEFT_BORDER(max_utility, min_utility); CGraph* pGraph = CreateRandomAndSpecificForIDNetGraph(num_nodes, num_indep_nodes, max_size_family); if (!pGraph->IsDAG()) { PNL_THROW(CInconsistentType, " the graph should be a DAG "); } if (!pGraph->IsTopologicallySorted()) { PNL_THROW(CInconsistentType, " the graph should be sorted topologically "); } if (pGraph->NumberOfConnectivityComponents() > 1) { PNL_THROW(CInconsistentType, " the graph should be linked "); } int i, j, k; CNodeType *nodeTypes = new CNodeType [num_nodes]; intVector nonValueNodes(0); intVector posibleDecisionNodes(0); nonValueNodes.resize(0); posibleDecisionNodes.resize(0); for (i = 0; i < num_nodes; i++) { if (pGraph->GetNumberOfChildren(i) == 0) { nodeTypes[i].SetType(1, 1, nsValue); } else { nonValueNodes.push_back(i); posibleDecisionNodes.push_back(i); } } int ind_decision_node; int num_states; int index; int node; intVector neighbors(0); neighborTypeVector neigh_types(0); num_decision_nodes = (num_decision_nodes > posibleDecisionNodes.size()) ? posibleDecisionNodes.size() : num_decision_nodes; for (i = 0; (i < num_decision_nodes) && (posibleDecisionNodes.size()>0); i++) { ind_decision_node = rand() % posibleDecisionNodes.size(); node = posibleDecisionNodes[ind_decision_node]; num_states = GetRandomNumberOfStates(max_num_states_decision_nodes); nodeTypes[node].SetType(1, num_states, nsDecision); index = -1; for (j = 0; j < nonValueNodes.size(); j++) { if (nonValueNodes[j] == node) { index = j; break; } } if (index != -1) nonValueNodes.erase(nonValueNodes.begin() + index); posibleDecisionNodes.erase(posibleDecisionNodes.begin() + ind_decision_node); pGraph->GetNeighbors(node, &neighbors, &neigh_types); for (j = 0; j < neighbors.size(); j++) { index = -1; for (k = 0; k < posibleDecisionNodes.size(); k++) { if (neighbors[j] == posibleDecisionNodes[k]) { index = k; break; } } if (index != -1) posibleDecisionNodes.erase(posibleDecisionNodes.begin() + index); } } for (i = 0; i < nonValueNodes.size(); i++) { num_states = GetRandomNumberOfStates(max_num_states_chance_nodes); nodeTypes[nonValueNodes[i]].SetType(1, num_states, nsChance); } int *nodeAssociation = new int[num_nodes]; for (i = 0; i < num_nodes; i++) { nodeAssociation[i] = i; } CIDNet *pIDNet = CIDNet::Create(num_nodes, num_nodes, nodeTypes, nodeAssociation, pGraph); pGraph = pIDNet->GetGraph(); CModelDomain* pMD = pIDNet->GetModelDomain(); CFactor **myParams = new CFactor*[num_nodes]; int *nodeNumbers = new int[num_nodes]; int **domains = new int*[num_nodes]; intVector parents(0); for (i = 0; i < num_nodes; i++) { nodeNumbers[i] = pGraph->GetNumberOfParents(i) + 1; domains[i] = new int[nodeNumbers[i]]; pGraph->GetParents(i, &parents); for (j = 0; j < parents.size(); j++) { domains[i][j] = parents[j]; } domains[i][nodeNumbers[i]-1] = i; } pIDNet->AllocFactors(); for (i = 0; i < num_nodes; i++) { myParams[i] = CTabularCPD::Create(domains[i], nodeNumbers[i], pMD); } float **data = new float*[num_nodes]; int size_data; int num_states_node; int num_blocks; intVector size_nodes(0); float belief, sum_beliefs; for (i = 0; i < num_nodes; i++) { size_data = 1; size_nodes.resize(0); for (j = 0; j < nodeNumbers[i]; j++) { size_nodes.push_back(pIDNet->GetNodeType(domains[i][j])->GetNodeSize()); size_data *= size_nodes[j]; } num_states_node = size_nodes[size_nodes.size() - 1]; num_blocks = size_data / num_states_node; data[i] = new float[size_data]; switch (pIDNet->GetNodeType(i)->GetNodeState()) { case nsChance: { for (j = 0; j < num_blocks; j++) { sum_beliefs = 0.0; for (k = 0; k < num_states_node - 1; k++) { belief = GetBelief(1.0f - sum_beliefs); data[i][j * num_states_node + k] = belief; sum_beliefs += belief; } belief = 1.0f - sum_beliefs; data[i][j * num_states_node + num_states_node - 1] = belief; } break; } case nsDecision: { if (is_uniform_start_policy) { belief = 1.0f / float(num_states_node); for (j = 0; j < num_blocks; j++) { sum_beliefs = 0.0; for (k = 0; k < num_states_node - 1; k++) { data[i][j * num_states_node + k] = belief; sum_beliefs += belief; } data[i][j * num_states_node + num_states_node - 1] = 1.0f - sum_beliefs; } } else { for (j = 0; j < num_blocks; j++) { sum_beliefs = 0.0; for (k = 0; k < num_states_node - 1; k++) { belief = GetBelief(1.0f - sum_beliefs); data[i][j * num_states_node + k] = belief; sum_beliefs += belief; } belief = 1.0f - sum_beliefs; data[i][j * num_states_node + num_states_node - 1] = belief; } } break; } case nsValue: { for (j = 0; j < num_blocks; j++) { data[i][j] = float(GetUtility(min_utility, max_utility)); } break; } } } for (i = 0; i < num_nodes; i++) { myParams[i]->AllocMatrix(data[i], matTable); pIDNet->AttachFactor(myParams[i]); } delete [] nodeTypes; delete [] nodeAssociation; return pIDNet; }
CGraph* CreateRandomAndSpecificForIDNetGraph(int num_nodes, int num_indep_nodes, int max_size_family) { PNL_CHECK_LEFT_BORDER(num_nodes, 10); PNL_CHECK_RANGES(num_indep_nodes, 1, num_nodes-1); PNL_CHECK_RANGES(max_size_family, 2, num_nodes); int i, j, k; CGraph *pGraph = CGraph::Create(0, NULL, NULL, NULL); PNL_CHECK_IF_MEMORY_ALLOCATED(pGraph); srand((unsigned int)time(NULL)); pGraph->AddNodes(num_nodes); int num_parents; int ind_parent; intVector prev_nodes(0); for (i = num_indep_nodes; i < num_nodes; i++) { prev_nodes.resize(0); for (j = 0; j < i; j++) prev_nodes.push_back(j); num_parents = rand() % (max_size_family - 1); num_parents += 1; num_parents = (num_parents > i) ? i : num_parents; for (j = 0; j < num_parents; j++) { ind_parent = rand() % prev_nodes.size(); pGraph->AddEdge(prev_nodes[ind_parent], i, 1); prev_nodes.erase(prev_nodes.begin() + ind_parent); } } intVector parents(0); intVector childs(0); for (i = 0; i < num_nodes; i++) { if (pGraph->GetNumberOfChildren(i) == 0) { pGraph->GetParents(i, &parents); for (j = 0; j < parents.size(); j++) { pGraph->GetChildren(parents[j], &childs); for (k = 0; k < childs.size(); k++) if ((childs[k] != i) && (pGraph->GetNumberOfChildren(childs[k]) == 0) && (pGraph->GetNumberOfParents(childs[k]) == 1)) { if (i < childs[k]) { pGraph->RemoveEdge(parents[j], childs[k]); pGraph->AddEdge(i, childs[k], 1); } else { pGraph->AddEdge(childs[k], i, 1); } } } } } return pGraph; }
CIDNet* CreateLIMIDWith2DecInClick() { const int nnodes = 7; const int numberOfNodeTypes = 7; int i; CGraph *pGraph = CGraph::Create(0, NULL, NULL, NULL); pGraph->AddNodes(nnodes); pGraph->AddEdge(0,1,1); pGraph->AddEdge(2,3,1); pGraph->AddEdge(1,4,1); pGraph->AddEdge(3,4,1); pGraph->AddEdge(1,5,1); pGraph->AddEdge(4,6,1); CNodeType *nodeTypes = new CNodeType [numberOfNodeTypes]; nodeTypes[0].SetType(1, 2, nsChance); nodeTypes[1].SetType(1, 2, nsDecision); nodeTypes[2].SetType(1, 2, nsChance); nodeTypes[3].SetType(1, 2, nsDecision); nodeTypes[4].SetType(1, 2, nsChance); nodeTypes[5].SetType(1, 1, nsValue); nodeTypes[6].SetType(1, 1, nsValue); int *nodeAssociation = new int[nnodes]; for (i = 0; i < nnodes; i++) { nodeAssociation[i] = i; } CIDNet *pIDNet = CIDNet::Create(nnodes, numberOfNodeTypes, nodeTypes, nodeAssociation, pGraph); CModelDomain* pMD = pIDNet->GetModelDomain(); CFactor **myParams = new CFactor*[nnodes]; int *nodeNumbers = new int [nnodes]; int domain0[] = { 0 }; nodeNumbers[0] = 1; int domain1[] = { 0, 1 }; nodeNumbers[1] = 2; int domain2[] = { 2 }; nodeNumbers[2] = 1; int domain3[] = { 2, 3 }; nodeNumbers[3] = 2; int domain4[] = { 1, 3, 4 }; nodeNumbers[4] = 3; int domain5[] = { 1, 5 }; nodeNumbers[5] = 2; int domain6[] = { 4, 6 }; nodeNumbers[6] = 2; int *domains[] = { domain0, domain1, domain2, domain3, domain4, domain5, domain6 }; pIDNet->AllocFactors(); for (i = 0; i < nnodes; i++) { myParams[i] = CTabularCPD::Create(domains[i], nodeNumbers[i], pMD); } float data0[] = {0.200000f, 0.800000f}; float data1[] = {0.500000f, 0.500000f, 0.500000f, 0.500000f}; float data2[] = {0.600000f, 0.400000f}; float data3[] = {0.500000f, 0.500000f, 0.500000f, 0.500000f}; float data4[] = {0.500000f, 0.500000f, 0.100000f, 0.900000f, 0.800000f, 0.200000f, 0.020000f, 0.980000f}; float data5[] = {10000.000000f, -2000.000000f}; float data6[] = {-5000.000000f, 10000.000000f}; float *data[] = { data0, data1, data2, data3, data4, data5, data6 }; for (i = 0; i < nnodes; i++) { myParams[i]->AllocMatrix(data[i], matTable); pIDNet->AttachFactor(myParams[i]); } delete [] nodeTypes; delete [] nodeAssociation; return pIDNet; }