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

📄 aipreqres.cpp

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

aiprrOption::~aiprrOption() {}

//----------------------------------------------------------------------
//  take_msg  - take and react to a message

void aiprrOption::take_msg (aipMsg *mm) {

  aipHHOption::take_msg(mm);  // pass message to parent class

  aiprrMsg *m = (aiprrMsg *)mm;

  if (m->typ() == HH_Starting_New_Try) {
    m_g_dynamic = aipNeutral;
  }

}

//----------------------------------------------------------------------
//  set_g_dynamic

void aiprrOption::set_g_dynamic (aipG x) { m_g_dynamic  = x; }

//----------------------------------------------------------------------
//  add_g_dynamic

void aiprrOption::add_g_dynamic (aipG x) { m_g_dynamic += x; }

//----------------------------------------------------------------------
//  g_opt

aipG aiprrOption::g_opt() {

  return aipHHOption::g_opt() + g_user_constant() + m_g_dynamic;

}

//----------------------------------------------------------------------
//  g_opt_cmp

aipG aiprrOption::g_opt_cmp() { return g_user_constant() + m_g_dynamic; }

//----------------------------------------------------------------------
//  g_opt_usr

aipG aiprrOption::g_opt_usr() { return g_user_constant() + m_g_dynamic; }

//======================================================================
//  aiprrRequirement
//
//----------------------------------------------------------------------
//  Constructor

aiprrRequirement::aiprrRequirement (long a_id, aiprrProblem *a_prob) {

  m_id = a_id;
  m_prob = a_prob;

  m_reqdays = new aipPandemonium;

  m_hope = new aipHHHope;

}

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

aiprrRequirement::~aiprrRequirement () {

  if (m_reqdays) delete m_reqdays;

  if (m_hope) delete m_hope;

}

//----------------------------------------------------------------------
//  add_reqday

void aiprrRequirement::add_reqday (aiprrReqDay *x) {

  if (!x) return;

  m_reqdays->add (x);

}

//----------------------------------------------------------------------
//  take_msg  - take and react to a message

void aiprrRequirement::take_msg (aipMsg *mm) {

  aiprrMsg *m = (aiprrMsg *)mm;

  m->set_is_in_cur_solution(1);
  m_hope->take_msg(mm);
  m_importance.take_msg(mm);

  m_reqdays->take_msg(mm);

}

//----------------------------------------------------------------------
//  Note that a decision for this requirement has been decided

void aiprrRequirement::note_aiprr_decide (aiprrDecision *d, aiprrOption *o) {

  // o (ptr to an option) may be null

  m_importance.note_aiprr_decide(d, o);

}


//----------------------------------------------------------------------
//  Return true if all req-days are satisfied

int aiprrRequirement::is_satisfied () const {

  aiprrReqDay *rd = first_unsatisfied_reqday();

  return rd ? 0 : 1;

}


//----------------------------------------------------------------------
//  Return the first unsatisfied requirement-day

aiprrReqDay * aiprrRequirement::first_unsatisfied_reqday () const {

  aiprrReqDayItr itr = reqday_iterator();

  for ( aiprrReqDay *prd = itr.first(); prd; prd = itr.next() ) {
    if ( ! prd->is_satisfied() ) return prd;
  }

  return 0;

}

//----------------------------------------------------------------------
//  Return a requirement-day that has just enough options left, so we
//  can decide the decisions the remaining number of times and 
//  for each decide, take the first available option.

//aiprrReqDay * aiprrRequirement::trivial_reqday () const {

//  aiprrReqDayItr itr = reqday_iterator();
//  for ( aiprrReqDay *rd = itr.first(); rd; rd = itr.next() ) {
//    if ( !(rd->has_surplus_opts()) ) return rd;
//  }

//  return 0;

//}


//----------------------------------------------------------------------
//  return an iterator: requirement-days for the requirement

aiprrReqDayItr  aiprrRequirement::reqday_iterator() const {

  aiprrReqDayItr i(m_reqdays);

  return i;

}

//======================================================================
//  aiprrReqDay
//
//----------------------------------------------------------------------
//  Constructor
//
//  set_dcsn() must be called after the decision is created

aiprrReqDay::aiprrReqDay (aiprrRequirement *a_req, long a_yyyymmdd) {

  m_req  = a_req;
  m_day  = aipTime(a_yyyymmdd);
  m_dcsn = 0;

  m_hope = new aipHHHope;

}

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

