/farmR/src/java/src/jfm/lp/LPX.java

https://code.google.com/p/javawfm/ · Java · 81 lines · 56 code · 11 blank · 14 comment · 6 complexity · 645eec749a252e1a225cb04acdd97248 MD5 · raw file

  1. package jfm.lp;
  2. import java.util.HashMap;
  3. import jfm.xml.XMLSyntaxException;
  4. /** \internal row and column bound types defined in the C headers for glpk
  5. * It is essential to ensure that the same integer
  6. * values are used in this class and in the header file glpk.h. A quick check should be
  7. * made whenever upgrading to a new version of glpk. This class is valid for glpk-4.23 */
  8. public enum LPX {
  9. /** Free variable */
  10. LPX_FR (110,"lpx_fr"),
  11. /** Variable with lower bound */
  12. LPX_LO (111,"lpx_lo"),
  13. /** Variable with upper bound */
  14. LPX_UP (112,"lpx_up"),
  15. /** Double bounded (upper and lower) variable */
  16. LPX_DB (113,"lpx_db"),
  17. /** Fixed variable */
  18. LPX_FX (114,"lpx_fx"),
  19. LPX_LP (100,"lpx_lp"),
  20. LPX_MIP (101,"lpx_mip"),
  21. LPX_CV (160,"lpx_cv"),
  22. LPX_IV (161,"lpx_iv"),
  23. LPX_TERMON (1,"lpx_termon"),
  24. LPX_TERMOFF(0,"lpx_termoff"),
  25. // Status variables
  26. LPX_NOTOPT(179,"lpx_notopt"),
  27. LPX_OPT (180,"lpx_opt"),// solution is optimal
  28. LPX_FEAS (181,"lpx_feas"), //solution is feasible;
  29. LPX_INFEAS (182,"lpx_infeas"),//solution is infeasible;
  30. LPX_NOFEAS (183,"lpx_nofeas"),// problem has no feasible solution;
  31. LPX_UNBND (184,"lpx_unbnd"),//problem has unbounded solution;
  32. LPX_UNDEF (185,"lpx_undef");
  33. /** The integer corresponding to this enum which corresponds to the definition in glpk.h */
  34. private final int toCPP;
  35. public final String xmlname;
  36. private LPX(int intequiv,String xmln){
  37. toCPP=intequiv;
  38. xmlname=xmln;
  39. }
  40. /** The integer value corresponding to this LPX row or column type to
  41. * be used in C++ code */
  42. public int toCPP(){return toCPP;};
  43. /** Return the LPX enum corresponding to an xml string of the same name */
  44. public static LPX xmlToGLPKType(String str) throws XMLSyntaxException {
  45. if (xmlToGLPKType.containsKey(str)){
  46. return xmlToGLPKType.get(str);
  47. } else {
  48. throw new XMLSyntaxException("The string "+str+" does not correspond to a LPX type");
  49. }
  50. }
  51. public static LPX intToGLPKType(int iglpk) {
  52. if (intToGLPKType.containsKey(iglpk)){
  53. return intToGLPKType.get(iglpk);
  54. } else {
  55. throw new Error("The integer "+iglpk+" does not correspond to a LPX type");
  56. }
  57. }
  58. private static HashMap<Integer,LPX> intToGLPKType=new HashMap<Integer,LPX>();
  59. static {
  60. for(LPX lt:LPX.values()){
  61. intToGLPKType.put(lt.toCPP, lt);
  62. }
  63. }
  64. private static HashMap<String,LPX>xmlToGLPKType =new HashMap<String,LPX>();
  65. static{
  66. for(LPX lt:LPX.values()){
  67. xmlToGLPKType.put(lt.xmlname, lt);
  68. }
  69. }
  70. }