int test_main(int , char* []) { typedef boost::variant<int, std::string> var_t; std_log(LOG_FILENAME_LINE,"[Test Case for recursive_comparison_test]"); var_t var1(3); var_t var2(5); var_t var3("goodbye"); var_t var4("hello"); assert_equality_comparable(var1, var1, var1); assert_equality_comparable(var_t(var1), var_t(var1), var_t(var1)); assert_equality_comparable(var1, var2, var3); assert_less_than_comparable(var1, var2, var3); assert_less_than_comparable(var2, var3, var4); std::vector<var_t> vec; vec.push_back( var3 ); vec.push_back( var2 ); vec.push_back( var4 ); vec.push_back( var1 ); std::sort(vec.begin(), vec.end()); std::string sort_result( print_range(vec.begin(), vec.end()) ); BOOST_CHECK( sort_result == "3 5 goodbye hello " ); #ifdef __SYMBIAN32__ testResultXml("variant_comparison_test"); close_log_file(); #endif return boost::exit_success; }
void FunctionCMP_NonIso_LocalNCPForm<T1, T2>::output(const NumLib::TimeStep &/*time*/) { //update data for output Ogs6FemData* femData = Ogs6FemData::getInstance(); this->_msh_id = this->_problem->getDiscreteSystem()->getMesh()->getID(); // set the new output // we have 2 primary variables OutputVariableInfo var1("MEAN_PRESSURE", _msh_id, OutputVariableInfo::Node, OutputVariableInfo::Real, 1, _P); femData->outController.setOutput(var1.name, var1); OutputVariableInfo var2("TOTAL_MASS_DENSITY", _msh_id, OutputVariableInfo::Node, OutputVariableInfo::Real, 1, _X); femData->outController.setOutput(var2.name, var2); OutputVariableInfo var3("TEMPERATURE", _msh_id, OutputVariableInfo::Node, OutputVariableInfo::Real, 1, _T); femData->outController.setOutput(var3.name, var3); // and 8 secondary variables // add all seconary variables as well. //we have several secondary variables the values of which are defined on each elements OutputVariableInfo var_Sec_1("Saturation", _msh_id, OutputVariableInfo::Element, OutputVariableInfo::Real, 1, _S); femData->outController.setOutput(var_Sec_1.name, var_Sec_1); OutputVariableInfo var_Sec_3("Gas_Pressure", _msh_id, OutputVariableInfo::Element, OutputVariableInfo::Real, 1, _PG); femData->outController.setOutput(var_Sec_3.name, var_Sec_3); OutputVariableInfo var_Sec_4("Capillary_Pressure", _msh_id, OutputVariableInfo::Element, OutputVariableInfo::Real, 1, _PC); femData->outController.setOutput(var_Sec_4.name, var_Sec_4); OutputVariableInfo var_Sec_6("Mass_Density_G_H", _msh_id, OutputVariableInfo::Element, OutputVariableInfo::Real, 1, _rho_G_h); femData->outController.setOutput(var_Sec_6.name, var_Sec_6); OutputVariableInfo var_Sec_7("Mass_Density_G_W", _msh_id, OutputVariableInfo::Element, OutputVariableInfo::Real, 1, _rho_G_w); femData->outController.setOutput(var_Sec_7.name, var_Sec_7); }
TEST_F(VarRenamerTests, ClashingNamesEndingWithNumberAreSuffixedWithUnderscores) { // Set-up the module. // // int a; // int b; // int c; // // void test() { // } // ShPtr<Variable> varA(Variable::create("a", IntType::create(32))); module->addGlobalVar(varA); ShPtr<Variable> varB(Variable::create("b", IntType::create(32))); module->addGlobalVar(varB); ShPtr<Variable> varC(Variable::create("c", IntType::create(32))); module->addGlobalVar(varC); // Setup the name generator so it always returns "g1". INSTANTIATE_VAR_NAME_GEN_AND_VAR_RENAMER(VarRenamerWithCreate, false); EXPECT_CALL(*varNameGenMock, getNextVarName()) .Times(3) .WillOnce(Return("g1")) .WillOnce(Return("g1")) .WillOnce(Return("g1")); // Do the renaming. varRenamer->renameVars(module); // We expect the following output: // // int g1; // int g1_; // int g1__; // // void test() { // } // VarSet globalVarsSet(module->getGlobalVars()); ASSERT_EQ(3, globalVarsSet.size()); // We have to sort the variables to ease the checking. VarVector globalVarsVector(globalVarsSet.begin(), globalVarsSet.end()); sortByName(globalVarsVector); ShPtr<Variable> var1(globalVarsVector[0]); EXPECT_EQ("g1", var1->getName()); ShPtr<Variable> var2(globalVarsVector[1]); EXPECT_EQ("g1_", var2->getName()); ShPtr<Variable> var3(globalVarsVector[2]); EXPECT_EQ("g1__", var3->getName()); }
void LyricDisplay::Update( float fDeltaTime ) { ActorFrame::Update( fDeltaTime ); if( GAMESTATE->m_pCurSong == NULL ) return; /* If the song has changed (in a course), reset. */ if( GAMESTATE->m_fMusicSeconds < m_fLastSecond ) Init(); m_fLastSecond = GAMESTATE->m_fMusicSeconds; if( m_iCurLyricNumber >= GAMESTATE->m_pCurSong->m_LyricSegments.size() ) return; const Song *pSong = GAMESTATE->m_pCurSong; const float fStartTime = (pSong->m_LyricSegments[m_iCurLyricNumber].m_fStartTime) - IN_LENGTH.GetValue(); if( GAMESTATE->m_fMusicSeconds < fStartTime ) return; /* Clamp this lyric to the beginning of the next or the end of the music. */ float fEndTime; if( m_iCurLyricNumber+1 < GAMESTATE->m_pCurSong->m_LyricSegments.size() ) fEndTime = pSong->m_LyricSegments[m_iCurLyricNumber+1].m_fStartTime; else fEndTime = pSong->GetElapsedTimeFromBeat( pSong->m_fLastBeat ); const float fDistance = fEndTime - pSong->m_LyricSegments[m_iCurLyricNumber].m_fStartTime; const float fTweenBufferTime = IN_LENGTH.GetValue() + OUT_LENGTH.GetValue(); /* If it's negative, two lyrics are so close together that there's no time * to tween properly. Lyrics should never be this brief, anyway, so just * skip it. */ float fShowLength = max( fDistance - fTweenBufferTime, 0.0f ); // Make lyrics show faster for faster song rates. fShowLength /= GAMESTATE->m_SongOptions.GetCurrent().m_fMusicRate; const LyricSegment &seg = GAMESTATE->m_pCurSong->m_LyricSegments[m_iCurLyricNumber]; LuaThreadVariable var1( "LyricText", seg.m_sLyric ); LuaThreadVariable var2( "LyricDuration", LuaReference::Create(fShowLength) ); LuaThreadVariable var3( "LyricColor", LuaReference::Create(seg.m_Color) ); PlayCommand( "Changed" ); m_iCurLyricNumber++; }
TEST_F(UnifiedVarRenamerTests, GlobalVariablesGetCorrectlyRenamed) { // Set-up the module. // // int a; // int b; // int c; // // void test() { // } // ShPtr<Variable> varA(Variable::create("a", IntType::create(32))); module->addGlobalVar(varA); ShPtr<Variable> varB(Variable::create("b", IntType::create(32))); module->addGlobalVar(varB); ShPtr<Variable> varC(Variable::create("c", IntType::create(32))); module->addGlobalVar(varC); // Setup the renamer. INSTANTIATE_VAR_NAME_GEN_AND_VAR_RENAMER(UnifiedVarRenamer, true); // Do the renaming. varRenamer->renameVars(module); // We expect the following output: // // int g1; // int g2; // int g3; // // void test() { // } // VarSet globalVarsSet(module->getGlobalVars()); ASSERT_EQ(3, globalVarsSet.size()); // We have to sort the variables to ease the checking. VarVector globalVarsVector(globalVarsSet.begin(), globalVarsSet.end()); sortByName(globalVarsVector); ShPtr<Variable> var1(globalVarsVector[0]); EXPECT_EQ("g1", var1->getName()); ShPtr<Variable> var2(globalVarsVector[1]); EXPECT_EQ("g2", var2->getName()); ShPtr<Variable> var3(globalVarsVector[2]); EXPECT_EQ("g3", var3->getName()); }
bool FunctionCMP_NonIsoTotalMassEXPForm<T1, T2>::initialize(const BaseLib::Options &option) { Ogs6FemData* femData = Ogs6FemData::getInstance(); _msh_id = option.getOptionAsNum<size_t>("MeshID"); size_t time_id = option.getOptionAsNum<int>("TimeGroupID"); NumLib::ITimeStepFunction* tim = femData->list_tim[time_id]; //mesh and FE objects MeshLib::IMesh* msh = femData->list_mesh[_msh_id]; // get the number of elements size_t n_ele = msh->getNumberOfElements(); size_t n_nodes = msh->getNumberOfNodes(); MyDiscreteSystem* dis = 0; dis = DiscreteLib::DiscreteSystemContainerPerMesh::getInstance()->createObject<MyDiscreteSystem>(msh); _feObjects = new FemLib::LagrangeFeObjectContainer(msh); // set names of the output parameters this->setOutputParameterName(0, "MEAN_PRESSURE"); this->setOutputParameterName(1, "TOTAL_MASS_DENSITY"); this->setOutputParameterName(2, "TEMPERATURE"); this->setOutputParameterName(3, "Saturation"); this->setOutputParameterName(4, "Liquid_Pressure"); this->setOutputParameterName(5, "Gas_Pressure"); this->setOutputParameterName(6, "Capillary_Pressure"); this->setOutputParameterName(7, "Mass_Density_L_H"); this->setOutputParameterName(8, "Mass_Density_G_H"); this->setOutputParameterName(9, "Mass_Density_G_W"); // also secondary variables // TODO: set seconary variable names also as output parameters // create the MyCMPPressureForm problem _problem = new MyCMPNonIsoTotalMassEXPFormProblemType(dis); _problem->setTimeSteppingFunction(*tim); // applying the time stepping function // creating mean pressure vector MyVariableCMPNonIsoTotalMassEXPForm* mean_pressure = _problem->addVariable("MEAN_PRESSURE"); FemVariableBuilder var_builder; var_builder.doit("MEAN_PRESSURE", option, msh, femData->geo, femData->geo_unique_name, _feObjects, mean_pressure); SolutionLib::FemIC* femIC = _problem->getVariable(0)->getIC(); _P = new MyNodalFunctionScalar(); if (femIC) { // FemIC vector is not empty _P->initialize(*dis, _problem->getVariable(0)->getCurrentOrder(), 0.0); femIC->setup(*_P); } else { // FemIC vector is empty // initialize the vector with zeros _P->initialize(*dis, _problem->getVariable(0)->getCurrentOrder(), 0.0); } // creating molar fraction MyVariableCMPNonIsoTotalMassEXPForm* total_mass_density = _problem->addVariable("TOTAL_MASS_DENSITY"); var_builder.doit("TOTAL_MASS_DENSITY", option, msh, femData->geo, femData->geo_unique_name, _feObjects, total_mass_density); femIC = _problem->getVariable(1)->getIC(); _X = new MyNodalFunctionScalar(); if (femIC) { // FemIC vector is not empty _X->initialize(*dis, _problem->getVariable(1)->getCurrentOrder(), 0.0); femIC->setup(*_X); } else { // FemIC vector is empty // initialize the vector with zeros _X->initialize(*dis, _problem->getVariable(1)->getCurrentOrder(), 0.0); } MyVariableCMPNonIsoTotalMassEXPForm* temperature = _problem->addVariable("TEMPERATURE"); var_builder.doit("TEMPERATURE", option, msh, femData->geo, femData->geo_unique_name, _feObjects, temperature); femIC = _problem->getVariable(2)->getIC(); _T = new MyNodalFunctionScalar(); if (femIC) { // FemIC vector is not empty _T->initialize(*dis, _problem->getVariable(2)->getCurrentOrder(), 0.0); femIC->setup(*_T); } else { // FemIC vector is empty // initialize the vector with zeros _T->initialize(*dis, _problem->getVariable(2)->getCurrentOrder(), 0.0); } // initialize the local EOS problem //_LP_EOS = new LocalProblem_EOS_TotalMassEXPForm(); //ogsChem::LocalVector _output1; //_output1 = ogsChem::LocalVector::Zero(_LP_EOS->N); _S = new MyIntegrationPointFunctionVector(); _S->initialize(dis); _PL = new MyIntegrationPointFunctionVector(); _PL->initialize(dis); _PG = new MyIntegrationPointFunctionVector(); _PG->initialize(dis); _PC = new MyIntegrationPointFunctionVector(); _PC->initialize(dis); _rho_L_h = new MyIntegrationPointFunctionVector(); _rho_L_h->initialize(dis); _rho_G_h = new MyIntegrationPointFunctionVector(); _rho_G_h->initialize(dis); _rho_G_w = new MyIntegrationPointFunctionVector(); _rho_G_w->initialize(dis); MathLib::LocalVector tmp = MathLib::LocalVector::Zero(1); for (size_t ele_id = 0; ele_id < n_ele; ele_id++) { MeshLib::IElement *e = msh->getElement(ele_id); const std::size_t node_ele = e->getNumberOfNodes();// _S->setNumberOfIntegationPoints(ele_id, node_ele); _PL->setNumberOfIntegationPoints(ele_id, node_ele); _PC->setNumberOfIntegationPoints(ele_id, node_ele); _rho_G_h->setNumberOfIntegationPoints(ele_id, node_ele); _rho_G_w->setNumberOfIntegationPoints(ele_id, node_ele); for (size_t jj = 0; jj < node_ele; jj++) { _S->setIntegrationPointValue(ele_id, jj, tmp); _PL->setIntegrationPointValue(ele_id, jj, tmp); _PC->setIntegrationPointValue(ele_id, jj, tmp); _rho_G_h->setIntegrationPointValue(ele_id, jj, tmp); _rho_G_w->setIntegrationPointValue(ele_id, jj, tmp); } } _mat_secDer = new MyNodalFunctionMatrix();// define a matrix to store all the derivatives of the secondary variables MathLib::LocalMatrix tmp_mat = MathLib::LocalMatrix::Zero(3, 2); //the size I will modify later _mat_secDer->initialize(*dis, FemLib::PolynomialOrder::Linear, tmp_mat); /** * initialize the vector of tempVar */ _vec_tempVar = new MyNodalFunctionVector(); MathLib::LocalVector tmp_vec = MathLib::LocalVector::Zero(2); _vec_tempVar->initialize(*dis, FemLib::PolynomialOrder::Linear, tmp_vec); //initialize the local M matrix and K matrix for (size_t index = 0; index < n_ele; index++) { MathLib::LocalMatrix test1 = MathLib::LocalMatrix::Zero(6, 6); _elem_M_matrix.push_back(test1); MathLib::LocalMatrix test2 = MathLib::LocalMatrix::Zero(6, 6); _elem_K_matrix.push_back(test2); } // linear assemblers MyNonLinearAssemblerType* nonlin_assembler = new MyNonLinearAssemblerType(_feObjects, this, msh->getGeometricProperty()->getCoordinateSystem()); MyNonLinearResidualAssemblerType* non_linear_r_assembler = new MyNonLinearResidualAssemblerType(_feObjects, this, msh->getGeometricProperty()->getCoordinateSystem()); MyNonLinearJacobianAssemblerType* non_linear_j_assembler = new MyNonLinearJacobianAssemblerType(_feObjects, this, msh->getGeometricProperty()->getCoordinateSystem()); // define nonlinear problem _non_linear_problem = new MyNonLinearCMPNonIsoTotalMassEXPFormProblemType(dis); _non_linear_eqs = _non_linear_problem->createEquation(); _non_linear_eqs->initialize(nonlin_assembler, non_linear_r_assembler, non_linear_j_assembler); _non_linear_problem->setTimeSteppingFunction(*tim); _non_linear_problem->addVariable("MEAN_PRESSURE"); _non_linear_problem->addVariable("TOTAL_MASS_DENSITY"); _non_linear_problem->addVariable("TEMPERATURE"); SolutionLib::FemIC* P_ic = new SolutionLib::FemIC(msh); P_ic->addDistribution(femData->geo->getDomainObj(), new NumLib::TXFunctionDirect<double>(_P->getDiscreteData())); var_builder.doit("MEAN_PRESSURE", option, msh, femData->geo, femData->geo_unique_name, _feObjects, _non_linear_problem->getVariable(0)); _non_linear_problem->getVariable(0)->setIC(P_ic); SolutionLib::FemIC* X_ic = new SolutionLib::FemIC(msh); X_ic->addDistribution(femData->geo->getDomainObj(), new NumLib::TXFunctionDirect<double>(_X->getDiscreteData())); var_builder.doit("TOTAL_MASS_DENSITY", option, msh, femData->geo, femData->geo_unique_name, _feObjects, _non_linear_problem->getVariable(1)); _non_linear_problem->getVariable(1)->setIC(X_ic); SolutionLib::FemIC* T_ic = new SolutionLib::FemIC(msh); T_ic->addDistribution(femData->geo->getDomainObj(), new NumLib::TXFunctionDirect<double>(_T->getDiscreteData())); var_builder.doit("TEMPERATURE", option, msh, femData->geo, femData->geo_unique_name, _feObjects, _non_linear_problem->getVariable(2)); _non_linear_problem->getVariable(2)->setIC(T_ic); // set up non-linear solution myNRIterator = new MyNRIterationStepInitializer(non_linear_r_assembler, non_linear_j_assembler); myNSolverFactory = new MyDiscreteNonlinearSolverFactory(myNRIterator); this->_non_linear_solution = new MyNonLinearSolutionType(dis, this->_non_linear_problem, myNSolverFactory); this->_non_linear_solution->getDofEquationIdTable()->setNumberingType(DiscreteLib::DofNumberingType::BY_POINT); // global order this->_non_linear_solution->getDofEquationIdTable()->setLocalNumberingType(DiscreteLib::DofNumberingType::BY_VARIABLE); // local order const BaseLib::Options* optNum = option.getSubGroup("Numerics"); // linear solver MyLinearSolver* linear_solver = this->_non_linear_solution->getLinearEquationSolver(); linear_solver->setOption(*optNum); // set nonlinear solver options this->_non_linear_solution->getNonlinearSolver()->setOption(*optNum); // set theta if (!optNum->hasOption("TimeTheta")) { ERR("Time theta setting not found!!!"); exit(1); } else { double tmp_theta(optNum->getOptionAsNum<double>("TimeTheta")); non_linear_j_assembler->setTheta(tmp_theta); non_linear_r_assembler->setTheta(tmp_theta); _non_linear_eqs->getLinearAssembler()->setTheta(tmp_theta); } // get the nonlinear solution dof manager this->_nl_sol_dofManager = this->_non_linear_solution->getDofEquationIdTable(); // set up solution _solution = new MyCMPNonIsoTotalMassEXPFormSolution(dis, _problem, _non_linear_solution, this); /** *Calculate the secondary variables on each node */ this->calc_nodal_eos_sys(0.0); // set initial output parameter OutputVariableInfo var1(this->getOutputParameterName(0), _msh_id, OutputVariableInfo::Node, OutputVariableInfo::Real, 1, _P); femData->outController.setOutput(var1.name, var1); OutputVariableInfo var2(this->getOutputParameterName(1), _msh_id, OutputVariableInfo::Node, OutputVariableInfo::Real, 1, _X); femData->outController.setOutput(var2.name, var2); OutputVariableInfo var3(this->getOutputParameterName(2), _msh_id, OutputVariableInfo::Node, OutputVariableInfo::Real, 1, _T); femData->outController.setOutput(var3.name, var3); // OutputVariableInfo var_Sec_1(this->getOutputParameterName(3), _msh_id, OutputVariableInfo::Element, OutputVariableInfo::Real, 1, _S); femData->outController.setOutput(var_Sec_1.name, var_Sec_1); OutputVariableInfo var_Sec_2(this->getOutputParameterName(4), _msh_id, OutputVariableInfo::Element, OutputVariableInfo::Real, 1, _PL); femData->outController.setOutput(var_Sec_2.name, var_Sec_2); OutputVariableInfo var_Sec_3(this->getOutputParameterName(5), _msh_id, OutputVariableInfo::Element, OutputVariableInfo::Real, 1, _PG); femData->outController.setOutput(var_Sec_3.name, var_Sec_3); OutputVariableInfo var_Sec_4(this->getOutputParameterName(6), _msh_id, OutputVariableInfo::Element, OutputVariableInfo::Real, 1, _PC); femData->outController.setOutput(var_Sec_4.name, var_Sec_4); OutputVariableInfo var_Sec_5(this->getOutputParameterName(7), _msh_id, OutputVariableInfo::Element, OutputVariableInfo::Real, 1, _rho_L_h); femData->outController.setOutput(var_Sec_5.name, var_Sec_5); OutputVariableInfo var_Sec_6(this->getOutputParameterName(8), _msh_id, OutputVariableInfo::Element, OutputVariableInfo::Real, 1, _rho_G_h); femData->outController.setOutput(var_Sec_6.name, var_Sec_6); OutputVariableInfo var_Sec_7(this->getOutputParameterName(9), _msh_id, OutputVariableInfo::Element, OutputVariableInfo::Real, 1, _rho_G_w); femData->outController.setOutput(var_Sec_7.name, var_Sec_7); return true; }
int main (int argc, char *argv[]) { ifstream infile; infile.open("Proj3_op.txt"); if(!infile){ cerr << "Unable to open the file\n"; exit(1); } cout << "Before Everything!!!" << "\n"; IloEnv env; IloInt i,j,varCount1,varCount2,varCount3,conCount; //same as “int i;” IloInt k,w,K,W,E,l,P,N,L; IloInt tab, newline, val; //from file char line[2048]; try { N = 9; K = 3; L = 36; W = (IloInt)atoi(argv[1]); IloModel model(env); //set up a model object IloNumVarArray var1(env);// C - primary cout << "Here\n"; IloNumVarArray var2(env);// B - backup cout << "here1\n"; IloNumVarArray var3(env);// = IloNumVarArray(env,W); //declare an array of variable objects, for unknowns IloNumVar W_max(env, 0, W, ILOINT); //var1: c_ijk_w IloRangeArray con(env);// = IloRangeArray(env,N*N + 3*w); //declare an array of constraint objects IloNumArray2 t = IloNumArray2(env,N); //Traffic Demand IloNumArray2 e = IloNumArray2(env,N); //edge matrix //IloObjective obj; //Define the Xijk matrix cout << "Before init xijkl\n"; Xijkl xijkl_m(env, L); for(l=0;l<L;l++){ xijkl_m[l] = Xijk(env, N); for(i=0;i<N;i++){ xijkl_m[l][i] = Xjk(env, N); for(j=0;j<N;j++){ xijkl_m[l][i][j] = IloNumArray(env, K); } } } //reset everything to zero here for(l=0;l<L;l++) for(i=0;i<N;i++) for(j=0;j<N;j++) for(k=0;k<K;k++) xijkl_m[l][i][j][k] = 0; input_Xijkl(xijkl_m); cout<<"bahre\n"; for(i=0;i<N;i++){ t[i] = IloNumArray(env,N); for(j=0;j<N;j++){ if(i == j) t[i][j] = IloNum(0); else if(i != j) t[i][j] = IloNum((i+j+2)%5); } } printf("ikde\n"); //Minimize W_max IloObjective obj=IloMinimize(env); obj.setLinearCoef(W_max, 1.0); cout << "here khali\n"; //Setting var1[] for Demands Constraints for(i=0;i<N;i++) for(j=0;j<N;j++) for(k=0;k<K;k++) for(w=0;w<W;w++) var1.add(IloNumVar(env, 0, 1, ILOINT)); //c_ijk_w variables set. //Setting var2[] for Demands Constraints for(i=0;i<N;i++) for(j=0;j<N;j++) for(k=0;k<K;k++) for(w=0;w<W;w++) var2.add(IloNumVar(env, 0, 1, ILOINT)); //b_ijk_w variables set. for(w = 0;w < W;w++) var3.add(IloNumVar(env, 0, 1, ILOINT)); //Variables for u_w cout<<"variables ready\n"; conCount = 0; for(i=0;i<N;i++) for(j=0;j<N;j++){ con.add(IloRange(env, 2 * t[i][j], 2 * t[i][j])); //varCount1 = 0; for(k=0;k<K;k++) for(w=0;w<W;w++){ con[conCount].setLinearCoef(var1[i*N*W*K+j*W*K+k*W+w],1.0); con[conCount].setLinearCoef(var2[i*N*W*K+j*W*K+k*W+w],1.0); } conCount++; }//Adding Demands Constraints to con cout<<"1st\n"; IloInt z= 0; for(w=0;w<W;w++){ for(l=0;l<L;l++){ con.add(IloRange(env, -IloInfinity, 1)); for(i=0;i<N;i++){ for(j=0;j<N;j++){ for(k=0;k<K;k++){ con[conCount].setLinearCoef(var1[i*N*W*K+j*W*K+k*W+w],xijkl_m[l][i][j][k]); con[conCount].setLinearCoef(var2[i*N*W*K+j*W*K+k*W+w],xijkl_m[l][i][j][k]); } } } conCount++; } } cout<<"2nd\n"; //Adding Wavelength Constraints_1 to con P = N * (N-1) * K; for(w=0;w<W;w++){ con.add(IloRange(env, -IloInfinity, 0)); varCount1 = 0; for(i=0;i<N;i++) for(j=0;j<N;j++) for(k=0;k<K;k++){ con[conCount].setLinearCoef(var1[i*N*W*K+j*W*K+k*W+w],1.0); con[conCount].setLinearCoef(var2[i*N*W*K+j*W*K+k*W+w],1.0); } con[conCount].setLinearCoef(var3[w],-P); conCount++; } cout<<"3rd\n"; for(i=0;i<N;i++) for(j=0;j<N;j++) for(k=0;k<K;k++) for(w=0;w<W;w++){ con.add(IloRange(env, -IloInfinity, 1)); con[conCount].setLinearCoef(var1[i*N*W*K+j*W*K+k*W+w], 1.0); con[conCount++].setLinearCoef(var2[i*N*W*K+j*W*K+k*W+w], 1.0); } varCount3 = 0; for(w=0;w<W;w++){ con.add(IloRange(env, 0, IloInfinity)); con[conCount].setLinearCoef(W_max, 1.0); con[conCount++].setLinearCoef(var3[w], -1.0 * (w+1)); } cout<<"after constraints\n"; //model.add(obj); //add objective function into model model.add(IloMinimize(env,obj)); model.add(con); //add constraints into model IloCplex cplex(model); //create a cplex object and extract the //model to this cplex object // Optimize the problem and obtain solution. if ( !cplex.solve() ) { env.error() << "Failed to optimize LP" << endl; throw(-1); } IloNumArray vals(env); //declare an array to store the outputs //if 2 dimensional: IloNumArray2 vals(env); env.out() << "Solution status = " << cplex.getStatus() << endl; //return the status: Feasible/Optimal/Infeasible/Unbounded/Error/… env.out() << "Solution value = " << cplex.getObjValue() << endl; //return the optimal value for objective function cplex.getValues(vals, var1); //get the variable outputs env.out() << "Values Var1 = " << vals << endl; //env.out() : output stream cplex.getValues(vals, var3); env.out() << "Values Val3 = " << vals << endl; } catch (IloException& e) { cerr << "Concert exception caught: " << e << endl; } catch (...) { cerr << "Unknown exception caught" << endl; } env.end(); //close the CPLEX environment return 0; } // END main
int main (int argc, char *argv[]) { ifstream infile; clock_t start_time, end_time; infile.open("Proj3_op.txt"); if(!infile){ cerr << "Unable to open the file\n"; exit(1); } cout << "Before Everything!!!" << "\n"; IloEnv env; IloInt i,j,varCount1,varCount2,varCount3,conCount; //same as “int i;” IloInt k,w,K,W,E,l,P,N,L; IloInt tab, newline, val; //from file char line[2048]; try { N = 9; K = 2; L = 36; W = (IloInt)atoi(argv[1]); IloModel model(env); //set up a model object IloNumVarArray var1(env);// = IloNumVarArray(env,K*W*N*N); IloNumVarArray var3(env);// = IloNumVarArray(env,W); //declare an array of variable objects, for unknowns IloNumVar W_max(env, 0, W, ILOINT); IloRangeArray con(env);// = IloRangeArray(env,N*N + 3*w); //declare an array of constraint objects IloNumArray2 t = IloNumArray2(env,N); //Traffic Demand IloNumArray2 e = IloNumArray2(env,N); //edge matrix //IloObjective obj; //Define the Xijk matrix Xijkl xijkl_m(env, L); for(l=0;l<L;l++){ xijkl_m[l] = Xijk(env, N); for(i=0;i<N;i++){ xijkl_m[l][i] = Xjk(env, N); for(j=0;j<N;j++){ xijkl_m[l][i][j] = IloNumArray(env, K); } } } //reset everything to zero here for(l=0;l<L;l++) for(i=0;i<N;i++) for(j=0;j<N;j++) for(k=0;k<K;k++) xijkl_m[l][i][j][k] = 0; input_Xijkl(xijkl_m); cout<<"bahre\n"; FILE *file; file = fopen(argv[2],"r"); int tj[10]; for(i=0;i<N;i++){ t[i] = IloNumArray(env,N); fscanf(file,"%d %d %d %d %d %d %d %d %d \n",&tj[0],&tj[1],&tj[2],&tj[3],&tj[4],&tj[5],&tj[6],&tj[7],&tj[8]); for(j=0;j<N;j++){ t[i][j] = IloNum(tj[j]); } } printf("ikde\n"); //Minimize W_max IloObjective obj=IloMinimize(env); obj.setLinearCoef(W_max, 1.0); cout << "here khali\n"; //Setting var1[] for Demands Constraints for(i=0;i<N;i++) for(j=0;j<N;j++) for(k=0;k<K;k++) for(w=0;w<W;w++) var1.add(IloNumVar(env, 0, 1, ILOINT)); for(w = 0;w < W;w++) var3.add(IloNumVar(env, 0, 1, ILOINT)); //Variables for u_w cout<<"variables ready\n"; conCount = 0; for(i=0;i<N;i++) for(j=0;j<N;j++){ con.add(IloRange(env, t[i][j], t[i][j])); //varCount1 = 0; for(k=0;k<K;k++) for(w=0;w<W;w++){ con[conCount].setLinearCoef(var1[i*N*W*K+j*W*K+k*W+w],1.0); //cout << "Before Adding Constraint\n"; //con[1].setLinearCoef(IloNumVar(env, 0, 1, ILOINT), 1.0); //cout<<"coef set "<<varCount1; } conCount++; }//Adding Demands Constraints to con cout<<"1st\n"; IloInt z= 0; for(w=0;w<W;w++){ for(l=0;l<L;l++){ con.add(IloRange(env, -IloInfinity, 1)); for(i=0;i<N;i++){ for(j=0;j<N;j++){ for(k=0;k<K;k++){ con[conCount].setLinearCoef(var1[i*N*W*K+j*W*K+k*W+w],xijkl_m[l][i][j][k]); } } } conCount++; } } cout<<"2nd\n"; //Adding Wavelength Constraints_1 to con P = N * (N-1) * K; for(w=0;w<W;w++){ con.add(IloRange(env, -IloInfinity, 0)); varCount1 = 0; for(i=0;i<9;i++) for(j=0;j<9;j++) for(k=0;k<K;k++){ con[conCount].setLinearCoef(var1[i*N*W*K+j*W*K+k*W+w],1.0); } con[conCount].setLinearCoef(var3[w],-P); conCount++; } cout<<"3rd\n"; varCount3 = 0; for(w=0;w<W;w++){ con.add(IloRange(env, 0, IloInfinity)); con[conCount].setLinearCoef(W_max, 1.0); con[conCount++].setLinearCoef(var3[w], -1.0 * (w+1)); } cout<<"after constraints\n"; //model.add(obj); //add objective function into model model.add(IloMinimize(env,obj)); model.add(con); //add constraints into model IloCplex cplex(model); //create a cplex object and extract the //model to this cplex object // Optimize the problem and obtain solution. start_time = clock(); if ( !cplex.solve() ) { env.error() << "Failed to optimize LP" << endl; throw(-1); } end_time = clock(); IloNumArray vals(env); //declare an array to store the outputs IloNumVarArray opvars(env); //if 2 dimensional: IloNumArray2 vals(env); //env.out() << "Solution status = " << cplex.getStatus() << endl; //return the status: Feasible/Optimal/Infeasible/Unbounded/Error/… env.out() << "W_max value = " << cplex.getObjValue() << endl; //return the optimal value for objective function cplex.getValues(vals, var1); //get the variable outputs //env.out() << "Values Var1 = " << vals << endl; //env.out() : output stream cplex.getValues(vals, var3); //env.out() << "Values Val3 = " << vals << endl; } catch (IloException& e) { cerr << "Concert exception caught: " << e << endl; } catch (...) { cerr << "Unknown exception caught" << endl; } env.end(); //close the CPLEX environment float running_time (((float)end_time - (float)start_time)/CLOCKS_PER_SEC); cout << "*******RUNNING TIME: " << running_time << endl; return 0; } // END main
void test_recursive_variant_over() { typedef boost::make_recursive_variant_over< boost::mpl::vector< int , std::vector<boost::recursive_variant_> > >::type var1_t; std::vector<var1_t> vec1; vec1.push_back(3); vec1.push_back(5); vec1.push_back(vec1); vec1.push_back(7); var1_t var1(vec1); std::string result1( boost::apply_visitor( vector_printer(), var1 ) ); std::cout << "result1: " << result1 << '\n'; BOOST_CHECK(result1 == "( 3 5 ( 3 5 ) 7 ) "); typedef boost::make_recursive_variant_over< boost::mpl::vector< boost::make_variant_over<boost::mpl::vector<int, double> >::type , std::vector<boost::recursive_variant_> > >::type var2_t; std::vector<var2_t> vec2; vec2.push_back(boost::variant<int, double>(3)); vec2.push_back(boost::variant<int, double>(3.5)); vec2.push_back(vec2); vec2.push_back(boost::variant<int, double>(7)); var2_t var2(vec2); std::string result2( boost::apply_visitor( vector_printer(), var2 ) ); std::cout << "result2: " << result2 << '\n'; BOOST_CHECK(result2 == "( 3 3.5 ( 3 3.5 ) 7 ) "); typedef boost::make_recursive_variant_over< boost::mpl::vector< int , std::vector< boost::make_variant_over< boost::mpl::vector< double , std::vector<boost::recursive_variant_> > >::type > > >::type var3_t; typedef boost::make_variant_over< boost::mpl::copy< boost::mpl::vector< double , std::vector<var3_t> > >::type >::type var4_t; std::vector<var3_t> vec3; vec3.push_back(3); vec3.push_back(5); std::vector<var4_t> vec4; vec4.push_back(3.5); vec4.push_back(vec3); vec3.push_back(vec4); vec3.push_back(7); var4_t var3(vec3); std::string result3( boost::apply_visitor( vector_printer(), var3 ) ); std::cout << "result2: " << result3 << '\n'; BOOST_CHECK(result3 == "( 3 5 ( 3.5 ( 3 5 ) ) 7 ) "); typedef boost::make_recursive_variant_over< boost::mpl::vector< double , std::vector<var1_t> > >::type var5_t; std::vector<var5_t> vec5; vec5.push_back(3.5); vec5.push_back(vec1); vec5.push_back(17.25); std::string result5( vector_printer()(vec5) ); std::cout << "result5: " << result5 << '\n'; BOOST_CHECK(result5 == "( 3.5 ( 3 5 ( 3 5 ) 7 ) 17.25 ) "); }