⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rrproj_fctry.cpp

📁 aiParts is a set of C++ classes that can be used to develop artificial intelligence for multi-decisi
💻 CPP
📖 第 1 页 / 共 2 页
字号:

        rpfOpt *fopt = new rpfOpt (spd, sed, aipManditory);
        if (!fopt) { status = 0;  log("Err new rpfOpt"); break; }
        m_opts->add (fopt);  // list is forced distinct

      }
    }
  }

  return status;

}

//----------------------------------------------------------------------
//  handle the set of PosEmps (plus solution PosDays and EmpDays)
//
//  add to the opt-list

int rpfFactory::handle_pe_pd_ed (rppPosEmpItr peitr, 
                                 rpsProblem *sprob) {

  int status = 1;

  if (status) {                  // create {opt} from [PosEmp]

    rppPosEmp    * ppe;    // a posemp from the problem

    rpsPosition  * sp;     // pointers to objects in the solver
    rpsPosDay    * spd;
    rpsEmployee  * se;
    rpsEmpDay    * sed;

    rpsPositionItr pitr = sprob->position_iterator();
    rpsEmployeeItr eitr = sprob->employee_iterator();

    pitr.first();
    eitr.first();
                                            //  for each pos_emp...
    for ( ppe = peitr.first(); ppe; ppe = peitr.next() ) {

      sp = (rpsPosition*)(pitr.find(ppe->pos_id()));
      if (!sp) continue;

      se = (rpsEmployee*)(eitr.find(ppe->emp_id()));
      if (!se) continue;

      rpsPosDayItr pditr = sp->posday_iterator();
      rpsEmpDayItr editr = se->empday_iterator();

                                 // for each pos_day and emp_day...
      for ( spd = pditr.first(); spd; spd = pditr.next() ) {
        for ( sed = editr.first(); sed; sed = editr.next() ) {
          if (spd->yyyymmdd() == sed->yyyymmdd()) {

            if ( sed->start_time() > spd->start_time() ||
                 sed->end_time()   < spd->end_time() ) continue;

            rpfOpt *fopt = new rpfOpt (spd, sed, aipPrettyGood);
            if (!fopt) { status = 0; log("Err new rpfOpt"); break; }
            m_opts->add (fopt);  // list is forced distinct

          }
        }   // end of loop through emp_days (in the solver)
      }   // end of loop through pos_days (in the solver)

    }   // end of loop through posemps (in the problem)

  }

  return status;

}

//----------------------------------------------------------------------
//  handle the list of opts
//
//  create solver-options and attach them to decisions

int rpfFactory::handle_o (rpfOptItr foitr, rpsProblem *sprob) {

  int status = 1;

  if (!sprob) { status = 0; log("handle_o sprob"); }

  if (status) {                  // create (Option) from {opt}

    rpfOpt * fo;        // an opt-list element (stored in the factory)

    for ( fo = foitr.first(); fo; fo = foitr.next() ) {

      rpsDecision *sd = fo->pos_day()->dcsn();
      if (!sd) { status = 0; log("Err h_o dcsn"); break; }

      rpsOption *sopt = new rpsOption (fo->emp_day(), 
                                       fo->g_constant());
      if (!sopt) { status = 0; log("new rpsOption"); break; }

      sd->add_rps_option (sopt);

    }   // end of elements in distinct opt-list

  }

  return status;

}

//----------------------------------------------------------------------
//  return a posday from the solver given an pos_id and a date

rpsPosDay * rpfFactory::find_posday (long a_pos_id, long a_yyyymmdd, 
                                 long a_proj_id, rpsProblem *sprob) {

  if (!sprob) return 0;

  rpsPositionItr pitr = sprob->position_iterator();
  rpsPosition * sp = (rpsPosition*)(pitr.find(a_pos_id));
  if (!sp) return 0;

  rpsPosDayItr pditr = sp->posday_iterator();
  rpsPosDay  * spd = (rpsPosDay*) 
                        (pditr.find(a_pos_id, a_yyyymmdd, a_proj_id));

  return spd;

}

//----------------------------------------------------------------------
//  return an empday from the solver given an emp_id and a date

rpsEmpDay * rpfFactory::find_empday (long emp_id, long a_yyyymmdd, 
                                               rpsProblem *sprob) {

  if (!sprob) return 0;

  rpsEmployeeItr eitr = sprob->employee_iterator();

  rpsEmployee * se = (rpsEmployee*)(eitr.find(emp_id));
  if (!se) return 0;

  rpsEmpDayItr editr = se->empday_iterator();
  rpsEmpDay  * sed;

  for ( sed = editr.first(); sed; sed = editr.next() ) {
    if (sed->yyyymmdd() == a_yyyymmdd) break;
  }

  return sed;

}

