Home Page Downloads Contact Us

Free Open Source Artificial Intelligence C++ Parts

aiParts Open Source Project  

Home Page
Open Source
Contact
Free Downloads
Releases and Credits
Software Status
License
v0.9.3 README File
About rrproj
assigning people and/or equipment to projects
High-Hope Technique
History of the AI
View Source Files
and how they are organized
Making Programs
Development Notes
Using aiParts
Your Application
Support and Services

aiParts Source File

//**********************************************************************
//  rrproj_fctry.h   Used by a problem to build a solver
//
//  An application should not directly include this file; 
//  an application should include:  rrproj_prob.h
//
//  Copyright (c)  2008  Brian Marshall
//
//  See the license at end of this file.
//
//  Developers/Contributers:
//    [BRM] Brian Marshall - Calgary - bmarshal@agt.net
//
//  08/01/28  [BRM] began development
//
//----------------------------------------------------------------------
//  A note on prefixes
//
//  rpp   rrproj  problem  (setup by application)
//  rps   rrproj  solver   (used by the problem)
//  rpf   rrproj  factory  (solver-factory)
//
//----------------------------------------------------------------------
//  Data-sets used to create other data-sets
//
//    key: [Problem-data]  (solver-data)  {temp-data}  
//
//
//                  [PosDay]    [PosEmp]    [Assgnmnt]______
//                  |  |  |     |      |     |              |
//              (Pos)  |  |     |      {EmpId}              |
//                     |  |     |         | ___[EmpDayPos]  |
//                (Dcsn)  |   __|       (Emp)               |
//                        |  |            |                 |
//                 (PosDay)  |  [EmpOff]  |  [EmpDOW]       |
//                      |    |__       |  |  |              |
//                      |       |      (EmpDay)             |
//                      |       |_______| or _|             |
//                      |_______________{Opt}_______________|
//                                        |
//                                     (Option)
//
//  1: [PosDay] =>  (Pos) (Dcsn) (PosDay)
//  2: [PosEmp] [Assgnmnt] [EmpDayPos] [EmpOff] [EmpDOW] 
//                                         => (Emp) (EmpDay)
//  3: [Assgnmnt] (EmpDay) => {Opt}
//  4: [PosEmp] (PosDay) (EmpDay) => {Opt}
//  5: {Opt} => (Option)
//
//  in the future...
//     {Opt} => {Opt}    remove opts where a manditory opt exists
//                         and manditory opts satisfy the dcsn
//
//----------------------------------------------------------------------
//  Future development
//
//  if, after all options have been created, an empday has no opts
//  in its list, delete the empday, and if an emp has no empdays,
//  delete the emp
//
//----------------------------------------------------------------------

#ifndef rrproj_fctry_h_guard
#define rrproj_fctry_h_guard

#include "rrproj_prob.h"
#include "rrproj_solv.h"

//----------------------------------------------------------------------
//  Classes  -  subclassing is shown by indentation

   class rpfFactory;          // builds a solver from a problem

// class aipDemon                 ( in aipPandemonium.h )
     class rpfEmpId;          // for making a distinct list of emps
     class rpfOpt;            // for making a distinct list of opts
// class aipDemonItr;             ( in aipPandemonium.h )
     class rpfEmpIdItr;       // iterator for rpfEmpId
     class rpfOptItr;         // iterator for rpfOpt

//======================================================================
//  rpfFactory  -  Factory that can build a solver from a problem
//
//  setup() and handle_xxx() functions return true on success

class rpfFactory {

  rppProblem     * m_problem_data;

                        // temporary datasets
  aipPandemonium * m_emp_ids;        // distinct emp_ids
  aipPandemonium * m_opts;           // distinct option data

protected:

  long very_unlikely_id () { return -938258186; }

  int setup  (rpsProblem *sprob);

  int handle_pd (rppPosDayItr  pditr, rpsProblem *sprob);

  int handle_pe_a (rppPosEmpItr peitr, rppAssgnItr aitr,  
                                            rpsProblem *sprob);

  int handle_e (rpsEmployee *semp, rpsProblem *sprob);

  int handle_a_ed (rppAssgnItr aitr, rpsProblem *sprob);

  int handle_pe_pd_ed (rppPosEmpItr peitr, rpsProblem *sprob);

