Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

OsiDylpMessages.cpp

00001 #ifdef COIN_USE_DYLP
00002 
00009 namespace {
00010   char sccsid[] = "%W%  %G%" ;
00011   char cvsid[] = "$Id: OsiDylpMessages.cpp,v 1.3 2003/09/27 18:22:19 lou-oss Exp $" ;
00012 }
00013 
00014 #include "OsiDylpSolverInterface.hpp"
00015 #include "OsiDylpMessages.hpp"
00016 
00017 /* Cut name lengths for readability. */
00018 
00019 #define ODSI OsiDylpSolverInterface
00020 #define OSI OsiSolverInterface
00021 
00022 /*
00023   The general strategy for setting up the COIN messaging facility is as
00024   follows:
00025 
00026     * Create a CoinMessages object, sized to accommodate the number of messages
00027       you plan to define. The initial size can be zero, but incremental growth
00028       is not particularly efficient.
00029 
00030     * Define your messages. There are three pieces of information that need
00031       to be supplied for each message: an external ID number, a level, and a
00032       format string. There is a notion of severity wired into the external ID
00033       number; see CoinMessageHandler for details. Level controls when the
00034       message is printed; CoinMessageHandler associates higher numbers with
00035       increased verbosity.  The format string can be null, if you want to
00036       build the whole thing on the fly.
00037 
00038     * Load the messages into the CoinMessage object. This involves repeated
00039       creation of a CoinOneMessage object, which is then loaded into the
00040       CoinMessages object using CoinMessages::addMessage. You specify an
00041       internal ID number at the time you add the message to the CoinMessages
00042       object.
00043     
00044       One approach to this is to define a derived class, XXXMessages, whose
00045       sole reason for existence is a constructor that performs the load. The
00046       internal ID numbers can be defined with an enum, which makes it a bit
00047       easier to specify a particular message and makes your code a bit more
00048       resilient against the inevitable insertion/deletion of messages as the
00049       code evolves.
00050 
00051     * Create a CoinMessageHandler object.
00052 
00053   To print a message, start construction of the message with
00054 
00055     CoinMessageHandler::message(<internal ID number>,<CoinMessages object>)
00056   
00057   Then use the various overloaded << operators to supply the necessary
00058   parameters. Finish with CoinMessageHandler::finish() or '<< CoinMessageEol'
00059   (where CoinMessageEol is part of the CoinMessageMarker enum).
00060 */
00061 
00062 /*
00063   Message definitions.
00064 
00065   The precise form isn't important here, so long as the method that loads them
00066   into a CoinMessages object can come up with values for external number,
00067   detail level, and format string. The use of an enum to provide a local ID
00068   for each message is mainly useful with the internationalisation feature. It
00069   makes it easy to slap the same ID on alternate versions of a message.
00070 */
00071 
00072 namespace { /* unnamed:file */
00073 
00074 typedef struct { OsiDylpMessageID_enum inID ;
00075                  int exID ;
00076                  int lvl ;
00077                  const char *fmt ; } MsgDefn ;
00078 
00079 static MsgDefn us_en_defns[] = {
00080   { ODSI_TEST_MSG, 0001, 2, "This is the us_en test message, eh." },
00081   { ODSI_MPSFILEIO, 0010, 2, "MPS file %s %s with %d errors." },
00082   { ODSI_UNSUPFORCEDO, 6001, 1, "Attempt to force unsupported hint; %s." },
00083   { ODSI_IGNORED, 3001, 2, "Ignored unsupported hint; %s." },
00084   { ODSI_EMPTYODWSB, 6101, 1, "Empty warm start basis object." },
00085   { ODSI_NOTODWSB, 6102, 1,
00086     "The warm start basis object is not an OsiDylpWarmStartBasis object." },
00087   { ODSI_ODWSBBADSIZE, 6101, 1,
00088     "Basis size %d x %d does not match constraint system size %d x %d." },
00089   { ODSI_DUMMY_END, 999999, 0, "" }
00090 } ;
00091 
00092 static MsgDefn uk_en_defns[] = {
00093   { ODSI_TEST_MSG, 0001, 2, "Blimey, this must be the uk_en test message" },
00094   { ODSI_DUMMY_END, 999999, 0, "" }
00095 } ;
00096 
00097 /*
00098   We seem to need a dummy CoinMessages object to prevent the compiler from
00099   complaining that CoinMessages::Language is unintialised.
00100 */
00101   const CoinMessages dummy(0) ;
00102 /*
00103   The author is Canadian, eh? But we'll go with us_en anyways.
00104 */
00105   const CoinMessages::Language default_language = CoinMessages::us_en ;
00106 
00107 } /* End unnamed:file */
00108 
00120 void ODSI::setOsiDylpMessages (CoinMessages::Language local_language)
00121 
00122   
00123 { CoinMessages(sizeof(us_en_defns)/sizeof(MsgDefn)) ;
00124 
00125   messages_.setLanguage(local_language) ;
00126   strcpy(messages_.source_,"dylp");
00127 
00128 /*
00129   Yes, this is gloriously redundant, but it's set up in anticipation of
00130   future extensions.
00131 */
00132   MsgDefn *msgdefn ;
00133   switch (default_language)
00134   { case CoinMessages::us_en:
00135     { msgdefn = us_en_defns ;
00136       break ; }
00137     default:
00138     { msgdefn = us_en_defns ;
00139       break ; } }
00140 /*
00141   Open a loop to create and load the messages.
00142 */
00143   while (msgdefn->inID != ODSI_DUMMY_END)
00144   { CoinOneMessage coinmsg(msgdefn->exID,msgdefn->lvl,msgdefn->fmt) ;
00145     messages_.addMessage(msgdefn->inID,coinmsg) ;
00146     msgdefn++ ; }
00147 /*
00148   Now, if the local language differs from the default language, load any
00149   overrides. There's a trivial uk_en message set, solely for the purpose of
00150   testing language change routines.
00151 */
00152   if (local_language != default_language)
00153   { switch (local_language)
00154     { case CoinMessages::us_en:
00155       { msgdefn = us_en_defns ;
00156         break; }
00157       case CoinMessages::uk_en:
00158       { msgdefn = uk_en_defns ;
00159         break; }
00160       default:
00161       { msgdefn = us_en_defns ;
00162         break; } }
00163 
00164     while (msgdefn->inID != ODSI_DUMMY_END)
00165     { messages_.replaceMessage(msgdefn->inID,msgdefn->fmt) ;
00166       msgdefn++ ; } }
00167 
00168   return ; }
00169 
00170 
00171 #endif /* COIN_USE_DYLP */

Generated on Wed Dec 3 14:35:30 2003 for Osi by doxygen 1.3.5