//----------------------------------------------------------------------
//  apply historic EmpDayPos data to the emp

void rpfFactory::apply_empdaypos (rpsEmployee *e) {

  rppEmpDayPosItr edpitr = pprob()->empdaypos_iterator();

  rppEmpDayPos *edp = (rppEmpDayPos*)(edpitr.find(e->emp_id()));
  if (!edp) return;

  long last_yyyymmdd = edp->yyyymmdd();

  for ( edp = edpitr.next(); edp; edp = edpitr.next() ) {

    if (edp->emp_id() != e->emp_id()) break;

    if (edp->yyyymmdd() > last_yyyymmdd) {
      last_yyyymmdd = edp->yyyymmdd();
    }

  }

  aipTime lw(last_yyyymmdd);
  e->set_start_last_work(lw);

}

//----------------------------------------------------------------------
//  return true if emp is off on the specified day

int rpfFactory::emp_is_off (long a_emp_id, aipTime a_day) {

  int is_off = 0;

  rppEmpOffItr eoitr = pprob()->empoff_iterator();

  rppEmpOff *eoff = (rppEmpOff*)(eoitr.find(a_emp_id));

  for ( ; eoff; eoff = eoitr.next() ) {
    if (eoff->emp_id() != a_emp_id) break;
    if (a_day >= eoff->start_day() && a_day <= eoff->end_day() ) {
      is_off = 1;
      break;
    }
  }

  return is_off;

}

//----------------------------------------------------------------------
//  get data about the day of week for the emp or, if there is none
//  for this emp, set default values - return false on failure

void rpfFactory::get_dow_data (long a_emp_id, long a_dow,
                               long *a_start_hhmm, long *a_end_hhmm) {

  int is_any = 0;
  int is_match = 0;

  *a_start_hhmm = *a_end_hhmm = 0;

  rppEmpDowItr edowitr = pprob()->empdow_iterator();
  rppEmpDow *edow = (rppEmpDow*)(edowitr.find(a_emp_id));

  for ( ; edow; edow = edowitr.next()) {
    if (edow->emp_id() != a_emp_id) break;
    is_any = 1;
    if (edow->dow() == a_dow) {
      *a_start_hhmm = edow->start_hhmm();
      *a_end_hhmm   = edow->end_hhmm();
      is_match = 1;
      break;
    }
  }

  if (!is_match && !is_any) {
    *a_start_hhmm = 0;    // emp can work all days
    *a_end_hhmm   = 2359;
  }

}

//----------------------------------------------------------------------
// get an iterator for empids in the list owned by the factory

rpfEmpIdItr  rpfFactory::empid_iterator () const {

  rpfEmpIdItr i(m_emp_ids);

  return i;

}

//----------------------------------------------------------------------
// get an iterator for opts in the list owned by the factory

rpfOptItr  rpfFactory::opt_iterator () const {

  rpfOptItr i(m_opts);

  return i;

}

//======================================================================
//  rpfOpt
//
//----------------------------------------------------------------------
//  Constructor

rpfOpt::rpfOpt (rpsPosDay *a_pos_day, rpsEmpDay *a_emp_day,
                                           aipG a_g_constant) {

  m_pos_day = a_pos_day;
  m_emp_day = a_emp_day;
  m_g_constant = a_g_constant;
  m_proj_id  = m_pos_day ? m_pos_day->proj_id()  : 0;
  m_pos_id   = m_pos_day ? m_pos_day->pos_id()   : 0;
  m_emp_id   = m_emp_day ? m_emp_day->emp_id()   : 0;
  m_yyyymmdd = m_emp_day ? m_emp_day->yyyymmdd() : 0;

}

//----------------------------------------------------------------------
//  Destructor

rpfOpt::~rpfOpt () {}

//======================================================================
//                           License
//
//   Permission is hereby granted, free of charge, to any
//   person obtaining a copy of this software and associated
//   documentation files (the "Software"), to deal in the Software
//   without restriction, including without limitation the rights
//   to use, copy, modify, merge, publish, distribute, sublicense,
//   and/or sell copies of the Software, and to permit persons to
//   whom the Software is furnished to do so, subject to the
//   following conditions:
//
//   The copyright notice and this license shall be included in all
//   copies or substantial portions of the Software.
//
//   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
//   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
//   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//   NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
//   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
//   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
//   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
//   OTHER DEALINGS IN THE SOFTWARE.
//
//======================================================================

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -