Virtual U.org
Get Personal Training on VU Today
    
Top shadow
 
 register/help
User Name:

Password:

Ofac_rs.cpp Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

Ofac_rs.cpp

Go to the documentation of this file.
00001 //Filename    : OFACULTY.cpp
00002 //Description : FACULTY Class Definition - Research!            // 990421
00003 
00004 #include <OMATH.H>
00005 //#include <OINFO.H>
00006 //#include <OPSCHOOL.H>         // trimester_array
00007 
00008 // game logic
00009 
00010 #include <OFACULTY.H>
00011 #include <OFINANCE.H>
00012 #include <ODEPT.H>
00013 #include <ODEPTRES.H>
00014 #include <OPEERSCH.H>
00015 #include <OSCHLRES.H>
00016 #include <OPSCHOOL.H>                             //## chea begin "special case" when spon.=none 070699 5.1.4
00017 
00018 static bool is_calc_ini_statistic;
00019 
00020 /*
00021 //---------- Begin of function Faculty::think_research -----------//
00025 void Faculty::think_research()
00026 {
00027   int i;
00028 
00029   //------------------------//
00030   if ( rank_level == LONG_TERM_ADJUNCT || rank_level == SHORT_TERM_ADJUNCT || ave_proj_size <=0 )
00031 return;
00032 
00033 //------------------------//
00034 
00035 // 990414
00036 
00037 float oRate = finance.get_research_overhead_rate() / 100.0f;
00038 float qualityDriver = this->get_quality_driver();
00039 this->award_prob =
00040 float (0.01 + 0.005 * math.dual_response_func(1,50,100,29,33,20,76, qualityDriver) * math.safe_pow(1.0f+oRate, -1.5f) );
00041 
00042 //------------------------//
00043 
00044 Department* deptPtr = department_array[department_recno];
00045 DepartmentInfo* deptInfo = department_res[deptPtr->department_id];
00046 FacultyTemplate* templ = faculty_res.get_faculty_template(deptInfo->template_discretionary_time, rank_age_group() );
00047 //      PeerSchool *playerSchool = school_res.player_peer_school;
00048 
00049 //------------------------//
00050 
00051 for (i=0; i<research_proposal_count; i++)
00052 {
00053 ResearchProposal* researchProposal = research_proposal_array+i;
00054 
00055 if ( researchProposal->status == RESEARCH_PROPOSED )
00056 {
00057 // 990412 if ( math.get_random_float() < researchProposal->prob_proposal_funded )
00058 if ( math.get_random_float() < award_prob )
00059 {
00060 // accepted
00061 researchProposal->status = RESEARCH_ACTIVE;
00062 researchProposal->date_to_next_status = info.game_date + (4 + m.random(MAX_ACTIVE_RESEARCH_MONTH-3)) * 30;              // draw a random number from 4 to 12 months
00063 
00064 research_month_expense += researchProposal->total_dollars / MAX_ACTIVE_RESEARCH_MONTH;
00065 research_month_expense_direct += int((researchProposal->total_dollars / MAX_ACTIVE_RESEARCH_MONTH ) / ( 1+researchProposal->overhead_rate));
00066 
00067 deptPtr->research_m_history[R_ACCEPT][THIS_MONTH] += (researchProposal->total_dollars / MAX_ACTIVE_RESEARCH_MONTH);
00068 }
00069 }
00070 else if ( researchProposal->status == RESEARCH_ACTIVE )
00071 {
00072 }
00073 else
00074 err_here();
00075 
00076 if ( info.game_date >= researchProposal->date_to_next_status )          // depends on game_date
00077 {
00078 // expired: proposal rejected or research finished
00079 
00080 if ( researchProposal->status == RESEARCH_PROPOSED )
00081 deptPtr->research_m_history[R_REJECT][THIS_MONTH] += (researchProposal->total_dollars / MAX_ACTIVE_RESEARCH_MONTH);
00082 else if ( researchProposal->status = RESEARCH_ACTIVE )
00083 {
00084 research_month_expense -= researchProposal->total_dollars / MAX_ACTIVE_RESEARCH_MONTH;
00085 research_month_expense_direct -= int((researchProposal->total_dollars / MAX_ACTIVE_RESEARCH_MONTH ) / ( 1+researchProposal->overhead_rate));
00086 }
00087 
00088 for (int j=i+1; j<research_proposal_count; j++)
00089 memcpy(research_proposal_array+j-1, research_proposal_array+j, sizeof(ResearchProposal));
00090 
00091 research_proposal_count--;
00092 i--;
00093 }
00094 }
00095 
00096 //------------------------//    var 24
00097 
00098 //990412
00099 
00100 Faculty* facultyPtr = this;
00101 int projectCount = 0;
00102 float prob=0;
00103 const float forCalcProb = (facultyPtr->ave_proj_count / facultyPtr->award_prob );
00104 
00105 float randNum = math.get_random_float();
00106 for ( i=0, prob=0; i<=MAX_RESEARCH_PROPOSAL; i++)
00107 {
00108 //              prob += math.double_poisson(i, forCalcProb);
00109 if ( randNum < prob )
00110 {
00111 projectCount = i;
00112 break;
00113 }
00114 }
00115 
00116 //----- add research proposals -----//
00117 
00118 for( ; projectCount > 0 && facultyPtr->research_proposal_count < MAX_RESEARCH_PROPOSAL;
00119 projectCount--, facultyPtr->research_proposal_count++ )
00120 {
00121 ResearchProposal* researchProposal = facultyPtr->research_proposal_array + facultyPtr->research_proposal_count;
00122 
00123 int tmp = (int) max(0, facultyPtr->ave_proj_size * math.get_random_snd(1.0f, 0.05f));
00124 
00125 researchProposal->total_dollars = tmp;
00126 
00127 researchProposal->overhead_rate = oRate;
00128 
00129 researchProposal->status = RESEARCH_PROPOSED;
00130 researchProposal->date_to_next_status = info.game_date + (2 + m.random(5)) * 30;                // draw a random number from 2 to 6 months
00131 
00132 deptPtr->research_m_history[R_PROPOSAL][THIS_MONTH] += (researchProposal->total_dollars / MAX_ACTIVE_RESEARCH_MONTH);
00133 }
00134 
00135 }
00136 //---------- End of function Faculty::think_research -----------//
00137 */
00138 
00139 //---------- Begin of function DepartmentArray::init_research -----------//
00143 void DepartmentArray::init_research() {
00144     //  return;
00145     //  err_here();
00146 
00147     is_calc_ini_statistic = false;
00148 
00149     //----//
00150 
00151     int saveGameDate = info.game_date;
00152 
00153     //----//            run for a year; just to generate and update research projects
00154 
00155     const int oneMonth = 30;
00156     const int simMonths = 6;
00157 
00158     int i, j, m;
00159 
00160     for ( m=1; m<=simMonths; m++ ) {
00161         if ( m == simMonths )
00162             is_calc_ini_statistic = true;
00163 
00164         info.game_date += oneMonth;
00165 
00166         for (i=size(); i>0; i--) {
00167             if ( is_deleted(i) )
00168                 continue;
00169 
00170             Department* dPtr = department_array[i];
00171 
00172             // for each faculty
00173             for ( j=dPtr->faculty_array.size(); j>0; j-- ) {
00174                 if ( dPtr->faculty_array.is_deleted(j) )
00175                     continue;
00176 
00177                 Faculty * fPtr = dPtr->faculty_array[j];
00178 
00179                 fPtr->init_research();
00180 
00181                 //## chea 301199 since I have run the preru year so this may make the date_to_next_status neg.
00182                 //                              if ( m == simMonths )
00183                 //                              {
00184                 //                                      for (int c=0; c<fPtr->research_proposal_count; c++)
00185                 //                                              fPtr->research_proposal_array[c].date_to_next_status -= simMonths * oneMonth;
00186                 //                              }
00187             }
00188         }
00189     }
00190 
00191     err_when(info.game_date - oneMonth * simMonths != saveGameDate );
00192     info.game_date = saveGameDate;
00193     is_calc_ini_statistic = false;                  //## chea BUGHERE after init this should set to true
00194     //  is_calc_ini_statistic = true;   //## chea BUGHERE after init this should set to true
00195 
00196 }
00197 
00198 //---------- Begin of function DepartmentArray::init_research -----------//
00199 
00200 //---------- Begin of function Faculty::init_research -----------//
00204 void Faculty::init_research() {
00205 
00206     //## chea begin "special case" when spon.=none 070699 5.1.4
00207     if ( player_school.sponsored_research_intensity <= 0 )
00208         return;
00209     //## chea end "special case" when spon.=none 070699 5.1.4
00210 
00211     int i;
00212 
00213     //------------------------//
00214     if ( rank_level == LONG_TERM_ADJUNCT || rank_level == SHORT_TERM_ADJUNCT || ave_proj_size <=0 )
00215         return;
00216 
00217     //------------------------//
00218 
00219     // 990414
00220 
00221     float oRate = finance.get_research_overhead_rate() / 100.0f;
00222 
00223     float qualityDriver = this->get_quality_driver();
00224 #if(GAME_VERSION>=200)
00225     // change in 18/03/2002
00226     float awardProb = 2.0f * (qualityDriver * 0.01f) / math.safe_pow( (1.0f + oRate), 3.0f );
00227     this->award_prob = m.fmin( 0.85f, m.fmax(0.10f, awardProb) );
00228 #else
00229     this->award_prob =
00230 
00231         //      float (0.01 + 0.005 * math.dual_response_func(1,50,100,29,33,20,76, qualityDriver) * math.safe_pow(1.0f+oRate, -1.5f) );
00232         //## chea 251099
00233         float (0.01 + 0.5 * math.dual_response_func(1,50,100,29,33,20,76, qualityDriver)/100 * math.safe_pow(1.0f+oRate, -1.5f) );
00234 #endif
00235 
00236     //------------------------//
00237 
00238     Department* deptPtr = department_array[department_recno];
00239     DepartmentInfo* deptInfo = department_res[deptPtr->department_id];
00240     FacultyTemplate* templ = faculty_res.get_faculty_template(deptInfo->template_discretionary_time, rank_age_group() );
00241     // PeerSchool *playerSchool = school_res.player_peer_school;
00242 
00243     //------------------------//
00244 
00245     for (i=0; i<research_proposal_count; i++) {
00246 
00247         ResearchProposal* researchProposal = research_proposal_array+i;
00248 
00249         if ( researchProposal->status == RESEARCH_PROPOSED ) {
00250             if ( math.get_random_float() < award_prob ) {
00251                 // accepted
00252                 researchProposal->status = RESEARCH_ACTIVE;
00253 
00254                 // TRICK #1
00255 
00256                 //                              researchProposal->date_to_next_status = info.game_date + (4 + m.random(MAX_ACTIVE_RESEARCH_MONTH-3)) * 30;              // draw a random number from 4 to 12 months
00257                 //## chea240899 draw a random number from 0 to 6 months  //## chea 251099
00258                 researchProposal->date_to_next_status = info.game_date + (m.random(6)) * 30;
00259                 //                              researchProposal->date_to_next_status = info.game_date + (1) * 30;              //## chea 251099 test
00260 
00261                 //## chea 151199 try my cal. method 1.4.1
00262                 research_month_expense += researchProposal->total_dollars / MAX_ACTIVE_RESEARCH_MONTH;
00263                 research_month_expense_direct += int((researchProposal->total_dollars / MAX_ACTIVE_RESEARCH_MONTH ) / ( 1+researchProposal->overhead_rate));
00264 
00265                 if ( is_calc_ini_statistic ) {
00266 #if(GAME_VERSION>=200)
00267                     // not sure why divide after add
00268                     deptPtr->research_m_history[R_ACCEPT][THIS_MONTH] += (float)researchProposal->total_dollars / (MAX_ACTIVE_RESEARCH_MONTH*1000);
00269 #else
00270                     deptPtr->research_m_history[R_ACCEPT][THIS_MONTH] += (researchProposal->total_dollars / MAX_ACTIVE_RESEARCH_MONTH);
00271                     //## chea 221199
00272                     deptPtr->research_m_history[R_ACCEPT][THIS_MONTH] /= 1000;
00273 #endif
00274                 }
00275             }
00276         }
00277         else if ( researchProposal->status == RESEARCH_ACTIVE ) {
00278         }
00279         else
00280             err_here();
00281 
00282         // TRICK #2
00283         // depends on game_date  //## chea 031199
00284         if ( info.game_date>= researchProposal->date_to_next_status ) {
00285             // expired: proposal rejected or research finished
00286 
00287             if ( researchProposal->status == RESEARCH_PROPOSED ) {
00288                 if ( is_calc_ini_statistic ) {
00289 #if(GAME_VERSION>=200)
00290                     deptPtr->research_m_history[R_REJECT][THIS_MONTH] += (float)researchProposal->total_dollars / (MAX_ACTIVE_RESEARCH_MONTH * 1000);
00291 #else
00292                     deptPtr->research_m_history[R_REJECT][THIS_MONTH] += (researchProposal->total_dollars / MAX_ACTIVE_RESEARCH_MONTH);
00293                     //## chea 221199
00294                     deptPtr->research_m_history[R_REJECT][THIS_MONTH] /= 1000;
00295 #endif
00296                 }
00297             }
00298             // fix in ver 2
00299             // else if ( researchProposal->status = RESEARCH_ACTIVE )
00300             else if ( researchProposal->status == RESEARCH_ACTIVE ) {
00301                 //## chea 151199 try my cal. method 1.4.1
00302                 research_month_expense -= researchProposal->total_dollars / MAX_ACTIVE_RESEARCH_MONTH;
00303                 research_month_expense_direct -= int((researchProposal->total_dollars / MAX_ACTIVE_RESEARCH_MONTH ) / ( 1+researchProposal->overhead_rate));
00304 
00305             }
00306             else
00307                 err_here();
00308 
00309             for (int j=i+1; j<research_proposal_count; j++) {
00310                 memcpy(research_proposal_array+j-1, research_proposal_array+j, sizeof(ResearchProposal));
00311             }
00312             research_proposal_count--;
00313 
00314             i--;
00315         }
00316     }
00317 
00318     //----------------------------------//
00319 
00320     Faculty* facultyPtr = this;
00321     int projectCount = 0;
00322     float prob=0;
00323 
00324     //## chea 161099
00325     //  const float forCalcProb = (facultyPtr->ave_proj_count / facultyPtr->award_prob ); //tryttt
00326     //   const float forCalcProb = (facultyPtr->ave_proj_count * deptInfo->percent_pi_faculty/100.0f / facultyPtr->award_prob );  //## chea 230899
00327     //tryttt
00328     const float forCalcProb = (facultyPtr->award_prob);
00329 
00330     //## chea 161099  it is impossiable to added k1 in the alg.
00331     //  const float forCalcProb = (k1*GCON*facultyPtr->ave_proj_count / (DCON*facultyPtr->award_prob ));  //## chea 161099
00332 
00333     //## 251099 use k1&k2  =1
00334     //  const float forCalcProb = (k1*GCON*facultyPtr->ave_proj_count / (DCON*facultyPtr->award_prob ));  //## chea 161099
00335     // const float forCalcProb = (GCON*facultyPtr->ave_proj_count / (DCON*facultyPtr->award_prob ));  //## chea 161099
00336 
00337     float randNum = math.get_random_float();
00338     for ( i=0, prob=0; i<=MAX_RESEARCH_PROPOSAL; i++) {
00339         prob += math.double_poisson(i, forCalcProb);
00340 
00341         if ( randNum < prob ) {
00342             projectCount = i;
00343             break;
00344         }
00345     }
00346 
00347     //----- add research proposals -----//
00348 
00349     for( ; projectCount > 0 && facultyPtr->research_proposal_count < MAX_RESEARCH_PROPOSAL;
00350          projectCount--, facultyPtr->research_proposal_count++ ) {
00351         ResearchProposal* researchProposal = facultyPtr->research_proposal_array + facultyPtr->research_proposal_count;
00352 
00353         //## chea 251099
00354         //              int tmp = (int) max(0.0f, facultyPtr->ave_proj_size * math.get_random_snd(1.0f, 0.05f)); //min & max bug chea
00355         //              int tmp = (int) max(0.2f, facultyPtr->ave_proj_size * math.get_random_snd(1.0f, 0.20f)); //min & max bug chea
00356         //              int tmp = (int) max(0.2f, facultyPtr->ave_proj_size ); //min & max bug chea //for testing
00357         //## chea 221199
00358         //min & max bug chea
00359         int tmp = (int) m.fmax(0.0f, facultyPtr->ave_proj_size * 1000 * math.get_random_snd(1.0f, 0.05f));
00360 
00361         //## chea 151199 try to make the research projet non 0
00362         //              if(tmp >=0 && tmp <= 1)
00363         //                      tmp =1;
00364 
00365         //## chea 191199 1.8.3
00366         //              if(tmp >=50)
00367         //                      tmp = 50;
00368 
00369         researchProposal->total_dollars = tmp;
00370 
00371         researchProposal->overhead_rate = oRate;
00372 
00373         researchProposal->status = RESEARCH_PROPOSED;
00374 
00375         //TRICK #3
00376         // draw a random number from 2 to 6 months
00377         researchProposal->date_to_next_status = info.game_date + (2 + m.random(5)) * 30;
00378         //              researchProposal->date_to_next_status = info.game_date + (1) * 30;              //## chea 251099 test
00379         //              researchProposal->date_to_next_status = info.game_date + (m.random(7)) * 30;            //## chea 240899 draw a random number from 2 to 6 months //## chea 251099
00380 
00381         if ( is_calc_ini_statistic ) {
00382 #if(GAME_VERSION>=200)
00383             deptPtr->research_m_history[R_PROPOSAL][THIS_MONTH] += (float)researchProposal->total_dollars / (MAX_ACTIVE_RESEARCH_MONTH * 1000);
00384 #else
00385             deptPtr->research_m_history[R_PROPOSAL][THIS_MONTH] += (researchProposal->total_dollars / MAX_ACTIVE_RESEARCH_MONTH);
00386             //## chea 221199
00387             deptPtr->research_m_history[R_PROPOSAL][THIS_MONTH] /= 1000;
00388 #endif
00389         }
00390     }
00391 
00392     for (int c=0; c<research_proposal_count; c++)
00393         //## chea 031199
00394         err_when( research_proposal_array[c].date_to_next_status > info.game_date+30*18 );
00395 }
00396 
00397 //---------- End of function Faculty::init_research -----------//

Generated on Fri Aug 23 01:37:29 2002 for VirtualU by doxygen1.2.17