int dijkstra( s_env& st_env, float af_maxAllowedCost, bool ab_surfaceCostVoid) { int i, j; int vno_c = -1; int vno_n = -1; int vno_i, vno_f; VERTEX *v_c, *v_n; float cost, f_pathCost; struct d_node *dn, *dn_next; int rv; // s_iterInfo st_iterInfo; MRIS* surf = st_env.pMS_active; // bool b_relNextReference = true; // If we aren't going to preserve cost history in the environment, then we // will by default always be able to write path costs bool b_canWriteCostVal = !st_env.b_costHistoryPreserve; static int calls = 0; int marked = 0; int totalLoops = -1; /* --- sanity checks --- */ vno_i = st_env.startVertex; vno_f = st_env.endVertex; assert(vno_i >= 0); assert(vno_i < surf->nvertices); assert(vno_f >= 0); assert(vno_f < surf->nvertices); if (!st_env.b_costHistoryPreserve) { assert(!surf->vertices[vno_i].ripflag); assert(!surf->vertices[vno_f].ripflag); } /* --- initialize --- */ for (i = 0; i < surf->nvertices; i++) { bool b_overwrite = true; if (mark(surf, i, DIJK_VIRGIN, b_overwrite) != NO_ERROR) goto error; // Set all vertex values to -1 - only the very first time // that this function is called, or if explicitly // specified in the calling parameters. if (!calls || ab_surfaceCostVoid) surf->vertices[i].val = -1; } calls++; surf->vertices[vno_i].val = 0.0; surf->vertices[vno_i].old_undefval = vno_f; if (mark(surf, vno_i, DIJK_IN_PLAY) != NO_ERROR) goto error; // If the start and end vertices are coincident in the problem environment, // we should loop through at least once, and ignore the vno_c!=vno_f // condition, otherwise the while() will terminate after one loop. while ( vno_c!=vno_f || !totalLoops) { totalLoops++; if(totalLoops >= st_env.pMS_curvature->nvertices-1) { // If this condition is true, we have processed all available vertices // in the mesh -- typically only occurs if the startVertex == endVertex // and is used for 'autodijk' type calculations. rv = TRUE; goto clean; } /* set vno_c (find min) */ if (d_list == NULL) { ErrorPrintf(ERROR_BADPARM, "dijkstra(): out of vertices"); colprintf(st_env.lw, st_env.rw, "start:stop", "[ %d:%d ]\n", st_env.startVertex, st_env.endVertex); goto error; } vno_c = d_list->vno; v_c = &surf->vertices[vno_c]; /* mark it */ if (mark(surf, vno_c, DIJK_DONE) != NO_ERROR) goto error; /* update neighbors */ //cout << "neighbors = " << (int) v_c->num << endl; for (j = 0; j < (int) v_c->vnum; j++) { //cout << "neighbor = " << j << endl; vno_n = v_c->v[j]; v_n = &surf->vertices[vno_n]; //if(v_n->ripflag) continue; if (v_n->marked == DIJK_DONE) continue; // for "circular" path searches // cost = st_env.costFunc_do(st_env, &st_iterInfo, vno_c, j, // b_relNextReference); cost = s_env_edgeCostFind(st_env, vno_c, vno_n); f_pathCost = v_c->val + cost; // Break out of while if af_maxAllowedCost is violated. if (af_maxAllowedCost && (f_pathCost > af_maxAllowedCost)) continue; if ( (v_n->marked == DIJK_VIRGIN) || (f_pathCost < v_n->val) ) { // The check in the <if> statement preserves pathCost values in the MRIS // from previous calls to this function. This history is important // in determing ply distances from a given target path. A pathCost // is only written to a new vertex iff that vertex has never been // visited, or if the cost is less than an older value. if (st_env.b_costHistoryPreserve) { b_canWriteCostVal = (f_pathCost<v_n->val||v_n->val==-1); } if (b_canWriteCostVal) { marked++; v_n->val = f_pathCost; v_n->old_undefval = vno_c; //cout << vno_c << "<---" << vno_n << endl; } } // cout << "v->marked in dijkstra " << v_n->marked << endl; if (v_n->marked == DIJK_VIRGIN) if (mark(surf, vno_n, DIJK_IN_PLAY) != NO_ERROR) goto error; } } rv = TRUE; goto clean; error: rv = FALSE; clean: for (dn = d_list;dn != NULL;dn = dn_next) { dn_next = dn->next; free(dn); } d_list = NULL; return(rv); } /* end dijkstra() */
int main() { ProgramData prog; bool done = false, errorInLoop = false; int checkVal = 0; srand(time(NULL)); # ifdef ASSISTED_CONNECT checkVal = prog.AssistedConnect(); if (checkVal != 0) { printf("Error %d occurred while attempting assisted connection! Program stop.\n", checkVal); return checkVal; } # else // ASSISTED_CONNECT if (prog.ConnectToIRC("chat.freenode.net", 6667) != 0) { printf("Problem connecting to server! Program stop.\n"); return -1; } /// TODO: CHANGE THIS IF YOU WANT TO TEST IT OUT. /// prog.AddToSendQueue("NICK ParlourBot"); prog.AddToSendQueue("USER parlourbot \"example.com\" \"chat.freenode.net\" :The IRC Parlour Bot"); # endif // ASSISTED_CONNECT prog.QueryDLLs(); while (!done && !errorInLoop) { QueueData recvData; prog.ProcessChrono(); prog.GetSendQueues(); if (prog.RecvDataQueue() < 0) { printf("Error receiving data!"); errorInLoop = true; } else if (!errorInLoop && prog.SendDataQueue() < 0) { printf("Error sending data!"); errorInLoop = true; } while (prog.GetFrontRecvQueue(recvData)) { if (recvData.getType() == MSG_PING) prog.Pong(recvData); else { int ircProc = 0; if ((recvData.getNick() == prog.GetMyNick() || (recvData.hasRecipient() && recvData.getRecipient() == prog.GetMyNick())) && recvData.IsThisMe()) { switch (recvData.getType()) { case MSG_JOIN: prog.CreateChannel(recvData); break; case MSG_PART: case MSG_KICK: if (recvData.getType() == MSG_KICK && recvData.getRecipient() != prog.GetMyNick()) break;//"ParlourBot") break; prog.DestroyChannel(recvData); break; case MSG_INVITE: ircProc = prog.ProcessCommand(recvData); break; } } else ircProc = prog.ProcessCommand(recvData); if (ircProc != IRCPROC_SKIPDISPLAY) colprintf("%s", recvData.ToString()); } if (recvData.getType() == MSG_ERROR) { done = true; break; } else if (recvData.getType() == MSG_CTCPREQ) prog.CTCP(recvData); } Sleep(1); } return 0; }