aiprrReqDay::~aiprrReqDay () {

  if (m_hope) delete m_hope;

}

//----------------------------------------------------------------------
//  take_msg  - take and react to a message

void aiprrReqDay::take_msg (aipMsg *mm) {

  aiprrMsg *m = (aiprrMsg *)mm;

  m->set_is_in_cur_solution(1);
  m_hope->take_msg(mm);
  m_importance.take_msg(mm);

}

//----------------------------------------------------------------------
//  Note that a decision for this requirement-day has been decided

void aiprrReqDay::note_aiprr_decide (aiprrDecision *d, aiprrOption *o) {

  // o (ptr to an option) may be null

  if (!d) {
    if (o) {
      log ("aiprrReqDay d is null");
    } else {
      log ("aiprrReqDay d,o are null");
    }
  }
    
}


//----------------------------------------------------------------------
//  Return true if the reqday has all the resourcess it needs

int aiprrReqDay::is_satisfied () const {

  if ( m_dcsn && m_dcsn->is_decided() ) return 1;

  return 0;

}

//----------------------------------------------------------------------
//  Return true if the reqday has more than enough options

int aiprrReqDay::has_surplus_opts () const {

  if (!m_dcsn) return 0;

  long remaining_to_decide = m_dcsn->num_to_decide() - 
                             m_dcsn->num_decided();

  if (m_dcsn->num_opt_remaining() > remaining_to_decide) return 1;

  return 0;

}

//======================================================================
//  aiprrResource
//
//----------------------------------------------------------------------
//  Constructor

aiprrResource::aiprrResource (long a_id, aiprrProblem *a_prob) {

  m_id = a_id;
  m_prob = a_prob;

  m_resdays = new aipPandemonium;

  m_hope = new aipHHHope;
  m_is_in_cur_solution = 0;

}

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

aiprrResource::~aiprrResource () {

  if (m_resdays) delete m_resdays;

  if (m_hope) delete m_hope;

}

//----------------------------------------------------------------------
//  add_resday

void aiprrResource::add_resday (aiprrResDay *x) {

  if (!x) return;

  m_resdays->add (x);

}

//----------------------------------------------------------------------
//  take_msg  - take and react to a message

void aiprrResource::take_msg (aipMsg *mm) {

  aiprrMsg *m = (aiprrMsg *)mm;

  if (m->typ() == HH_Starting_New_Try) {
    m_is_in_cur_solution = 0;
  }

  m->set_is_in_cur_solution(m_is_in_cur_solution);
  m_hope->take_msg(mm);

  m_resdays->take_msg(mm);

}

//----------------------------------------------------------------------
//  Note that a decision involving this resource has been decided

void aiprrResource::note_aiprr_decide (aiprrDecision *d, aiprrOption *o) {

  if (!d) log ("aiprrReqDay d is null");

  // o (ptr to an option) may be null

  if (o) m_is_in_cur_solution = 1;

}


//----------------------------------------------------------------------
//  resday_iterator

aiprrResDayItr  aiprrResource::resday_iterator() const {

  aiprrResDayItr i(m_resdays);

  return i;

}

//======================================================================
//  aiprrResDay
//
//----------------------------------------------------------------------
//  Constructor

aiprrResDay::aiprrResDay (aiprrResource *a_res, long a_yyyymmdd) {

  m_res = a_res;
  m_day = aipTime(a_yyyymmdd);

  m_opts = new aipPandemonium;

  m_hope = new aipHHHope;

}

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

aiprrResDay::~aiprrResDay () {

  if (m_hope) delete m_hope;

  if (m_opts) delete m_opts;

}

//----------------------------------------------------------------------
//  take_msg  - take and react to a message

void aiprrResDay::take_msg (aipMsg *mm) {

  aiprrMsg *m = (aiprrMsg *)mm;

  if (m->typ() == HH_Starting_New_Try) {
    m_is_in_cur_solution = 0;
  }

  m->set_is_in_cur_solution(m_is_in_cur_solution);
  m_hope->take_msg(mm);

}

//----------------------------------------------------------------------
//  Note that a decision involving this resday has been decided

void aiprrResDay::note_aiprr_decide (aiprrDecision *d, aiprrOption *o) {

  if (!d) log ("aiprrReqDay d is null");

  // o (ptr to an option) may be null

  if (o) m_is_in_cur_solution = 1;

}


//======================================================================
//                           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 + -