  int handle_o (rpfOptItr oitr, rpsProblem *sprob);

  rpsPosDay * find_posday (long pos_id, long yyyymmdd, 
                           long proj_id, rpsProblem *sprob);

  rpsEmpDay * find_empday (long emp_id, long yyyymmdd, 
                                            rpsProblem *sprob);

  void apply_empdaypos (rpsEmployee *e);

  int emp_is_off (long a_emp_id, aipTime a_day);

  void get_dow_data (long a_emp_id, long a_dow,
                     long *a_start_hhmm, long *a_end_hhmm);

public:

  rpfFactory (rppProblem *pdata);      // factory uses problem data
  virtual ~rpfFactory ();

  const char * rslt_desc () const { 
    return m_problem_data->get_rslt_desc(); 
  }

  rppProblem * pprob () { return m_problem_data; }

  rpsProblem * make_rps_problem ();   // to create a solver-problem

  rpfEmpIdItr  empid_iterator () const;  // get an iterator
  rpfOptItr    opt_iterator   () const;

  void log (const char *str) const { m_problem_data->log(str); }

};

//======================================================================
//  rpfEmpId  -  for making a distinct list of emps

class rpfEmpId : public aipDemon {

  long  m_emp_id;

public:

  rpfEmpId (long a_emp_id) { m_emp_id = a_emp_id; }
  ~rpfEmpId () {}

  virtual long num_keys (void) const { return 1;        }
  virtual long     key1 (void) const { return m_emp_id; }

  long emp_id () const { return m_emp_id; }

};

//======================================================================
//  rpfOpt  -  for making a distinct list of opts

class rpfOpt : public aipDemon {

  rpsPosDay  * m_pos_day;
  rpsEmpDay  * m_emp_day;
  aipG         m_g_constant;

  long         m_proj_id;
  long         m_pos_id;
  long         m_emp_id;
  long         m_yyyymmdd;

public:

  rpfOpt (rpsPosDay *a_pos_day, rpsEmpDay *a_emp_day, 
                                     aipG a_g_constant);
  ~rpfOpt ();

  virtual long num_keys (void) const { return 4;          }
  virtual long     key1 (void) const { return m_proj_id;  }
  virtual long     key2 (void) const { return m_pos_id;   }
  virtual long     key3 (void) const { return m_yyyymmdd; }
  virtual long     key4 (void) const { return m_emp_id;   }

  long pos_id     () const { return m_emp_id;     }
  long emp_id     () const { return m_emp_id;     }
  long yyyymmdd   () const { return m_yyyymmdd;   }
  aipG g_constant () const { return m_g_constant; }

  rpsPosDay * pos_day () const { return m_pos_day; }
  rpsEmpDay * emp_day () const { return m_emp_day; }

};

//======================================================================
// iterator for rpfEmpId

class rpfEmpIdItr : public aipDemonItr  {

public:

  rpfEmpIdItr (aipPandemonium *p) {
    set_demon_itr(p,0);
  }

  rpfEmpIdItr (const rpfEmpIdItr& x) {
    set_demon_itr (x.pandemonium(), x.current());
  }

  virtual ~rpfEmpIdItr () {}

  rpfEmpIdItr& operator = (const rpfEmpIdItr& x) {
    set_demon_itr(x.pandemonium(), x.current());
    return *this;
  }

  rpfEmpId * first () {
    return (rpfEmpId*)aipDemonItr::first();
  }

  rpfEmpId * next () {
    return (rpfEmpId*)aipDemonItr::next();
  }

};

//======================================================================
// iterator for rpfOpt

class rpfOptItr : public aipDemonItr  {

public:

  rpfOptItr (aipPandemonium *p) {
    set_demon_itr(p,0);
  }

  rpfOptItr (const rpfOptItr& x) {
    set_demon_itr (x.pandemonium(), x.current());
  }

  virtual ~rpfOptItr () {}

  rpfOptItr& operator = (const rpfOptItr& x) {
    set_demon_itr(x.pandemonium(), x.current());
    return *this;
  }

  rpfOpt * first () {
    return (rpfOpt*)aipDemonItr::first();
  }

  rpfOpt * next () {
    return (rpfOpt*)aipDemonItr::next();
  }

};

//======================================================================

#endif

//======================================================================
//                           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.
//
//**********************************************************************