problems_operationplan.cpp
Go to the documentation of this file.00001 /*************************************************************************** 00002 file : $URL: https://frepple.svn.sourceforge.net/svnroot/frepple/trunk/src/model/problems_operationplan.cpp $ 00003 version : $LastChangedRevision: 1315 $ $LastChangedBy: jdetaeye $ 00004 date : $LastChangedDate: 2010-07-17 18:08:53 +0200 (Sat, 17 Jul 2010) $ 00005 ***************************************************************************/ 00006 00007 /*************************************************************************** 00008 * * 00009 * Copyright (C) 2007-2010 by Johan De Taeye * 00010 * * 00011 * This library is free software; you can redistribute it and/or modify it * 00012 * under the terms of the GNU Lesser General Public License as published * 00013 * by the Free Software Foundation; either version 2.1 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 * This library is distributed in the hope that it will be useful, * 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser * 00019 * General Public License for more details. * 00020 * * 00021 * You should have received a copy of the GNU Lesser General Public * 00022 * License along with this library; if not, write to the Free Software * 00023 * Foundation Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,* 00024 * USA * 00025 * * 00026 ***************************************************************************/ 00027 00028 #define FREPPLE_CORE 00029 #include "frepple/model.h" 00030 namespace frepple 00031 { 00032 00033 00034 DECLARE_EXPORT void Operation::updateProblems() 00035 { 00036 // Find all operationplans, and delegate the problem detection to them 00037 if (getDetectProblems()) 00038 for (OperationPlan *o = first_opplan; o; o = o->next) o->updateProblems(); 00039 } 00040 00041 00042 // 00043 // BEFORECURRENT, BEFOREFENCE, PRECEDENCE 00044 // 00045 00046 00047 void OperationPlan::updateProblems() 00048 { 00049 // A flag for each problem type that may need to be created 00050 bool needsBeforeCurrent(false); 00051 bool needsBeforeFence(false); 00052 bool needsPrecedence(false); 00053 00054 // The following categories of operation plans can't have problems: 00055 // - locked opplans 00056 // - opplans of hidden operations 00057 if (!getLocked() && getOperation()->getDetectProblems()) 00058 { 00059 if (!getOwner() || getOperation() == OperationSetup::setupoperation) 00060 { 00061 // Avoid duplicating problems on child and owner operationplans 00062 // Check if a BeforeCurrent problem is required. 00063 if (dates.getStart() < Plan::instance().getCurrent()) 00064 needsBeforeCurrent = true; 00065 00066 // Check if a BeforeFence problem is required. 00067 // Note that we either detect of beforeCurrent or a beforeFence problem, 00068 // never both simultaneously. 00069 else if 00070 (dates.getStart() < Plan::instance().getCurrent() + oper->getFence()) 00071 needsBeforeFence = true; 00072 } 00073 if (nextsubopplan && getDates().getEnd() > nextsubopplan->getDates().getStart()) 00074 needsPrecedence = true; 00075 } 00076 00077 // Loop through the existing problems 00078 for (Problem::const_iterator j = Problem::begin(this, false); 00079 j!=Problem::end();) 00080 { 00081 // Need to increment now and define a pointer to the problem, since the 00082 // problem can be deleted soon (which invalidates the iterator). 00083 Problem& curprob = *j; 00084 ++j; 00085 // The if-statement keeps the problem detection code concise and 00086 // concentrated. However, a drawback of this design is that a new problem 00087 // subclass will also require a new demand subclass. I think such a link 00088 // is acceptable. 00089 if (typeid(curprob) == typeid(ProblemBeforeCurrent)) 00090 { 00091 // if: problem needed and it exists already 00092 if (needsBeforeCurrent) needsBeforeCurrent = false; 00093 // else: problem not needed but it exists already 00094 else delete &curprob; 00095 } 00096 else if (typeid(curprob) == typeid(ProblemBeforeFence)) 00097 { 00098 if (needsBeforeFence) needsBeforeFence = false; 00099 else delete &curprob; 00100 } 00101 else if (typeid(curprob) == typeid(ProblemPrecedence)) 00102 { 00103 if (needsPrecedence) needsPrecedence = false; 00104 else delete &curprob; 00105 } 00106 } 00107 00108 // Create the problems that are required but aren't existing yet. 00109 // There is a little trick involved here... Normally problems are owned 00110 // by objects of the Plannable class. OperationPlan isn't a subclass of 00111 // Plannable, so we need a dirty cast. 00112 if (needsBeforeCurrent) new ProblemBeforeCurrent(this); 00113 if (needsBeforeFence) new ProblemBeforeFence(this); 00114 if (needsPrecedence) new ProblemPrecedence(this); 00115 } 00116 00117 }
Documentation generated for frePPLe by
