📄 rrproj_prob.cpp
字号:
// Add a Employee-Off
void rppProblem::add_emp_off (long a_emp_id,
long a_start_yyyymmdd,
long a_end_yyyymmdd) {
rppEmpOff *x = new rppEmpOff (a_emp_id,
a_start_yyyymmdd, a_end_yyyymmdd);
if (x) m_empoffs->add(x);
}
//----------------------------------------------------------------------
// Add a Position-Employee pair
void rppProblem::add_pos_emp (long a_pos_id, long a_emp_id) {
rppPosEmp *x = new rppPosEmp (a_pos_id, a_emp_id);
if (x) m_posemps->add(x);
}
//----------------------------------------------------------------------
// Add an Assignment
void rppProblem::add_assignment (long a_proj_id, long a_pos_id,
long a_emp_id,
long a_start_yyyymmdd,
long a_end_yyyymmdd) {
rppAssignment *x = new rppAssignment (a_proj_id, a_pos_id, a_emp_id,
a_start_yyyymmdd, a_end_yyyymmdd);
if (x) m_assignments->add(x);
}
//----------------------------------------------------------------------
// Add an historic Emp-Day-Pos
void rppProblem::add_empdaypos (long a_emp_id, long a_yyyymmdd,
long a_proj_id, long a_pos_id) {
rppEmpDayPos *x = new rppEmpDayPos (a_emp_id, a_yyyymmdd,
a_proj_id, a_pos_id);
if (x) m_empdaypos->add(x);
}
//----------------------------------------------------------------------
// Add a Position-Day-Employee
void rppProblem::add_posdayemp (long a_proj_id, long a_pos_id,
long a_yyyymmdd, long a_emp_id) {
rppPosDayEmp *x = new rppPosDayEmp (a_proj_id, a_pos_id,
a_yyyymmdd, a_emp_id);
if (x) m_posdayemps->add(x);
}
//----------------------------------------------------------------------
// Attempt to solve the rrproj problem
//
// A description of the result of calling this function is logged.
//
// Return 1 (true) if a solution is found, 0 otherwise.
int rppProblem::solve () {
rpfFactory *factory = new rpfFactory(this);
if (!factory) {
log("ABORT - could not make factory");
return 0;
}
rpsProblem * rps_problem = factory->make_rps_problem();
if (!rps_problem) {
log("ABORT - error creating rps_problem");
return 0;
}
delete factory;
// rps_problem->enable_log_tries();
rps_problem->disable_log_tries();
// rps_problem->enable_log_options();
rps_problem->disable_log_options();
int status = rps_problem->solve_rr_problem();
if (status) {
log("Solution found.");
save_solution(this, rps_problem);
} else {
log("Solution was not found.");
}
delete rps_problem;
return status;
}
//----------------------------------------------------------------------
// get_pos_day_emp - get a solution datum, or zero after last
int rppProblem::get_pos_day_emp (long *a_proj_id, long *a_pos_id,
long *a_yyyymmdd, long *a_emp_id) {
rppPosDayEmp *pde;
if (m_posdayemp_itr) {
pde = m_posdayemp_itr->next();
} else {
m_posdayemp_itr = new rppPosDayEmpItr(m_posdayemps);
pde = m_posdayemp_itr->first();
}
if (!pde) return 0;
*a_proj_id = pde->proj_id();
*a_pos_id = pde->pos_id();
*a_yyyymmdd = pde->yyyymmdd();
*a_emp_id = pde->emp_id();
return 1;
}
//----------------------------------------------------------------------
// Get an iterator for Position-Days in a problem
rppPosDayItr rppProblem::posday_iterator () const {
rppPosDayItr i(m_posdays);
return i;
}
//----------------------------------------------------------------------
// Get an iterator for Employee-Days-of-week in a problem
rppEmpDowItr rppProblem::empdow_iterator () const {
rppEmpDowItr i(m_empdows);
return i;
}
//----------------------------------------------------------------------
// Get an iterator for Employee-days-Off in a problem
rppEmpOffItr rppProblem::empoff_iterator () const {
rppEmpOffItr i(m_empoffs);
return i;
}
//----------------------------------------------------------------------
// Get an iterator for Position-Employee pairs in a problem
rppPosEmpItr rppProblem::posemp_iterator () const {
rppPosEmpItr i(m_posemps);
return i;
}
//----------------------------------------------------------------------
// Get an iterator for Assignments in a problem
rppAssgnItr rppProblem::assgn_iterator () const {
rppAssgnItr i(m_assignments);
return i;
}
//----------------------------------------------------------------------
// Get an iterator for historic Emp-Day-Pos in a problem
rppEmpDayPosItr rppProblem::empdaypos_iterator () const {
rppEmpDayPosItr i(m_empdaypos);
return i;
}
//----------------------------------------------------------------------
// Get an iterator for Position-Day-Employees in a problem
rppPosDayEmpItr rppProblem::posdayemp_iterator () const {
rppPosDayEmpItr i(m_posdayemps);
return i;
}
//======================================================================
// rppPosDay
//
//----------------------------------------------------------------------
// Constructor
rppPosDay::rppPosDay (long a_proj_id, long a_pos_id,
long a_yyyymmdd, long a_num_emps_req,
long a_start_hhmm, long a_end_hhmm) {
m_proj_id = a_proj_id;
m_pos_id = a_pos_id;
m_yyyymmdd = a_yyyymmdd;
m_num_emps_req = a_num_emps_req;
m_start_hhmm = a_start_hhmm;
m_end_hhmm = a_end_hhmm;
}
//----------------------------------------------------------------------
// Destructor
rppPosDay::~rppPosDay () {}
//----------------------------------------------------------------------
// Read data from string to setup this object
int rppPosDay::read_str (const char *x) {
m_proj_id = m_pos_id = m_yyyymmdd = 0;
m_num_emps_req = m_start_hhmm = m_end_hhmm = 0;
char s_date[31], s_start_time[31], s_end_time[31];
if (x && *x) x = aip_get_val(x, 10, &m_proj_id, '|');
if (x && *x) x = aip_get_val(x, 10, &m_pos_id, '|');
if (x && *x) x = aip_get_str(x, 30, s_date, '|');
if (x && *x) x = aip_get_val(x, 10, &m_num_emps_req, '|');
if (x && *x) x = aip_get_str(x, 30, s_start_time, '|');
if (x && *x) x = aip_get_str(x, 30, s_end_time, '|');
if (!x) return 0;
rppFileDate x_date(s_date);
if ( !x_date.is_valid() ) return 0;
m_yyyymmdd = x_date.long_date();
rppFileTime x_start_time(s_start_time);
if ( !x_start_time.is_valid() ) return 0;
m_start_hhmm = x_start_time.long_time();
rppFileTime x_end_time(s_end_time);
if ( !x_end_time.is_valid() ) return 0;
m_end_hhmm = x_end_time.long_time();
return 1;
}
//----------------------------------------------------------------------
// Write the data in this object to the string; return 0 on failure
int rppPosDay::write_str (char *x) const {
rppFileDate x_date(m_yyyymmdd);
if ( !x_date.is_valid() ) return 0;
rppFileTime x_start_time(m_start_hhmm);
if ( !x_start_time.is_valid() ) return 0;
rppFileTime x_end_time(m_end_hhmm);
if ( !x_end_time.is_valid() ) return 0;
int n = sprintf (x, "rppPosDay|%ld|%ld|%s|%ld|%s|%s",
m_proj_id, m_pos_id,
x_date.file_date(),
m_num_emps_req,
x_start_time.file_time(),
x_end_time.file_time());
return (n ? 1 : 0);
}
//======================================================================
// rppEmpDow
//
//----------------------------------------------------------------------
// Constructor
rppEmpDow::rppEmpDow (long a_emp_id, long a_dow,
long a_start_hhmm, long a_end_hhmm) {
m_emp_id = a_emp_id;
m_dow = a_dow;
m_start_hhmm = a_start_hhmm;
m_end_hhmm = a_end_hhmm;
}
//----------------------------------------------------------------------
// Destructor
rppEmpDow::~rppEmpDow () {}
//----------------------------------------------------------------------
// Read data from string to setup this object
int rppEmpDow::read_str (const char *x) {
char s_start_time[31], s_end_time[31];
if (x && *x) x = aip_get_val(x, 10, &m_emp_id, '|');
if (x && *x) x = aip_get_val(x, 10, &m_dow, '|');
if (x && *x) x = aip_get_str(x, 30, s_start_time, '|');
if (x && *x) x = aip_get_str(x, 30, s_end_time, '|');
if (!x) return 0;
rppFileTime x_start_time(s_start_time);
if ( !x_start_time.is_valid() ) return 0;
m_start_hhmm = x_start_time.long_time();
rppFileTime x_end_time(s_end_time);
if ( !x_end_time.is_valid() ) return 0;
m_end_hhmm = x_end_time.long_time();
return 1;
}
//----------------------------------------------------------------------
// Write the data in this object to the string; return 0 on failure
int rppEmpDow::write_str (char *x) const {
rppFileTime x_start_time(m_start_hhmm);
if ( !x_start_time.is_valid() ) return 0;
rppFileTime x_end_time(m_end_hhmm);
if ( !x_end_time.is_valid() ) return 0;
int n = sprintf (x, "rppEmpDow|%ld|%ld|%s|%s",
m_emp_id, m_dow,
x_start_time.file_time(),
x_end_time.file_time());
return (n ? 1 : 0);
}
//======================================================================
// rppEmpOff
//
//----------------------------------------------------------------------
// Constructor
rppEmpOff::rppEmpOff (long a_emp_id,
long a_start_yyyymmdd, long a_end_yyyymmdd) {
m_emp_id = a_emp_id;
m_start_yyyymmdd = a_start_yyyymmdd;
m_end_yyyymmdd = a_end_yyyymmdd;
derive_data();
}
//----------------------------------------------------------------------
// Destructor
rppEmpOff::~rppEmpOff () {}
//----------------------------------------------------------------------
// Derive data
void rppEmpOff::derive_data() {
m_start_day = aipTime(m_start_yyyymmdd);
m_end_day = aipTime(m_end_yyyymmdd);
}
//----------------------------------------------------------------------
// Read data from string to setup this object
int rppEmpOff::read_str (const char *x) {
char s_start_date[31], s_end_date[31];
if (x && *x) x = aip_get_val(x, 10, &m_emp_id, '|');
if (x && *x) x = aip_get_str(x, 30, s_start_date, '|');
if (x && *x) x = aip_get_str(x, 30, s_end_date, '|');
if (!x) return 0;
rppFileDate x_start_date(s_start_date);
if ( !x_start_date.is_valid() ) return 0;
m_start_yyyymmdd = x_start_date.long_date();
rppFileDate x_end_date(s_end_date);
if ( !x_end_date.is_valid() ) return 0;
m_end_yyyymmdd = x_end_date.long_date();
if (x) derive_data(); // must get called
return 1;
}
//----------------------------------------------------------------------
// Write the data in this object to the string; return 0 on failure
int rppEmpOff::write_str (char *x) const {
rppFileDate x_start_date(m_start_yyyymmdd);
if ( !x_start_date.is_valid() ) return 0;
rppFileDate x_end_date(m_end_yyyymmdd);
if ( !x_end_date.is_valid() ) return 0;
int n = sprintf (x, "rppEmpOff|%ld|%s|%s",
m_emp_id,
x_start_date.file_date(),
x_end_date.file_date());
return (n ? 1 : 0);
}
//======================================================================
// rppPosEmp
//
//----------------------------------------------------------------------
// Constructor
rppPosEmp::rppPosEmp (long a_pos_id, long a_emp_id) {
m_pos_id = a_pos_id;
m_emp_id = a_emp_id;
}
//----------------------------------------------------------------------
// Destructor
rppPosEmp::~rppPosEmp () {}
//----------------------------------------------------------------------
// Read data from string to setup this object
int rppPosEmp::read_str (const char *x) {
if (x && *x) x = aip_get_val(x, 10, &m_pos_id, '|');
if (x && *x) x = aip_get_val(x, 10, &m_emp_id, '|');
return (x ? 1 : 0);
}
//----------------------------------------------------------------------
// Write the data in this object to the string; return 0 on failure
int rppPosEmp::write_str (char *x) const {
int n = sprintf (x, "rppPosEmp|%ld|%ld",
m_pos_id, m_emp_id);
return (n ? 1 : 0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -