Branching.java
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 package org.gecode;
00025
00026 import java.lang.reflect.*;
00027 import java.lang.reflect.Constructor;
00028 import java.lang.reflect.InvocationTargetException;
00029
00034 public abstract class Branching
00035 extends JavaBranching
00036 implements GecodeEnumConstants {
00037
00038 public Branching() {
00039 swigReleaseOwnership();
00040 }
00041
00042 public void dispose(Space home) {}
00043
00044 public final void dispose_internal(JavaSpace home) {
00045 dispose(new DummySpace(home.getCPtr(home),
00046 home.swigCMemOwn));
00047 }
00048
00051 public Branching copy(Space home, boolean share) {
00052 try {
00053 Constructor ctors[] = this.getClass().getDeclaredConstructors();
00054 if (this.getClass().getEnclosingClass() == null) {
00055 for (int i = 0; i < ctors.length; ++i) {
00056 Class<?> args[] = ctors[i].getParameterTypes();
00057 if (args.length != 3) continue;
00058 if (args[0] != Space.class) continue;
00059 if (args[1] != Boolean.class) continue;
00060 if (args[2] != this.getClass()) continue;
00061 ctors[i].setAccessible(true);
00062 return (Branching)ctors[i].newInstance(home, share, this);
00063 }
00064 } else {
00065 throw new FatalException("Nested classes must override " +
00066 "the copy(Space home, boolean share) method");
00067 }
00068 throw new NoSuchMethodException();
00069 } catch(NoSuchMethodException ex) {
00070 throw new FatalException("No suitable copy-constructor defined for "
00071 + this.getClass().getName(), ex);
00072 } catch(InstantiationException ex) {
00073 throw new FatalException("No suitable copy-constructor defined for "
00074 + this.getClass().getName(), ex);
00075 } catch(IllegalAccessException ex) {
00076 throw new FatalException("No suitable copy-constructor defined for "
00077 + this.getClass().getName(), ex);
00078 } catch(InvocationTargetException ex) {
00079 throw new FatalException("No suitable copy-constructor defined for "
00080 + this.getClass().getName(), ex);
00081 }
00082 }
00083 public JavaBranching copy_internal(JavaSpace home, boolean share) {
00084 JavaBranching ret = null;
00085 try {
00086 ret = copy(new DummySpace(home.getCPtr(home),
00087 home.swigCMemOwn), share);
00088 } catch (Throwable e) {
00089 System.err.println("Exception while copying a branching:");
00090 System.err.println(e.getMessage());
00091 e.printStackTrace();
00092 System.err.println("Exit.");
00093 System.exit(2);
00094 }
00095 return ret;
00096 }
00097 public abstract boolean status(Space home);
00098 public final boolean status_internal(JavaSpace home) {
00099 boolean ret = false;
00100 try {
00101 ret = status(new DummySpace(home.getCPtr(home), home.swigCMemOwn));
00102 } catch (Throwable e) {
00103 System.err.println("Exception while branching:");
00104 System.err.println(e.getMessage());
00105 e.printStackTrace();
00106 System.err.println("Exit.");
00107 System.exit(2);
00108 }
00109 return ret;
00110 }
00111 public abstract ExecStatus commit(Space home, JavaBranchingDesc d, long a);
00112 public final ExecStatus commit_internal(JavaSpace home, JavaBranchingDesc d, long a) {
00113 ExecStatus ret = null;
00114 try {
00115 ret = commit(new DummySpace(home.getCPtr(home),
00116 home.swigCMemOwn), d, a);
00117 } catch (Throwable e) {
00118 System.err.println("Exception while committing to a branch:");
00119 System.err.println(e.getMessage());
00120 e.printStackTrace();
00121 System.err.println("Exit.");
00122 System.exit(2);
00123 }
00124 return ret;
00125 }
00126 public abstract JavaBranchingDesc description(Space home);
00127 public final JavaBranchingDesc description_internal(JavaSpace home) {
00128 JavaBranchingDesc ret = null;
00129 try {
00130 ret = description(new DummySpace(home.getCPtr(home),
00131 home.swigCMemOwn));
00132 } catch (Throwable e) {
00133 System.err.println("Exception while computing branching description:");
00134 System.err.println(e.getMessage());
00135 e.printStackTrace();
00136 System.err.println("Exit.");
00137 System.exit(2);
00138 }
00139 return ret;
00140 }
00141 }