void ProcessesLocal::Private::readProcStat(struct kinfo_proc *p, Process *ps) { ps->setUserTime(LP(p, uticks) / 10000); ps->setSysTime((LP(p, sticks) + LP(p, iticks)) / 10000); ps->setNiceLevel(PP(p, nice)); ps->setVmSize(VP(p, map_size) / 1024); /* convert to KiB */ ps->setVmRSS(VP(p, prssize) * getpagesize() / 1024); /* convert to KiB */ // "idle","run","sleep","stop","zombie" switch( LP(p, stat) ) { case LSRUN: ps->setStatus(Process::Running); break; case LSSLEEP: ps->setStatus(Process::Sleeping); break; case LSSTOP: ps->setStatus(Process::Stopped); break; default: ps->setStatus(Process::OtherStatus); break; } if (PP(p, stat) == SZOMB) ps->setStatus(Process::Zombie); }
int main() { Graph g("graph_t3.txt"); ifstream reqfile("req.txt"); int reqN=4; int a,b,c; vector<Req*> reqL; reqL.clear(); for(int i=0;i<reqN;i++) { reqfile>>a>>b>>c; Req* r=new Req(a,b,c); reqL.push_back(r); } //线性规划部署 cout<<"--------------------------------------------------"<<endl; double result=0; result=LP(&g,reqL); cout<<"TE of this case is: "<<result<<endl; cout<<"End of the Program"<<endl; getchar(); return 0; }
// One jacobi iteration void jacobi_iteration() { for (int i = 0; i < local_height; i++) { for (int j = 0; j < local_width; j++) { local_pres[LP(i, j)] = calculate_jacobi(i, j); } } }
void LAV ( const DistSparseMatrix<Real>& A, const DistMultiVec<Real>& b, DistMultiVec<Real>& x, const lp::affine::Ctrl<Real>& ctrl ) { EL_DEBUG_CSE const Int m = A.Height(); const Int n = A.Width(); const Grid& grid = A.Grid(); DistSparseMatrix<Real> AHat(grid), G(grid); DistMultiVec<Real> c(grid), h(grid); // c := [0;1;1] // ============ Zeros( c, n+2*m, 1 ); for( Int iLoc=0; iLoc<c.LocalHeight(); ++iLoc ) if( c.GlobalRow(iLoc) >= n ) c.SetLocal( iLoc, 0, Real(1) ); // \hat A := [A, I, -I] // ==================== Zeros( AHat, m, n+2*m ); const Int numLocalEntriesA = A.NumLocalEntries(); AHat.Reserve( numLocalEntriesA + 2*AHat.LocalHeight() ); for( Int e=0; e<numLocalEntriesA; ++e ) AHat.QueueUpdate( A.Row(e), A.Col(e), A.Value(e) ); for( Int iLoc=0; iLoc<AHat.LocalHeight(); ++iLoc ) { const Int i = AHat.GlobalRow(iLoc); AHat.QueueLocalUpdate( iLoc, i+n, Real( 1) ); AHat.QueueLocalUpdate( iLoc, i+n+m, Real(-1) ); } AHat.ProcessLocalQueues(); // G := | 0 -I 0 | // | 0 0 -I | // ================ Zeros( G, 2*m, n+2*m ); G.Reserve( G.LocalHeight() ); for( Int iLoc=0; iLoc<G.LocalHeight(); ++iLoc ) G.QueueLocalUpdate( iLoc, G.GlobalRow(iLoc)+n, Real(-1) ); G.ProcessLocalQueues(); // h := | 0 | // | 0 | // ========== Zeros( h, 2*m, 1 ); // Solve the affine QP // =================== DistMultiVec<Real> xHat(grid), y(grid), z(grid), s(grid); LP( AHat, G, b, c, h, xHat, y, z, s, ctrl ); // Extract x // ========= x = xHat( IR(0,n), ALL ); }
// For debugging purposes void print_local_pres(float *jacobi) { for(int i = -1; i < local_height + 1; i++) { for (int j = -1; j < local_width + 1; j++) { printf("%f ", jacobi[LP(i, j)]); } printf("\n"); } }
void LAV ( const SparseMatrix<Real>& A, const Matrix<Real>& b, Matrix<Real>& x, const lp::affine::Ctrl<Real>& ctrl ) { EL_DEBUG_CSE const Int m = A.Height(); const Int n = A.Width(); const Range<Int> xInd(0,n), uInd(n,n+m), vInd(n+m,n+2*m); SparseMatrix<Real> AHat, G; Matrix<Real> c, h; // c := [0;1;1] // ============ Zeros( c, n+2*m, 1 ); auto cuv = c( IR(n,n+2*m), ALL ); Fill( cuv, Real(1) ); // \hat A := [A, I, -I] // ==================== Zeros( AHat, m, n+2*m ); const Int numEntriesA = A.NumEntries(); AHat.Reserve( numEntriesA + 2*m ); for( Int e=0; e<numEntriesA; ++e ) AHat.QueueUpdate( A.Row(e), A.Col(e), A.Value(e) ); for( Int i=0; i<m; ++i ) { AHat.QueueUpdate( i, i+n, Real( 1) ); AHat.QueueUpdate( i, i+n+m, Real(-1) ); } AHat.ProcessQueues(); // G := | 0 -I 0 | // | 0 0 -I | // ================ Zeros( G, 2*m, n+2*m ); G.Reserve( G.Height() ); for( Int i=0; i<2*m; ++i ) G.QueueUpdate( i, i+n, Real(-1) ); G.ProcessQueues(); // h := | 0 | // | 0 | // ========== Zeros( h, 2*m, 1 ); // Solve the affine linear program // =============================== Matrix<Real> xHat, y, z, s; LP( AHat, G, b, c, h, xHat, y, z, s, ctrl ); // Extract x // ========= x = xHat( xInd, ALL ); }
/*------------------------------main_proc--------------------------------*/ long main_proc (PFUNC_VAR) { static int hExit, hCurPage=ID_NULL, hPage1, hPage2, hPage3, hPage4, hTest = ID_NULL; static YT_COLOR col1, col2, col3, col4; enum local_keys { DRAW_MESS = YKEY_LOCALS }; switch (message) { case YCREATE: YSetDialog (dialog_proc); break; case YOPEN: col1 = YColor("fuchsia"); col2 = YColor("white"); col3 = YColor("blue"); col4 = YColor("red"); case YDRAW: YPaintRectF (0,0, WND->w,WND->h, YColor("yellow")); begin_group ("MESSAGES", 20,375, 440,55, YColor("")); YWnd (&hTest, testmsg_proc, "", 15,15, 385,30, 0,0,0,0, CLR_DEF); end_group (); YGoto (YDRAWITEM, 0,0,col1,(long)page1_proc); YWnd (&hPage1, push_proc, "Page1", 465, 20, 65,40, 0,0,0,0, col1); YWnd (&hPage2, push_proc, "Page2", 465, 70, 65,40, 0,0,0,0, col2); YWnd (&hPage3, push_proc, "Page3", 465,120, 65,40, 0,0,0,0, col3); YWnd (&hPage4, push_proc, "Page4", 465,170, 65,40, 0,0,0,0, col4); YWnd (&hExit, push_proc, "Exit", 465,380, 65,40, 0,0,0,0, YColor("lime")); break; case YDRAWITEM: /* YWndClose (hCurPage); */ /* YUnWnd (hCurPage); */ YWnd (&hCurPage, (YT_PFUNC)mes4, "", 20,20, 440,340, LP(hTest),0,0,0, (YT_COLOR)mes3); break; case YCLOSE: YWndClean (id); break; case MYPUSH_UP: if (mes1 == hExit ) exit(0); else if (mes1 == hPage1) YGoto (YDRAWITEM, 0,0,col1,(long)page1_proc); else if (mes1 == hPage2) YGoto (YDRAWITEM, 0,0,col2,(long)page2_proc); else if (mes1 == hPage3) YGoto (YDRAWITEM, 0,0,col3,(long)page3_proc); else if (mes1 == hPage4) YGoto (YDRAWITEM, 0,0,col4,(long)page4_proc); break; default: return (YSend (hTest, message, mes1,mes2,mes3,mes4)); } RETURN_TRUE; }
bool GP32FilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { assert(_isDirectory); GPDIRENTRY dirEntry; GPFILEATTR attr; GP32FilesystemNode entry; uint32 read; if (mode == FilesystemNode::kListAll) LP("listDir(kListAll)"); else LP("listDir(kListDirectoriesOnly)"); int startIdx = 0; // current file String listDir(_path); //listDir += "/"; while (GpDirEnumList(listDir.c_str(), startIdx++, 1, &dirEntry, &read) == SM_OK) { if (dirEntry.name[0] == '.') continue; entry._displayName = dirEntry.name; entry._path = _path; entry._path += dirEntry.name; GpFileAttr(entry._path.c_str(), &attr); entry._isDirectory = attr.attr & (1 << 4); // Honor the chosen mode if ((mode == FilesystemNode::kListFilesOnly && entry._isDirectory) || (mode == FilesystemNode::kListDirectoriesOnly && !entry._isDirectory)) continue; if (entry._isDirectory) entry._path += "\\"; myList.push_back(new GP32FilesystemNode(entry)); } BP("Dir... %s", listDir.c_str()); return true; }
/*------------------------------dial2_proc--------------------------------*/ long dial2_proc (PFUNC_VAR) { static int hExit, hTest = ID_NULL; static YT_BOOK pages[] = { {"MORE", impr_proc, LP(hTest)}, {"Page_1", page1_proc, LP(hTest)}, {"Page_2", page2_proc, LP(hTest)}, {"Page_3", page3_proc, LP(hTest)}, {"Page_4", page4_proc, LP(hTest)}, {"", NULL, 0} }; enum local_keys { DRAW_MESS = YKEY_LOCALS }; switch (message) { case YOPEN: case YDRAW: YDrawRectF (0,0, WND->w,WND->h, YColor("yellow")); YBeginGroup ("MESSAGES", 30,375, 420,55, YColor("")); YWnd (&hTest, TESTMSG, "", 15,15, 385,30, 0,0,0,0, CLR_DEF); /* YWnd (&hTest, testmsg_proc, "", 15,15, 385,30, 0,0,0,0, CLR_DEF); */ YEndGroup (); YWnd (&hExit, PUSH, "Exit", 455,380, 65,40, 0,0,0,0, YColor("lime")); YWnd (Ph(), BOOK, "", 30,20, WND->w-60,340, (long)pages,75,30,YUP, CLR_DEF); break; case YCLOSE: YWndClean (id); break; case YPUSH: if (mes1 == hExit) exit(0); default: return (YSend (hTest, message, mes1,mes2,mes3,mes4)); } RETURN_TRUE; }
void LAV ( const AbstractDistMatrix<Real>& A, const AbstractDistMatrix<Real>& b, AbstractDistMatrix<Real>& xPre, const lp::affine::Ctrl<Real>& ctrl ) { EL_DEBUG_CSE DistMatrixWriteProxy<Real,Real,MC,MR> xProx( xPre ); auto& x = xProx.Get(); const Int m = A.Height(); const Int n = A.Width(); const Grid& g = A.Grid(); const Range<Int> xInd(0,n), uInd(n,n+m), vInd(n+m,n+2*m); DistMatrix<Real> c(g), AHat(g), G(g), h(g); // c := [0;1;1] // ============ Zeros( c, n+2*m, 1 ); auto cuv = c( IR(n,n+2*m), ALL ); Fill( cuv, Real(1) ); // \hat A := [A, I, -I] // ==================== Zeros( AHat, m, n+2*m ); auto AHatx = AHat( IR(0,m), xInd ); auto AHatu = AHat( IR(0,m), uInd ); auto AHatv = AHat( IR(0,m), vInd ); AHatx = A; FillDiagonal( AHatu, Real( 1) ); FillDiagonal( AHatv, Real(-1) ); // G := | 0 -I 0 | // | 0 0 -I | // ================ Zeros( G, 2*m, n+2*m ); auto Guv = G( IR(0,2*m), IR(n,n+2*m) ); FillDiagonal( Guv, Real(-1) ); // h := | 0 | // | 0 | // ========== Zeros( h, 2*m, 1 ); // Solve the affine linear program // =============================== DistMatrix<Real> xHat(g), y(g), z(g), s(g); LP( AHat, G, b, c, h, xHat, y, z, s, ctrl ); // Extract x // ========= x = xHat( xInd, ALL ); }
// MODIFY THIS FUNCTION void drawMesh(cgtk::GLSLProgram &program, const MeshVAO &meshVAO) { program.enable(); // al=1; globals.program.setUniform1f("u_al",al); globals.program.setUniform1f("u_dl",dl); globals.program.setUniform1f("u_sl",sl); globals.program.setUniform1f("u_gamma",gam); globals.program.setUniform1f("u_invert",inv); // globals.program.setUniform1f("u_zoom",zoom); // Define the model, view, and projection matrices here glm::mat4 model = glm::mat4(1.0f); glm::mat4 view = glm::lookAt(glm::vec3(0.0f,0.0f,6.0f), glm::vec3(0.0f,1.0f,0.0f), glm::vec3(0.0f,0.0f,1.0f)); glm::mat4 projection = glm::perspective(zoom*10.5f,1.0f,3.0f,8.0f); // Construct the ModelViewProjection, ModelView, and normal // matrices here and pass them as uniform variables to the shader // program glm::mat4 MV = view*model; globals.program.setUniformMatrix4f("u_MV",MV); glm::mat4 MVP = projection*view*model; globals.program.setUniformMatrix4f("u_MVP",MVP); glm::mat4 NM = glm::transpose(glm::inverse(MV)); globals.program.setUniformMatrix4f("u_NM", NM); // Set up the light source and material properties and pass them // as uniform variables to the shader program, along with the // flags (uniform int variables) used for toggling on/off // different parts of the rendering glm::vec3 LP(0.0,0.0,8.0); globals.program.setUniform3f("u_LP", LP); glm::vec3 LC(1.0,1.0,1.0); globals.program.setUniform3f("u_LC", LC); glm::vec3 DC(1.0,1.0,0); glm::vec3 AC=glm::vec3(1.0,0,1.0); glm::vec3 SC(0,1.0,1.0); globals.program.setUniform3f("u_DC", DC); globals.program.setUniform3f("u_AC", AC); globals.program.setUniform3f("u_SC", SC); float SP = 1.0; // globals.program.setUniform1f("u_SP", SP); glBindVertexArray(meshVAO.vao); glDrawElements(GL_TRIANGLES, meshVAO.numIndices, GL_UNSIGNED_INT, 0); glBindVertexArray(0); program.disable(); }
// Exchange borders between processes during computation void exchange_borders() { float *lp = local_pres; if (north >= 0) { exchange_border(lp + LP(0, 0), lp + LP(-1, 0), north, border_row_t); } if (south >= 0) { exchange_border(lp + LP(local_height - 1, 0), lp + LP(local_height, 0), south, border_row_t); } if (west >= 0) { exchange_border(lp + LP(0, 0), lp + LP(0, -1), west, border_col_t); } if (east >= 0) { exchange_border(lp + LP(0, local_width - 1), lp + LP(0, local_width), east, border_col_t); } }
void LAV ( const Matrix<Real>& A, const Matrix<Real>& b, Matrix<Real>& x, const lp::affine::Ctrl<Real>& ctrl ) { EL_DEBUG_CSE const Int m = A.Height(); const Int n = A.Width(); const Range<Int> xInd(0,n), uInd(n,n+m), vInd(n+m,n+2*m); Matrix<Real> c, AHat, G, h; // c := [0;1;1] // ============ Zeros( c, n+2*m, 1 ); auto cuv = c( IR(n,n+2*m), ALL ); Fill( cuv, Real(1) ); // \hat A := [A, I, -I] // ==================== Zeros( AHat, m, n+2*m ); auto AHatx = AHat( IR(0,m), xInd ); auto AHatu = AHat( IR(0,m), uInd ); auto AHatv = AHat( IR(0,m), vInd ); AHatx = A; FillDiagonal( AHatu, Real( 1) ); FillDiagonal( AHatv, Real(-1) ); // G := | 0 -I 0 | // | 0 0 -I | // ================ Zeros( G, 2*m, n+2*m ); auto Guv = G( IR(0,2*m), IR(n,n+2*m) ); FillDiagonal( Guv, Real(-1) ); // h := | 0 | // | 0 | // ========== Zeros( h, 2*m, 1 ); // Solve the affine linear program // =============================== Matrix<Real> xHat, y, z, s; LP( AHat, G, b, c, h, xHat, y, z, s, ctrl ); // Extract x // ========== x = xHat( xInd, ALL ); }
bool Shader::checkShader(GLint object, GLint type, GLenum shaderType) { GLint success; glGetShaderiv(object, type, &success); if(success == GL_FALSE) { std::cout << ConsoleBlocks::Error << LP("ShaderCompileError", {getShaderName(shaderType)}) << std::endl; GLint infoLogSize; glGetShaderiv(object, GL_INFO_LOG_LENGTH, &infoLogSize); char* buffer = new char[infoLogSize]; glGetShaderInfoLog(object, infoLogSize, NULL, buffer); std::cout << ConsoleBlocks::Info << buffer << "\n\n"; delete[] buffer; return false; } return true; }
// Calculate the value for one element in the grid float calculate_jacobi(int row, int col) { float x1 = local_pres0[LP(row, col - 1)], x2 = local_pres0[LP(row - 1, col)], x3 = local_pres0[LP(row, col + 1)], x4 = local_pres0[LP(row + 1, col)]; // If the element is on the border of 'pres', set to it's current value instead if (north < 0 && row == 0) { x2 = local_pres0[LP(row, col)]; } if (south < 0 && row == local_height) { x4 = local_pres0[LP(row, col)]; } if (west < 0 && col == 0) { x1 = local_pres0[LP(row, col)]; } if (east < 0 && col == local_width) { x3 = local_pres0[LP(row, col)]; } return 0.25 * (x1 + x2 + x3 + x4 - local_diverg[row * local_width + col]); }
void sunxi_bg_every_frame(int hide) { unsigned long args[4] = {0}; int r; if(!bg_layer) return; args[1] = bg_layer; float alpha = hide ? 0 : 1; bg_wanted_alpha = LP(16, bg_wanted_alpha, alpha); int a8 = bg_wanted_alpha * 255.0; if(a8 == 0) { if(bg_open) { r = ioctl(sunxi.dispfd, DISP_CMD_LAYER_CLOSE, args); if(r) perror("ioctl(disphd,DISP_CMD_LAYER_CLOSE)"); else bg_open = 0; } } else { if(!bg_open) { r = ioctl(sunxi.dispfd, DISP_CMD_LAYER_OPEN, args); if(r) { perror("ioctl(disphd,DISP_CMD_LAYER_OPEN)"); return; } else bg_open = 1; } if(ioctl(sunxi.dispfd, DISP_CMD_LAYER_BOTTOM, args)) perror("ioctl(disphd,DISP_CMD_LAYER_BOTTOM)"); args[2] = a8; if(ioctl(sunxi.dispfd, DISP_CMD_LAYER_SET_ALPHA_VALUE, args)) perror("ioctl(disphd, DISP_CMD_LAYER_SET_ALPHA_VALUE)"); } }
// Calculates the displacements used in'gather_pres' and 'distribute_diverg' // for each of the processes, // and initializes 'local_pres' and 'local_pres0' to empty arrays void init_local_pres() { displs = malloc(sizeof(int) * size); counts = malloc(sizeof(int) * size); for (int i = 0; i < dims[0]; i++) { for (int j = 0; j < dims[1]; j++) { int index = i * dims[1] + j; displs[index] = i * local_height * (imageSize + 2) + j * local_width; counts[index] = 1; } } for (int i = -1; i < local_height + 1; i++) { for (int j = -1; j < local_width + 1; j++) { int index = LP(i, j); local_pres0[index] = 0.0; local_pres[index] = 0.0; } } }
std::pair<int, std::string> test_dag_shortest_path(std::ostream& strm,int argc, const char *argv[]) { sparse_graph_t s10(15, graph_type_t::DIRECTED); s10.insert(simple_edge_t(0,1,0.41));//1 s10.insert(simple_edge_t(0,7,0.41));//2 s10.insert(simple_edge_t(0,9,0.41));//3 s10.insert(simple_edge_t(1,2,0.51));//4 s10.insert(simple_edge_t(7,8,0.32));//5 s10.insert(simple_edge_t(8,2,0.32));//6 s10.insert(simple_edge_t(7,3,0.32));//7 s10.insert(simple_edge_t(6,8,0.21));//8 s10.insert(simple_edge_t(6,3,0.21));//9 s10.insert(simple_edge_t(9,4,0.29));//10 s10.insert(simple_edge_t(9,6,0.29));//11 s10.insert(simple_edge_t(5,5,0));//12 dag_all_shortest_paths<simple_edge_t> LP(s10); LP.pp(strm); strm << std::endl; return DONE; }
std::pair<int, std::string> test_dag_longest_path(std::ostream& strm,int argc, const char *argv[]) { sparse_graph_t s10(15, graph_type_t::DIRECTED); s10.insert(simple_edge_t(0,1,0.41));//1 s10.insert(simple_edge_t(0,7,0.41));//2 s10.insert(simple_edge_t(0,9,0.41));//3 s10.insert(simple_edge_t(1,2,0.51));//4 s10.insert(simple_edge_t(7,8,0.32));//5 s10.insert(simple_edge_t(8,2,0.32));//6 s10.insert(simple_edge_t(7,3,0.32));//7 s10.insert(simple_edge_t(6,8,0.21));//8 s10.insert(simple_edge_t(6,3,0.21));//9 s10.insert(simple_edge_t(9,4,0.29));//10 s10.insert(simple_edge_t(9,6,0.29));//11 s10.insert(simple_edge_t(5,5,0));//12 dag_all_longest_paths<simple_edge_t> LP(s10); LP.pp(strm); strm << "------------- distance ----------" << std::endl; std::vector<double> expected_dist= {0, 0.41, 1.23, 0.91, 0.70,0,0.70, 0.41, 0.91,0.41}; size_t index = expected_dist.size(); while (index-- > 0 ) { strm << "index : " << index << " expected : " << expected_dist[index] << " found : " << LP.dist(index) << std::endl; ASSERT(LP.dist(index).second && abs(LP.dist(index).first - expected_dist[index]) < 0.0001); } strm << "------------ predecessor ---------" << std::endl; std::vector<typename simple_edge_t::label_value_type> expected_pred = {0, 0, 8, 6, 9, 5, 9, 0, 6, 0}; index = expected_pred.size(); while (index-- > 0 ) { strm << "index : " << index << " expected : " << expected_pred[index] << " found : " << LP.pred(index) << std::endl; ASSERT(LP.pred(index).second && LP.pred(index).first == expected_pred[index]); } strm << std::endl; return DONE; }
void listcpy1(L d, L s, I i) { #define DS s1-s0 #define DD d1-d0 I ss=t_sizeof(d->t); P d0=LIST_PTR_ATS(d,i,ss), d1=LP(d)+d->c*ss; P s0=LIST_PTR_ATS(s,0,ss), s1=LP(s)+s->c*ss; I l=s->l*ss; if (DS <= DD) { memcpy(d0,s0,min(l,DS)); if((l-=DS)<=0)return; s0=LP(s); d0+=DS; memcpy(d0,s0,min(l,DD)); if((l-=DD)<=0)return; s0+=DD; d0=LP(d); } else { memcpy(d0,s0,min(l,DD)); if((l-=DD)<=0)return; s0+=DD; d0=LP(d); memcpy(d0,s0,min(l,DS)); if((l-=DS)<=0)return; s0=LP(s); d0+=DS; } memcpy(d0,s0,l); #undef DS #undef DD }
int Ifpack_Chebyshev:: CG(const int MaximumIterations, double& lambda_min, double& lambda_max) { IFPACK_CHK_ERR(-1);// NTS: This always seems to yield errors in AztecOO, ergo, // I turned it off. if(!UseBlockMode_) IFPACK_CHK_ERR(-1); #ifdef HAVE_IFPACK_AZTECOO Epetra_Vector x(Operator_->OperatorDomainMap()); Epetra_Vector y(Operator_->OperatorRangeMap()); x.Random(); y.PutScalar(0.0); Epetra_LinearProblem LP(const_cast<Epetra_RowMatrix*>(&*Matrix_), &x, &y); AztecOO solver(LP); solver.SetAztecOption(AZ_solver, AZ_cg_condnum); solver.SetAztecOption(AZ_output, AZ_none); solver.SetPrecOperator(&*InvBlockDiagonal_); solver.Iterate(MaximumIterations, 1e-10); const double* status = solver.GetAztecStatus(); lambda_min = status[AZ_lambda_min]; lambda_max = status[AZ_lambda_max]; return(0); #else cout << "You need to configure IFPACK with support for AztecOO" << endl; cout << "to use the CG estimator. This may require --enable-aztecoo" << endl; cout << "in your configure script." << endl; IFPACK_CHK_ERR(-1); #endif }
//============================================================================== int Ifpack_Chebyshev:: CG(const Epetra_Operator& Operator, const Epetra_Vector& InvPointDiagonal, const int MaximumIterations, double& lambda_min, double& lambda_max) { #ifdef HAVE_IFPACK_AZTECOO Epetra_Vector x(Operator.OperatorDomainMap()); Epetra_Vector y(Operator.OperatorRangeMap()); x.Random(); y.PutScalar(0.0); Epetra_LinearProblem LP(const_cast<Epetra_Operator*>(&Operator), &x, &y); AztecOO solver(LP); solver.SetAztecOption(AZ_solver, AZ_cg_condnum); solver.SetAztecOption(AZ_output, AZ_none); Ifpack_DiagPreconditioner diag(Operator.OperatorDomainMap(), Operator.OperatorRangeMap(), InvPointDiagonal); solver.SetPrecOperator(&diag); solver.Iterate(MaximumIterations, 1e-10); const double* status = solver.GetAztecStatus(); lambda_min = status[AZ_lambda_min]; lambda_max = status[AZ_lambda_max]; return(0); #else cout << "You need to configure IFPACK with support for AztecOO" << endl; cout << "to use the CG estimator. This may require --enable-aztecoo" << endl; cout << "in your configure script." << endl; IFPACK_CHK_ERR(-1); #endif }
#include <string.h> #include <signal.h> #include <sys/mman.h> #include <sched.h> /* for cpu sets */ #include "litmus.h" #include "internal.h" #define LP(name) {name ## _SEM, #name} static struct { int id; const char* name; } protocol[] = { LP(FMLP), LP(SRP), LP(MPCP), LP(MPCP_VS), {MPCP_VS_SEM, "MPCP-VS"}, LP(DPCP), LP(PCP), }; #define NUM_PROTOS (sizeof(protocol)/sizeof(protocol[0])) int lock_protocol_for_name(const char* name) { int i; for (i = 0; i < NUM_PROTOS; i++)
int main() { srand((unsigned)time(NULL)); Graph g("d:\\github\\CRANA_Voting\\graph2.txt"); int caseN=6; double judge=0,judge_sum=0; int req_sum=0,result_sum=0; vector<Req*> reqL_all; list<CEdge*> listEdge; int winner = 0;//No.1 float happiness_sum = 0;//记录各轮服务累加起来的满意度 int K_sum = 0;//记录一共有多少条流需要安排路径 float table[M2C+1][N2C+1] = {0}; int ranking[N2C+1]={0};//记录一种排序的投票人数 ofstream reqRecord("d:\\github\\reqRecord.txt"); //图的初始化 ifstream test("d:\\github\\CRANA_Voting\\graph2.txt"); int node_num,edge_num; int src,dst,weight,cap; test>>node_num>>edge_num; for(int i=1;i<=edge_num;i++) { test>>src>>dst>>weight>>cap; CEdge* e1=new CEdge(src,dst,weight,cap); CEdge* e2=new CEdge(dst,src,weight,cap); listEdge.push_back(e1); listEdge.push_back(e2); } CGraph gv(listEdge,node_num,edge_num); gv.p3(); gv.p4(); int req_num,req_constant; req_num=6; req_constant = req_num+1; for(int icase=1;icase<=caseN;icase++) { cout<<"--------------------------------------------------"<<endl; cout<<"case "<<icase<<endl; //需求记录 CReq* r1=new CReq(0,0,0); gv.r.push_back(r1); K=MAXREQ; if (req_num != (req_constant-1)) //第一个req来的时候,不需要修改link_bw { for (int k = 1; k <= K; k++) { list<CEdge*>::iterator it, iend; iend = listEdge.end(); for (it = listEdge.begin(); it != iend; it++) { gv.link_bw[k][(*it)->getTail()][(*it)->getHead()] = gv.link_bw[winner][(*it)->getTail()][(*it)->getHead()]; //cout << (*it)->getTail() << " " << (*it)->getHead() << " " << g.link_bw[k][(*it)->getTail()][(*it)->getHead()]<<endl; } } } for (int i = 1; i <= K; i++) for (int j = 1; j <= K; j++) { CPath* pa = new CPath(); gv.path_record[i][j] = pa; } //case输入 reqRecord<<"case "<<icase<<endl; int reqN,a,b,c; vector<Req*> reqL; reqN=MAXREQ; reqL.clear(); a=1;b=17; for(int i=0;i<reqN;i++) { c=0; while(c==0){c = 3 + rand()%MAXFLOW;} Req* r=new Req(a,b,c); reqL.push_back(r); CReq* r2=new CReq(a,b,c); gv.bw[i+1]=c; gv.r.push_back(r2); reqL_all.push_back(r); reqRecord<<c<<" "; } reqRecord<<endl<<endl; //@@@@@@@@@@@@@@@@ Voting @@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@ Voting @@@@@@@@@@@@@@@@@@@@@@ //提方案 for(int i=1;i<=K;i++) { gv.single_flow_propose(i,K); } //评价 for(int i=1;i<=K;i++) for(int j=1;j<=K;j++) gv.judge[i][j]=0; for(int i=1;i<=K;i++) gv.judge_sum[i]=0; for(int i=1;i<=K;i++) { //cout<<"evaluate "<<i<<endl; gv.single_flow_evaluate(i,K); gv.cost_evaluate(i); } /* cout<<endl; cout<<"************ single judge **************"<<endl; for(int i=1;i<=K;i++) { cout<<"flow "; cout.setf(ios::right); cout.width(3); cout<<i<<" judge: "; for(int j=1;j<=K;j++){ cout.setf(ios::left); cout.width(4); cout<<gv.judge[i][j]<<" "; } cout<<endl; } cout<<endl; cout<<"************ sum judge **************"<<endl; for(int i=1;i<=K;i++) { cout<<"proposal "<<i<<" : "<<gv.judge_sum[i]<<endl; } */ //voting method for(int i=1;i<=K;i++) for(int j=1;j<=K;j++) { if(gv.judge[i][j]==0) {table[i][j]=10000;}//如果是0,说明流没有摆在网络中 else table[i][j]=gv.judge[i][j]; } for(int i=1;i<=K;i++) ranking[i]=1; /* cout<<"************ voting table **************"<<endl; for(int i=1;i<=K;i++) { cout<<"flow "; cout.setf(ios::right); cout.width(3); cout<<i<<" judge: "; for(int j=1;j<=K;j++){ cout.setf(ios::left); cout.width(5); cout<<table[i][j]<<" "; } cout<<endl; } cout<<endl; */ cout<<" voting result "; int choice = 1; Voting vv(table,ranking,K,K); winner=vv.voting(choice); cout<<endl; if (choice == 1) cout << "schulze method : " << winner << endl; else if (choice == 2) cout << "comulative method: " << winner << endl; else if (choice == 3) cout << "copeland condorcet method: " << winner << endl; else cout << "ranked pairs method: " << winner << endl; //计算满意度 float happiness=0;//一轮所有流的满意度和,越高越好,0<=满意度<=1 for (int i = 1; i <= K; i++) happiness += table[i][i] / table[i][winner];//最好抉择评分/当前抉择评分 happiness_sum += happiness; K_sum += K; //如果流没有被安排进网络,就增加惩罚cost for(int i=1;i<=K;i++) if(table[i][winner]=10000) gv.judge_sum[winner]+=MAXPATH*gv.bw[i]; cout << "第" << req_constant - req_num << "轮整体满意度: " << happiness/K << endl; cout << "多轮整体满意度和:" << happiness_sum / K_sum << endl; cout << "多轮整体代价和: " << gv.judge_sum[winner] << endl; //@@@@@@@@@@@@@@@@@End of Voting@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@End of Voting@@@@@@@@@@@@@@@@@@@@@@@@@ //最优部署计算 g.cost_best.clear(); g.cost_LP.clear(); //cout<<"35 line"<<endl; for(int i=0;i<reqN;i++) { //cout<<reqL[i]->src<<" "<<reqL[i]->dst<<" "<<reqL[i]->flow<<endl; g.cost_best.push_back(reqL[i]->flow * g.dijkstra(reqL[i]->src,reqL[i]->dst,reqL[i]->flow)); } cout<<endl<<" LP result "<<endl; //线性规划部署 double result=0; result=LP(&g,reqL); //用线性规划解计算cost result_sum += result; cout<<"cost of this case is: "<<result<<endl; cout<<"cost of all cases is: "<<result_sum<<endl; //计算满意度 if(result==999999) judge=0; else { judge=0; //for(int i=0;i<reqN;i++) // cout<<g.cost_best[i]<<" "<<g.cost_LP[i]<<endl; for(int i=0;i<reqN;i++) judge += g.cost_best[i]/g.cost_LP[i]; } judge_sum += judge; req_sum += reqN; cout<<"单轮满意度: "<<judge/reqN<<endl; cout<<"多轮满意度: "<<judge_sum/req_sum<<endl; } //全局线性规划部署 cout<<endl<<" LP_ALL result "<<endl; Graph g3("d:\\github\\CRANA_Voting\\graph2.txt"); double result3=0; result3=LP(&g3,reqL_all); cout<<"cost of all cases is: "<<result3<<endl; cout<<"End of the Program"<<endl; test.close(); reqRecord.close(); getchar(); return 0; }
int main() { openlog("nana", LOG_PID, LOG_DAEMON); L("the temperature is falling - %d", 35); LP(LOG_USER, "the snow is falling"); return 0; }
void CoronaRenderer::defineLights() { // first get the globals node and serach for a directional light connection MObject coronaGlobals = objectFromName(MString("coronaGlobals")); MObjectArray nodeList; MStatus stat; if( this->mtco_renderGlobals->useSunLightConnection ) { getConnectedInNodes(MString("sunLightConnection"), coronaGlobals, nodeList); if( nodeList.length() > 0) { MObject sunObj = nodeList[0]; if(sunObj.hasFn(MFn::kTransform)) { // we suppose what's connected here is a dir light transform MVector lightDir(0, 0, 1); // default dir light dir MFnDagNode sunDagNode(sunObj); lightDir *= sunDagNode.transformationMatrix(); lightDir *= this->mtco_renderGlobals->globalConversionMatrix; lightDir.normalize(); MObject sunDagObj = sunDagNode.child(0, &stat); if( !stat ) logger.error("no child 0"); MColor sunColor(1); float colorMultiplier = 1.0f; if(sunDagObj.hasFn(MFn::kDirectionalLight)) { MFnDependencyNode sunNode(sunDagObj); getColor("color", sunNode, sunColor); getFloat("mtco_sun_multiplier", sunNode, colorMultiplier); }else{ logger.warning(MString("Sun connection is not a directional light - using transform only.")); } sunColor *= colorMultiplier * 10000.0; Corona::Sun sun; sun.active = true; sun.dirTo = Corona::Dir(lightDir.x, lightDir.y, lightDir.z).getNormalized(); sun.color = Corona::Rgb(sunColor.r,sunColor.g,sunColor.b); sun.visibleDirect = true; sun.visibleReflect = true; sun.visibleRefract = true; sun.sizeMultiplier = 2.0f; this->context.scene->getSun() = sun; } } } for( size_t lightId = 0; lightId < this->mtco_scene->lightList.size(); lightId++) { mtco_MayaObject *obj = (mtco_MayaObject *)this->mtco_scene->lightList[lightId]; if(!obj->visible) continue; if( this->isSunLight(obj)) continue; MFnDependencyNode depFn(obj->mobject); if( obj->mobject.hasFn(MFn::kPointLight)) { MColor col; getColor("color", depFn, col); float intensity = 1.0f; getFloat("intensity", depFn, intensity); int decay = 0; getEnum(MString("decayRate"), depFn, decay); MMatrix m = obj->transformMatrices[0] * this->mtco_renderGlobals->globalConversionMatrix; Corona::Pos LP(m[3][0],m[3][1],m[3][2]); PointLight *pl = new PointLight; pl->LP = LP; pl->distFactor = 1.0/this->mtco_renderGlobals->scaleFactor; pl->lightColor = Corona::Rgb(col.r, col.g, col.b); pl->lightIntensity = intensity; getEnum(MString("decayRate"), depFn, pl->decayType); this->context.scene->addLightShader(pl); } if( obj->mobject.hasFn(MFn::kSpotLight)) { MVector lightDir(0, 0, -1); MColor col; getColor("color", depFn, col); float intensity = 1.0f; getFloat("intensity", depFn, intensity); MMatrix m = obj->transformMatrices[0] * this->mtco_renderGlobals->globalConversionMatrix; lightDir *= obj->transformMatrices[0] * this->mtco_renderGlobals->globalConversionMatrix; lightDir.normalize(); Corona::Pos LP(m[3][0],m[3][1],m[3][2]); SpotLight *sl = new SpotLight; sl->LP = LP; sl->lightColor = Corona::Rgb(col.r, col.g, col.b); sl->lightIntensity = intensity; sl->LD = Corona::Dir(lightDir.x, lightDir.y, lightDir.z); sl->angle = 45.0f; sl->distFactor = 1.0/this->mtco_renderGlobals->scaleFactor; getEnum(MString("decayRate"), depFn, sl->decayType); getFloat("coneAngle", depFn, sl->angle); getFloat("penumbraAngle", depFn, sl->penumbraAngle); getFloat("dropoff", depFn, sl->dropoff); this->context.scene->addLightShader(sl); } if( obj->mobject.hasFn(MFn::kDirectionalLight)) { MVector lightDir(0, 0, -1); MColor col; getColor("color", depFn, col); float intensity = 1.0f; getFloat("intensity", depFn, intensity); MMatrix m = obj->transformMatrices[0] * this->mtco_renderGlobals->globalConversionMatrix; lightDir *= m; lightDir.normalize(); Corona::Pos LP(m[3][0],m[3][1],m[3][2]); DirectionalLight *dl = new DirectionalLight; dl->LP = LP; dl->lightColor = Corona::Rgb(col.r, col.g, col.b); dl->lightIntensity = intensity; dl->LD = Corona::Dir(lightDir.x, lightDir.y, lightDir.z); this->context.scene->addLightShader(dl); } if( obj->mobject.hasFn(MFn::kAreaLight)) { logger.warning(MString("Area light: ") + obj->shortName + " not yet supported."); MMatrix m = obj->transformMatrices[0] * this->mtco_renderGlobals->globalConversionMatrix; obj->geom = defineStdPlane(); Corona::AnimatedAffineTm atm; this->setAnimatedTransformationMatrix(atm, obj); obj->instance = obj->geom->addInstance(atm, NULL, NULL); //this->defineMaterial(obj->instance, obj); } } }
void CoronaRenderer::updateLight(std::shared_ptr<MayaObject> mobj) { std::shared_ptr<mtco_MayaObject> obj(std::static_pointer_cast<mtco_MayaObject>(mobj)); if (obj->lightShader != nullptr) { if (this->context.scene->hasLightShader(obj->lightShader)) this->context.scene->deleteLightShader(obj->lightShader); } if (obj->removed) return; if (MayaTo::getWorldPtr()->renderType == MayaTo::MayaToWorld::WorldRenderType::IPRRENDER) { obj->transformMatrices.clear(); obj->transformMatrices.push_back(obj->dagPath.inclusiveMatrix()); } MFnDependencyNode rGlNode(getRenderGlobalsNode()); MObject coronaGlobals = getRenderGlobalsNode(); std::shared_ptr<RenderGlobals> renderGlobals = MayaTo::getWorldPtr()->worldRenderGlobalsPtr; std::shared_ptr<MayaScene> mayaScene = MayaTo::getWorldPtr()->worldScenePtr; MObjectArray nodeList; MStatus stat; MFnDependencyNode glFn(getRenderGlobalsNode()); Corona::Rgb bgRgb = toCorona(getColorAttr("bgColor", glFn)); int bgType = getEnumInt("bgType", glFn); MayaObject *sunLight = nullptr; MFnDependencyNode depFn(obj->mobject); if (obj->mobject.hasFn(MFn::kPointLight)) { MColor col; getColor("color", depFn, col); float intensity = 1.0f; getFloat("intensity", depFn, intensity); int decay = 0; getEnum(MString("decayRate"), depFn, decay); MMatrix m = obj->transformMatrices[0] * renderGlobals->globalConversionMatrix; Corona::Pos LP(m[3][0], m[3][1], m[3][2]); PointLight *pl = new PointLight; pl->LP = LP; pl->distFactor = 1.0 / renderGlobals->scaleFactor; pl->lightColor = Corona::Rgb(col.r, col.g, col.b); pl->lightIntensity = intensity; getEnum(MString("decayRate"), depFn, pl->decayType); pl->lightRadius = getFloatAttr("lightRadius", depFn, 0.0) * renderGlobals->scaleFactor; pl->doShadows = getBoolAttr("useRayTraceShadows", depFn, true); col = getColorAttr("shadowColor", depFn); pl->shadowColor = Corona::Rgb(col.r, col.g, col.b); for (auto excludedObj : obj->excludedObjects) { pl->excludeList.nodes.push(excludedObj.get()); } this->context.scene->addLightShader(pl); obj->lightShader = pl; } if (obj->mobject.hasFn(MFn::kSpotLight)) { MVector lightDir(0, 0, -1); MColor col; getColor("color", depFn, col); float intensity = 1.0f; getFloat("intensity", depFn, intensity); MMatrix m = obj->transformMatrices[0] * renderGlobals->globalConversionMatrix; lightDir *= obj->transformMatrices[0] * renderGlobals->globalConversionMatrix; lightDir.normalize(); Corona::Pos LP(m[3][0], m[3][1], m[3][2]); SpotLight *sl = new SpotLight; sl->LP = LP; sl->lightColor = Corona::Rgb(col.r, col.g, col.b); sl->lightIntensity = intensity; sl->LD = Corona::Dir(lightDir.x, lightDir.y, lightDir.z); sl->angle = 45.0f; sl->distFactor = 1.0 / renderGlobals->scaleFactor; getEnum(MString("decayRate"), depFn, sl->decayType); getFloat("coneAngle", depFn, sl->angle); getFloat("penumbraAngle", depFn, sl->penumbraAngle); getFloat("dropoff", depFn, sl->dropoff); sl->lightRadius = getFloatAttr("lightRadius", depFn, 0.0) * renderGlobals->scaleFactor; sl->doShadows = getBoolAttr("useRayTraceShadows", depFn, true); col = getColorAttr("shadowColor", depFn); sl->shadowColor = Corona::Rgb(col.r, col.g, col.b); for (auto excludedObj : obj->excludedObjects) { sl->excludeList.nodes.push(excludedObj.get()); } Corona::AffineTm tm; setTransformationMatrix(sl->lightWorldInverseMatrix, m); ShadingNetwork network(obj->mobject); sl->lightColorMap = defineAttribute(MString("color"), depFn, network, oslRenderer); this->context.scene->addLightShader(sl); obj->lightShader = sl; } if (obj->mobject.hasFn(MFn::kDirectionalLight)) { if (getBoolAttr("mtco_useAsSun", depFn, false)) { if (sunLight != nullptr) { Logging::error(MString("A sun light is already defined, ignoring ") + obj->shortName); return; } sunLight = obj.get(); MVector lightDir(0, 0, 1); // default dir light dir lightDir *= obj->transformMatrices[0]; lightDir *= renderGlobals->globalConversionMatrix; lightDir.normalize(); MColor sunColor(1); MFnDependencyNode sunNode(obj->mobject); getColor("color", sunNode, sunColor); sunColor *= getFloatAttr("intensity", sunNode, 1.0f); //float colorMultiplier colorMultiplier = getFloatAttr("mtco_sun_multiplier", sunNode, 1.0f); const float intensityFactor = (1.f - cos(Corona::SUN_PROJECTED_HALF_ANGLE)) / (1.f - cos(getFloatAttr("sunSizeMulti", rGlNode, 1.0f) * Corona::SUN_PROJECTED_HALF_ANGLE)); sunColor *= intensityFactor * 1.0;// 2000000; Corona::Sun sun; Corona::ColorOrMap bgCoMap = this->context.scene->getBackground(); SkyMap *sky = dynamic_cast<SkyMap *>(bgCoMap.getMap()); Corona::Rgb avgColor(1, 1, 1); if (sky != nullptr) { avgColor = sky->sc(); } Corona::Rgb sColor(sunColor.r, sunColor.g, sunColor.b); sun.color = sColor * avgColor; sun.active = true; sun.dirTo = Corona::Dir(lightDir.x, lightDir.y, lightDir.z).getNormalized(); //sun.color = Corona::Rgb(sunColor.r,sunColor.g,sunColor.b); sun.visibleDirect = true; sun.visibleReflect = true; sun.visibleRefract = true; sun.sizeMultiplier = getFloatAttr("sunSizeMulti", rGlNode, 1.0); this->context.scene->getSun() = sun; if (sky != nullptr) { sky->initSky(); this->context.scene->setBackground(bgCoMap); avgColor = sky->sc(); this->context.scene->getSun().color = sColor * avgColor; } } else{ MVector lightDir(0, 0, -1); MVector lightDirTangent(1, 0, 0); MVector lightDirBiTangent(0, 1, 0); MColor col; getColor("color", depFn, col); float intensity = 1.0f; getFloat("intensity", depFn, intensity); MMatrix m = obj->transformMatrices[0] * renderGlobals->globalConversionMatrix; lightDir *= m; lightDirTangent *= m; lightDirBiTangent *= m; lightDir.normalize(); Corona::Pos LP(m[3][0], m[3][1], m[3][2]); DirectionalLight *dl = new DirectionalLight; dl->LP = LP; dl->lightColor = Corona::Rgb(col.r, col.g, col.b); dl->lightIntensity = intensity; dl->LD = Corona::Dir(lightDir.x, lightDir.y, lightDir.z); dl->LT = Corona::Dir(lightDirTangent.x, lightDirTangent.y, lightDirTangent.z); dl->LBT = Corona::Dir(lightDirBiTangent.x, lightDirBiTangent.y, lightDirBiTangent.z); dl->lightAngle = getFloatAttr("lightAngle", depFn, 0.0); dl->doShadows = getBoolAttr("useRayTraceShadows", depFn, true); col = getColorAttr("shadowColor", depFn); dl->shadowColor = Corona::Rgb(col.r, col.g, col.b); for (auto excludedObj : obj->excludedObjects) { dl->excludeList.nodes.push(excludedObj.get()); } this->context.scene->addLightShader(dl); obj->lightShader = dl; } } if (obj->mobject.hasFn(MFn::kAreaLight)) { MMatrix m = obj->transformMatrices[0] * renderGlobals->globalConversionMatrix; if ( obj->geom == nullptr) obj->geom = defineStdPlane(); obj->geom->deleteAllInstances(); Corona::AnimatedAffineTm atm; this->setAnimatedTransformationMatrix(atm, obj); obj->instance = obj->geom->addInstance(atm, nullptr, nullptr); if (getBoolAttr("mtco_envPortal", depFn, false)) { Corona::EnviroPortalMtlData data; Corona::SharedPtr<Corona::IMaterial> mat = data.createMaterial(); Corona::IMaterialSet ms = Corona::IMaterialSet(mat); obj->instance->addMaterial(ms); } else{ Corona::NativeMtlData data; MColor lightColor = getColorAttr("color", depFn); float intensity = getFloatAttr("intensity", depFn, 1.0f); lightColor *= intensity; Corona::ColorOrMap com; // experimental direct corona texture if (getBoolAttr("mtco_noOSL", depFn, false)) { MObject fileNode = getConnectedInNode(obj->mobject, "color"); if ((fileNode != MObject::kNullObj) && (fileNode.hasFn(MFn::kFileTexture))) { MFnDependencyNode fileDep(fileNode); mtco_MapLoader loader(fileNode); Corona::SharedPtr<Corona::Abstract::Map> texmap = loader.loadBitmap(""); com = Corona::ColorOrMap(bgRgb, texmap); } } else { com = defineAttribute(MString("color"), obj->mobject, oslRenderer); OSLMap *oslmap = (OSLMap *)com.getMap(); if (oslmap != nullptr) { oslmap->multiplier = intensity; } else{ Corona::Rgb col = com.getConstantColor() * intensity; com.setColor(col); } } data.emission.color = com; data.castsShadows = getBoolAttr("mtco_castShadows", depFn, false); for (auto excludedObj : obj->excludedObjects) { data.emission.excluded.nodes.push(excludedObj.get()); } data.emission.disableSampling = false; data.emission.useTwoSidedEmission = getBoolAttr("mtco_doubleSided", depFn, false); Corona::SharedPtr<Corona::IMaterial> mat = data.createMaterial(); Corona::IMaterialSet ms = Corona::IMaterialSet(mat); ms.visibility.direct = getBoolAttr("mtco_areaVisible", depFn, true); ms.visibility.reflect = getBoolAttr("mtco_visibleInReflection", depFn, true); ms.visibility.refract = getBoolAttr("mtco_visibleInRefraction", depFn, true); obj->instance->addMaterial(ms); } } }
void resize(L l, I s, I c) { // Assume resizing up if (l->c>=c) return; l->p=realloc(l->p, s*c); if (l->l+l->o > l->c) memcpy(LP(l)+s*l->c, LP(l), s*(l->l+l->o-l->c)); l->c=c; }
int main() { srand((unsigned)time(NULL)); string graph_address="graph_all.txt"; VGraph gv(graph_address);//Voting用的图 PGraph gp(graph_address);//LP用的图 VGraph gv_flow(graph_address); //Flow Voting用的图 vector<Voter*> flowL;//记录所有的流实例 vector<Voter*> voterL;//记录所有的投票者 vector<Voter*> candiL;//记录所有的候选者 int voting_choice=1; //收集每一轮投票的结果 vector<double> app_happiness, voting_happiness, network_happiness; vector<double> app_delay, voting_delay, network_delay; vector<double> app_te, voting_te, network_te; vector<double> app_load, voting_load, network_load; //记录当前时间 time_t tt = time(NULL);//这句返回的只是一个时间cuo tm* t= localtime(&tt); string s="result"; stringstream ss1; ss1<<t->tm_year+1900; s.append(ss1.str()); stringstream ss2; ss2<<t->tm_mon+1; s.append(ss2.str()); stringstream ss3; ss3<<t->tm_mday; s.append(ss3.str()); stringstream ss4; ss4<<t->tm_hour; s.append(ss4.str()); stringstream ss5; ss5<<t->tm_min; s.append(ss5.str()); s.append(".txt"); cout<<"current output file : "<<s<<endl; ofstream outfile(s);//最后一个case的结果 ofstream req_outfile("req_outfile.txt"); outfile<<graph_address<<"网络拓扑 caseN: "<<caseN<<endl; outfile<<"flow Range: "<<Begin_num<<"--"<<Maxflow+Begin_num-1<<endl<<endl; outfile<<"current output file : "<<s<<endl; vector<Req*> reqL; double table[M2C+1][N2C+1] = {0}; int ranking[N2C+1]={0};//记录一种排序的投票人数 double happiness_sum=0; for(int j=1;j<=Voternum;j++) ranking[j]=1;//每种投票结果有1个voter,如果为2就说明该方案有得到两个voter的票 Voter* net_lb = new Network_LB(Maxreq,1);// Maxreq是投票者id, 1 表示网络投票者 ranking[Voternum]=5;//给网络投票者更多的票数 //Maxreq+1是投票者id,2表示中立投票者 Voter* neutral_low = new Neutral(Maxreq+1, 2); // te = 胜者TE基础上+5% Voter* neutral_middle = new Neutral(Maxreq+2, 2); // te = 胜者TE基础上+10% Voter* neutral_high = new Neutral(Maxreq+3, 2); // te = 胜者TE基础上+20% //初次 修改neutral的te值 neutral_low->te = 0.3; neutral_middle->te = 0.4; neutral_high->te = 0.5; //******** Flow Voting Variables ******* vector<Voter*> flowL_flow;//记录Flow Voting所有的流实例 vector<Voter*> voterL_flow;//记录Flow Voting所有的投票者 vector<Voter*> candiL_flow;//记录Flow Voting所有的候选者 double table_flow[M2C+1][N2C+1] = {0}; int ranking_flow[N2C+1]={0};//记录一种排序的投票人数 double happiness_sum_flow=0; for(int j=1;j<=Maxreq;j++) ranking_flow[j]=1;//每种投票结果有1个voter,如果为2就说明该方案有得到两个voter的票 for(int i=0;i<caseN;i++) { cout<<endl<<"*************************"<<" case "<<i<<"*************************"<<endl; outfile<<endl<<"*************************"<<" case "<<i<<"*************************"<<endl; //初始化 for(int j=0;j<Voternum;j++) for(int k=0;k<Voternum+3;k++) { table[j][k]=0; table_flow[j][k]=0;//table_flow的有效数据范围是table的子集 } req_outfile<<"case "<<i<<endl; //以下程序时防止每个case都会创建的Req导致的内存泄露 vector<Req*>::iterator it,iend; iend=reqL.end(); for(it=reqL.begin();it!=iend;it++) delete(*it); //删除上一个case的流需求 reqL.clear(); gv.reqL.clear(); gv_flow.reqL.clear(); if(i==0){ for(int j=0;j<Maxreq;j++) { int a=0,b=0,c=0; while(1){ c = Begin_num + rand()%Maxflow; //if(c!=0) break; a = rand()%N; b = rand()%N; if(a!=b && c!=0) break; } //a=0;b=1;c=10; Req* r = new Req(j,a,b,c); reqL.push_back(r); gv.reqL.push_back(r); gv_flow.reqL.push_back(r); Voter* flow_now = new Flow(j,0,a,b,c); Voter* flow_now_flow = new Flow(j,0,a,b,c);//Flow Voting use flowL.push_back(flow_now); voterL.push_back(flow_now); candiL.push_back(flow_now); flowL_flow.push_back(flow_now_flow); voterL_flow.push_back(flow_now_flow); candiL_flow.push_back(flow_now_flow); req_outfile<<j<<" "<<a<<" "<<b<<" "<<c<<endl; } voterL.push_back(net_lb); candiL.push_back(net_lb); candiL.push_back(neutral_low); candiL.push_back(neutral_middle); candiL.push_back(neutral_high); } else{ for(int j=0;j<Maxreq;j++) { int a=0,b=0,c=0; while(1){ c = Begin_num + rand()%Maxflow; //if(c!=0) break; a = rand()%N; b = rand()%N; if(a!=b && c!=0) break; } //a=0;b=1;c=10; Req* r = new Req(j,a,b,c); reqL.push_back(r); gv.reqL.push_back(r); gv_flow.reqL.push_back(r); flowL[j]->modify(a,b,c); //candiL[j]->modify(a,b,c); flowL_flow[j]->modify(a,b,c); //candiL_flow[j]->modify(a,b,c); req_outfile<<j<<" "<<a<<" "<<b<<" "<<c<<endl; } net_lb->modify(0,0,0); neutral_low->modify(0,0,0); neutral_middle->modify(0,0,0); neutral_high->modify(0,0,0); } //cout<<"init completed"<<endl; //************************************** Flow Voting ************************************** //************************************** Flow Voting ************************************** //only flows' proposal can be voted for a winner //算最完美方案,所有的路都第一个走得到的方案 for(int j=0;j<Maxreq;j++) gv_flow.cost_best[j] = gv.dijkstra(reqL[j]->src,reqL[j]->dst,reqL[j]->flow,flowL_flow[0]->adj); //for(int j=0;j<Maxreq;j++) //cout<<"gv.cost_best "<<j<<" : "<<gv.cost_best[j]<<endl; //提方案 for(int j=0;j<candiL_flow.size();j++) candiL_flow[j]->propose(gv_flow); //cout<<"提出方案结束"<<endl; //评价方案 for(int j=0;j<voterL_flow.size();j++) voterL_flow[j]->evaluate(gv_flow,candiL_flow); //cout<<"评价方案结束"<<endl; //投票算法, 投票算法的输入是从1开始的,但是judge是从0开始的,所以需要调整一下 for(int j=0;j<voterL_flow.size();j++) for(int k=0;k<candiL_flow.size();k++) { //该操作在evaluate时候就惩罚----不用if(voterL[j]->judge[k]==0) table[j+1][k+1]=10000;//如果是0,说明流没有摆在网络中 table_flow[j+1][k+1]=voterL_flow[j]->judge[k]; } cout<<endl<<"voting uses "; int choice_flow=voting_choice;//选择一种投票算法 int winner_flow=0; Voting vv_flow(table_flow,ranking_flow,voterL_flow.size(),candiL_flow.size()); winner_flow=vv_flow.voting(choice_flow); winner_flow=winner_flow-1;//将结果还是按照从0开始编号 if (choice_flow == 1) cout << "schulze method : " << winner_flow << endl; else if (choice_flow == 2) cout << "comulative method: " << winner_flow << endl; else if (choice_flow == 3) cout << "copeland condorcet method: " << winner_flow << endl; else cout << "ranked pairs method: " << winner_flow << endl; // table show for(int i=1;i<=voterL_flow.size();i++) { cout<<"flow "; cout.setf(ios::right); cout.width(3); cout<<i-1<<" judge: "; for(int j=1;j<=candiL_flow.size();j++){ cout.setf(ios::left); cout.width(5); cout<<table_flow[i][j]<<" "; } cout<<endl; } cout<<endl; // file record of table show outfile<<endl; for(int i=1;i<=voterL_flow.size();i++) { outfile<<"flow "; outfile.setf(ios::right); outfile.width(3); outfile<<i-1<<" judge: "; for(int j=1;j<=candiL_flow.size();j++){ outfile.setf(ios::left); outfile.width(5); outfile<<table_flow[i][j]<<" "; } outfile<<endl; } outfile<<endl; //计算满意度 double happiness_flow=0;//一轮所有流的满意度和,越高越好,0<=满意度<=1 for(int j=1;j<=Maxreq;j++) happiness_flow += gv_flow.cost_best[j-1]/table_flow[j][winner_flow+1];//最好抉择评分/当前抉择评分 happiness_sum_flow += happiness_flow; //计算方案部署后当前总的cost,如果流没有被安排进网络,就增加惩罚cost //统计网络latency double latencyVoting_flow=0; latencyVoting_flow=judge_sum_function(gv_flow,candiL_flow,winner_flow); cout << "winner = "<<winner_flow<<endl; cout << "第" << i << "轮整体满意度: " << happiness_flow/Maxreq << endl; cout << "多轮满意度:" << happiness_sum_flow/ ((i+1)*Maxreq) << endl; cout << "多轮整体延时和: " << latencyVoting_flow << endl; double maxUtil_Voting_flow=0; double loadNUM_flow=0;//统计网络负载 for(int j=0;j<gv_flow.m;j++) { int src=gv_flow.incL[j]->src; int dst=gv_flow.incL[j]->dst; loadNUM_flow+=flowL_flow[winner_flow]->adj[src][dst]; double capacity=gv_flow.incL[j]->capacity; if(maxUtil_Voting_flow<(flowL_flow[winner_flow]->adj[src][dst]/capacity)) maxUtil_Voting_flow=flowL_flow[winner_flow]->adj[src][dst]/capacity; } cout<<"最大链路利用率: "<<maxUtil_Voting_flow<<endl; //文件记录 outfile<<"Case "<<i<<" Flow Voting Result"<<endl; outfile << "winner = "<<winner_flow<<endl; outfile << "第" << i << "轮整体满意度: " << happiness_flow/Maxreq << endl; outfile << "多轮满意度:" << happiness_sum_flow/ ((i+1)*Maxreq) << endl; outfile << "多轮整体延时和: " << latencyVoting_flow << endl; outfile <<"最大链路利用率: "<<maxUtil_Voting_flow<<endl; outfile <<"网络负载"<<loadNUM_flow<<endl; app_happiness.push_back(happiness_sum_flow/ ((i+1)*Maxreq)); app_delay.push_back(latencyVoting_flow); app_te.push_back(maxUtil_Voting_flow); app_load.push_back(loadNUM_flow); //胜利的方案部署 for(int j=0;j<candiL_flow.size();j++) candiL_flow[j]->end_implement(gv_flow,winner_flow,candiL_flow); cout<<endl; //************************************** End of Flow Voting ************************************** //************************************** End of Flow Voting ************************************** //@@@@@@@@@@@@@@@@ Voting @@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@ Voting @@@@@@@@@@@@@@@@@@@@@@ //算最完美方案,所有的路都第一个走得到的方案 for(int j=0;j<Maxreq;j++) gv.cost_best[j] = gv.dijkstra(reqL[j]->src,reqL[j]->dst,reqL[j]->flow,flowL[0]->adj); //for(int j=0;j<Maxreq;j++) //cout<<"gv.cost_best "<<j<<" : "<<gv.cost_best[j]<<endl; //提方案 for(int j=0;j<candiL.size();j++) candiL[j]->propose(gv); //cout<<"提出方案结束"<<endl; //评价方案 for(int j=0;j<voterL.size();j++) voterL[j]->evaluate(gv,candiL); //cout<<"评价方案结束"<<endl; //投票算法, 投票算法的输入是从1开始的,但是judge是从0开始的,所以需要调整一下 for(int j=0;j<voterL.size();j++) for(int k=0;k<candiL.size();k++) { //该操作在evaluate时候就惩罚----不用if(voterL[j]->judge[k]==0) table[j+1][k+1]=10000;//如果是0,说明流没有摆在网络中 table[j+1][k+1]=voterL[j]->judge[k]; } cout<<endl<<"voting uses "; int choice=voting_choice;//选择一种投票算法 int winner=0; Voting vv(table,ranking,voterL.size(),candiL.size()); winner=vv.voting(choice); winner=winner-1;//将结果还是按照从0开始编号 outfile<<endl<<"beat_record: "; for(int i=1;i<=candiL.size();i++) outfile<<vv.beat_record[i]<<" "; outfile<<endl; if (choice == 1) cout << "schulze method : " << winner << endl; else if (choice == 2) cout << "comulative method: " << winner << endl; else if (choice == 3) cout << "copeland condorcet method: " << winner << endl; else cout << "ranked pairs method: " << winner << endl; // table show for(int i=1;i<=voterL.size();i++) { cout<<"flow "; cout.setf(ios::right); cout.width(3); cout<<i-1<<" judge: "; for(int j=1;j<=candiL.size();j++){ cout.setf(ios::left); cout.width(5); cout<<table[i][j]<<" "; } cout<<endl; } cout<<endl; // file record of table show outfile<<endl; for(int i=1;i<=voterL.size();i++) { outfile<<"flow "; outfile.setf(ios::right); outfile.width(3); outfile<<i-1<<" judge: "; for(int j=1;j<=candiL.size();j++){ outfile.setf(ios::left); outfile.width(5); outfile<<table[i][j]<<" "; } outfile<<endl; } outfile<<endl; //计算满意度 double happiness=0;//一轮所有流的满意度和,越高越好,0<=满意度<=1 for(int j=1;j<=Maxreq;j++) happiness += gv.cost_best[j-1]/table[j][winner+1];//最好抉择评分/当前抉择评分 happiness_sum += happiness; //计算方案部署后当前总的cost,如果流没有被安排进网络,就增加惩罚cost //统计网络latency double latencyVoting=0; latencyVoting=judge_sum_function(gv,candiL,winner); cout << "winner = "<<winner<<endl; cout << "第" << i << "轮整体满意度: " << happiness/Maxreq << endl; cout << "多轮满意度:" << happiness_sum / ((i+1)*Maxreq) << endl; cout << "多轮整体延时和: " << latencyVoting << endl; double maxUtil_Voting=0; maxUtil_Voting=voterL[Maxreq]->judge[winner]; cout<<"最大链路利用率: "<<maxUtil_Voting<<endl; double loadNUM_voting=0; for(int j=0;j<gv.m;j++) { int src=gv.incL[j]->src; int dst=gv.incL[j]->dst; loadNUM_voting+=candiL[winner]->adj[src][dst]; } //文件记录 outfile<<"Case "<<i<<" Voting Result"<<endl; outfile << "winner = "<<winner<<endl; outfile << "第" << i << "轮整体满意度: " << happiness/Maxreq << endl; outfile << "多轮满意度:" << happiness_sum / ((i+1)*Maxreq) << endl; outfile << "多轮整体延时和: " << latencyVoting << endl; outfile <<"最大链路利用率: "<<maxUtil_Voting<<endl; outfile <<"网络负载"<<loadNUM_voting<<endl; voting_happiness.push_back(happiness_sum / ((i+1)*Maxreq)); voting_delay.push_back(latencyVoting); voting_te.push_back(maxUtil_Voting); voting_load.push_back(loadNUM_voting); //胜利的方案部署 for(int j=0;j<candiL.size();j++) candiL[j]->end_implement(gv,winner,candiL); //修改neutral的te值 neutral_low->te = maxUtil_Voting + 0.05; neutral_middle->te = maxUtil_Voting + 0.1; neutral_high->te = maxUtil_Voting + 0.2; cout<<endl; //@@@@@@@@@@@@@@@@@End of Voting@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@End of Voting@@@@@@@@@@@@@@@@@@@@@@@@@ //分段规划部分 cout<<endl<<" LP result "<<endl; //judge_LP记录单轮满意度总和,judge_sum_LP记录多轮满意度总和 double judge_LP=0; static double judge_sum_LP=0; //最优部署计算 for(int j=0;j<Maxreq;j++) gp.cost_best[j] =gp.dijkstra(reqL[j]->src,reqL[j]->dst,reqL[j]->flow); //线性规划部署 double result_LP=0;//TE结果 result_LP=LP(&gp,reqL); //计算满意度 if(result_LP==Inf)judge_LP=0; else { judge_LP=0; //for(int i=0;i<Maxreq;i++) //cout<<gp.cost_best[i]<<" "<<gp.cost_LP[i]<<endl; for(int j=0;j<Maxreq;j++) judge_LP += gp.cost_best[j]/gp.cost_LP[j]; } judge_sum_LP += judge_LP; cout<<"单轮满意度: "<<judge_LP/Maxreq<<endl; cout<<"多轮满意度: "<<judge_sum_LP/(Maxreq*(i+1))<<endl; double latency_LP=0; latency_LP=judge_sum_LP_function(gp); cout << "多轮整体延时和: " << latency_LP << endl; cout<<"最大链路利用率: "<<result_LP<<endl; double loadNUM_network=0; for(int j=0;j<gp.m;j++) { int src=gp.incL[j]->src; int dst=gp.incL[j]->dst; loadNUM_network+=gp.adj[src][dst]; } //文件记录 outfile<<"Case "<<i<<" LP Result"<<endl; outfile<<"单轮满意度: "<<judge_LP/Maxreq<<endl; outfile<<"多轮满意度: "<<judge_sum_LP/(Maxreq*(i+1))<<endl; outfile << "多轮整体延时和: " << latency_LP << endl; outfile<<"最大链路利用率: "<<result_LP<<endl; outfile <<"网络负载"<<loadNUM_network<<endl; network_happiness.push_back(judge_sum_LP/(Maxreq*(i+1))); network_delay.push_back(latency_LP); network_te.push_back(result_LP); network_load.push_back(loadNUM_network); /* cout<<"单轮最大剩余链路利用率: "<<result_LP<<endl; double maxUtil_LP=0; for(int j=0;j<gp.m;j++) { int src=gp.incL[j]->src; int dst=gp.incL[j]->dst; float capacity=gp.incL[j]->capacity; if(maxUtil_LP<(gp.adj[src][dst]/capacity)) maxUtil_LP=gp.adj[src][dst]/capacity; } */ /* if(i==(caseN-1)){ outfile << "LP result"<<endl; outfile<<"单轮满意度: "<<judge_LP/Maxreq<<endl; outfile<<"多轮满意度: "<<judge_sum_LP/(Maxreq*(i+1))<<endl; outfile<<"多轮整体代价和: "<<result_sum_LP<<endl; } */ }//一个case结束 //happiness results: 三行结果分别是app voting network的满意度 outfile<<endl; outfile<<"happiness results: app voting network"<<endl; for(int i=0;i<caseN;i++) { outfile<<app_happiness[i]<<","; } outfile<<endl; for(int i=0;i<caseN;i++) { outfile<<voting_happiness[i]<<","; } outfile<<endl; for(int i=0;i<caseN;i++) { outfile<<network_happiness[i]<<","; } //delay results outfile<<endl; outfile<<"delay results: app voting network"<<endl; for(int i=0;i<caseN;i++) { outfile<<app_delay[i]<<","; } outfile<<endl; for(int i=0;i<caseN;i++) { outfile<<voting_delay[i]<<","; } outfile<<endl; for(int i=0;i<caseN;i++) { outfile<<network_delay[i]<<","; } //te results outfile<<endl; outfile<<"te results: app voting network"<<endl; for(int i=0;i<caseN;i++) { outfile<<app_te[i]<<","; } outfile<<endl; for(int i=0;i<caseN;i++) { outfile<<voting_te[i]<<","; } outfile<<endl; for(int i=0;i<caseN;i++) { outfile<<network_te[i]<<","; } outfile<<endl; //load results outfile<<endl; outfile<<"load results: app voting network"<<endl; for(int i=0;i<caseN;i++) { outfile<<app_load[i]<<","; } outfile<<endl; for(int i=0;i<caseN;i++) { outfile<<voting_load[i]<<","; } outfile<<endl; for(int i=0;i<caseN;i++) { outfile<<network_load[i]<<","; } outfile<<endl; getchar(); return 0; }
int main() { srand((unsigned)time(NULL)); VGraph gv("graph_all.txt");//Voting用的图 PGraph gp("graph_all.txt");//LP用的图 ofstream outfile("result.txt");//最后一个case的输出结果 //ofstream req_outfile("d:\\github\\req_outfile.txt"); outfile<<"graph_all网络拓扑"<<endl; outfile<<"flow Range: "<<Begin_num<<"--"<<Maxflow+Begin_num-1<<endl; outfile<<"caseN = "<<caseN<<" Maxreq = "<<Maxreq<<endl; outfile<<"STARTUP = "<<STARTUP<<endl<<endl; vector<Flow*> flowL;//记录所有的流实例 double judge_LP=0,judge_sum_LP=0; vector<Req*> reqL; double table[M2C+1][N2C+1] = {0}; int ranking[N2C+1]={0};//记录一种排序的投票人数 double happiness_sum=0; for(int test=1;test<=1;test++) { outfile<<"test "<<test<<endl; //每个test的初始化操作 flowL.clear(); judge_LP=0; judge_sum_LP=0; reqL.clear(); happiness_sum=0; int links_size = gp.incL.size(); for(int j=0;j<links_size;j++) gp.adj[gp.incL[j]->src][gp.incL[j]->dst]=0; for(int j=0;j<M2C+1;j++) for(int jj=0;jj<N2C+1;jj++) table[j][jj]=0; for(int j=1;j<=Maxreq;j++) ranking[j]=1;//每种投票结果有1个voter,如果为2就说明该方案有得到两个voter的票 for(int i=0;i<caseN;i++) { cout<<endl<<"*************************"<<" case "<<i<<"*************************"<<endl; //初始化 for(int j=0;j<Maxreq;j++) for(int k=0;k<Maxreq;k++) table[j][k]=0; //req_outfile<<"case "<<i<<endl; reqL.clear(); gv.reqL.clear(); if(i==0){ for(int j=0;j<Maxreq;j++) { int a=0,b=0,c=0; while(1){ c = Begin_num + rand()%Maxflow; //if(c!=0) break; a = rand()%N; b = rand()%N; if(a!=b && c!=0) break; } //a=0;b=1;c=10; Req* r = new Req(j,a,b,c); reqL.push_back(r); gv.reqL.push_back(r); Flow* flow_now = new Flow(j,a,b,c); flowL.push_back(flow_now); //req_outfile<<j<<" "<<a<<" "<<b<<" "<<c<<endl; } } else{ for(int j=0;j<Maxreq;j++) { int a=0,b=0,c=0; while(1){ c = Begin_num + rand()%Maxflow; //if(c!=0) break; a = rand()%N; b = rand()%N; if(a!=b && c!=0) break; } //a=0;b=1;c=10; Req* r = new Req(j,a,b,c); reqL.push_back(r); gv.reqL.push_back(r); flowL[j]->flow_modify(a,b,c); //req_outfile<<j<<" "<<a<<" "<<b<<" "<<c<<endl; } } //@@@@@@@@@@@@@@@@ Voting @@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@ Voting @@@@@@@@@@@@@@@@@@@@@@ //算最完美方案,所有的路都第一个走得到的方案 for(int j=0;j<Maxreq;j++) gv.cost_best[j] = reqL[j]->flow * (gv.dijkstra(reqL[j]->src,reqL[j]->dst,reqL[j]->flow,flowL[0]->adj) - reqL[j]->flow); //for(int j=0;j<Maxreq;j++) //cout<<j<<" gv.cost_best[j]="<<gv.cost_best[j]<<endl; //提方案 for(int j=0;j<Maxreq;j++) flowL[j]->propose(gv,flowL); //评价方案 for(int j=0;j<Maxreq;j++) flowL[j]->evaluate(gv,flowL); //投票算法 for(int j=0;j<Maxreq;j++) for(int k=0;k<Maxreq;k++) { if(flowL[j]->judge[k]==0) table[j+1][k+1]=0;//如果是0,说明流没有摆在网络中 else table[j+1][k+1]=flowL[j]->judge[k]; } cout<<endl<<"voting uses "; int choice=1;//选择一种投票算法 int winner=0; Voting vv(table,ranking,Maxreq,Maxreq); winner=vv.voting(choice); if (choice == 1) cout << "schulze method : " << winner << endl; else if (choice == 2) cout << "comulative method: " << winner << endl; else if (choice == 3) cout << "copeland condorcet method: " << winner << endl; else cout << "ranked pairs method: " << winner << endl; /* // table show for(int i=1;i<=Maxreq;i++) { cout<<"flow "; cout.setf(ios::right); cout.width(3); cout<<i-1<<" judge: "; for(int j=1;j<=Maxreq;j++){ cout.setf(ios::left); cout.width(5); cout<<table[i][j]<<" "; } cout<<endl; } cout<<endl; */ //输出比best更好的结果 for(int i=1;i<=Maxreq;i++) { for(int j=1;j<=Maxreq;j++) { if(table[i][j]>gv.cost_best[i-1]) { cout<<"%%%%%%%%%%%%%%%%当前方案值比最优值还好error i:"<<i-1<<" j:"<<j-1<<endl; break; } } } //计算满意度 double happiness=0;//一轮所有流的满意度和,越高越好,0<=满意度<=1 for(int j=1;j<=Maxreq;j++) happiness += (double)table[j][winner]/gv.cost_best[j-1];//最好抉择评分/当前抉择评分 happiness_sum += happiness; //计算方案部署后当前总的cost,如果流没有被安排进网络,就增加惩罚cost //统计网络latency double latencyVoting=0; latencyVoting=judge_sum_function(gv,flowL,winner-1); for(int j=0;j<Maxreq;j++) if(table[j+1][winner]==10000) { cout<<"触发惩罚机制"<<endl; latencyVoting += Maxpath * reqL[j]->flow; } cout << "第" << i << "轮整体满意度: " << happiness/Maxreq << endl; cout << "多轮满意度:" << happiness_sum / ((i+1)*Maxreq) << endl; cout << "多轮整体延时和: " << latencyVoting << endl; //统计网络能耗 double energy_Voting=0; double maxUtil_Voting=0; for(int j=0;j<gp.m;j++) { int src=gv.incL[j]->src; int dst=gv.incL[j]->dst; double capacity=gv.incL[j]->capacity; if(maxUtil_Voting<((double)flowL[winner-1]->adj[src][dst]/capacity)) maxUtil_Voting=(double)flowL[winner-1]->adj[src][dst]/capacity; if(flowL[winner-1]->adj[src][dst]>0) energy_Voting += flowL[winner-1]->adj[src][dst] * flowL[winner-1]->adj[src][dst] + STARTUP; } cout<<"网络能耗:"<<energy_Voting<<endl; cout<<"最大链路利用率: "<<maxUtil_Voting<<endl; //voting结果输出到文件中 if(i == (caseN-1)) { outfile <<endl<<" Voting Result "<<endl; outfile << "第" << i << "轮整体满意度: " << happiness/Maxreq << endl; outfile << "多轮满意度:" << happiness_sum / ((i+1)*Maxreq) << endl; outfile << "多轮整体延时和: " << latencyVoting << endl; outfile << "网络能耗:" << energy_Voting <<endl; outfile << "最大链路利用率: "<<maxUtil_Voting<<endl; } //胜利的方案部署 for(int j=0;j<Maxreq;j++) { for(int k1=0;k1<N;k1++) for(int k2=0;k2<N;k2++) { //cout<<j<<" "<<k1<<" "<<k2<<endl; flowL[j]->adj[k1][k2]=flowL[winner-1]->adj[k1][k2]; } } cout<<endl; //@@@@@@@@@@@@@@@@@End of Voting@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@End of Voting@@@@@@@@@@@@@@@@@@@@@@@@@ //分段规划部分 cout<<endl<<" LP result "<<endl; //最优部署计算,cost_best代表的值和可用带宽有关 for(int j=0;j<Maxreq;j++) gp.cost_best[j] = reqL[j]->flow * (gp.dijkstra(reqL[j]->src,reqL[j]->dst,reqL[j]->flow) - reqL[j]->flow); //for(int j=0;j<Maxreq;j++) //cout<<"cost_best "<<"j"<<" :"<<gp.cost_best[j]<<endl; //线性规划部署 double result_LP=0; result_LP=LP(&gp,reqL); //计算满意度 if(result_LP==Inf)judge_LP=0; else { judge_LP=0; //for(int i=0;i<Maxreq;i++) //cout<<gp.cost_best[i]<<" "<<gp.cost_LP[i]<<endl; for(int j=0;j<Maxreq;j++) judge_LP += (double)gp.cost_LP[j]/gp.cost_best[j]; } judge_sum_LP += judge_LP; cout<<"单轮满意度: "<<judge_LP/Maxreq<<endl; cout<<"多轮满意度: "<<judge_sum_LP/(Maxreq*(i+1))<<endl; double latency_LP=0; latency_LP=judge_sum_LP_function(gp,flowL); cout << "多轮整体延时和: " << latency_LP << endl; cout<<"网络能耗: "<<result_LP<<endl; //统计网络最大链路利用率 double maxUtil_LP=0; for(int j=0;j<gp.m;j++) { int src=gp.incL[j]->src; int dst=gp.incL[j]->dst; float capacity=gp.incL[j]->capacity; if(maxUtil_LP<(gp.adj[src][dst]/capacity)) maxUtil_LP=gp.adj[src][dst]/capacity; } cout<<"最大链路利用率: "<<maxUtil_LP<<endl; //voting结果输出到文件中 if(i==(caseN-1)) { outfile <<endl<<" LP result "<<endl; outfile << "单轮满意度: "<<judge_LP/Maxreq<<endl; outfile << "多轮满意度: "<<judge_sum_LP/(Maxreq*(i+1))<<endl; outfile << "多轮整体延时和: " << latency_LP << endl; outfile << "网络能耗: "<<result_LP<<endl; outfile<<"最大链路利用率: "<<maxUtil_LP<<endl; } }//一个case结束 }//一个test结束 getchar(); return 0; }