00001 #ifndef PATH_CONSTRAINT_CC
00002 #define PATH_CONSTRAINT_CC
00003
00004 #include<scil/scil.h>
00005 #include<LEDA/graph.h>
00006 #include<LEDA/graph_alg.h>
00007 #include<LEDA/set.h>
00008 #include<scil/constraints/path.h>
00009 #include<LEDA/p_queue.h>
00010
00011 using namespace LEDA;
00012 using namespace SCIL;
00013
00014 <<<<<<< path.cc
00015 #define VALONE 1000.0
00016 #define NT int
00017 =======
00018 #define VALONE 1000.0
00019
00020 >>>>>>> 1.3
00021
00022 class PATH::path_cutset_inequality : public cons_obj {
00023 private:
00024 graph& G;
00025 scil_map<edge>& VM;
00026 node_array<bool> cut;
00027 double rhs;
00028
00029 public:
00030
00031 path_cutset_inequality(graph& Gt, scil_map<edge>& VM_, list<node>& L)
00032 : cons_obj(Greater, 1), G(Gt), VM(VM_) {
00033 node v;
00034 cut.init(G, false);
00035 forall(v,L) cut[v]=true;
00036 }
00037
00038 void non_zero_entries(row& r) {
00039 edge e;
00040 forall_edges(e,G) {
00041 if(coeff(e)==1) r+=VM(e);
00042 }
00043 }
00044
00045 virtual
00046 ~path_cutset_inequality() {};
00047
00048 double coeff(edge e) {
00049 if(e==nil) return 0;
00050 if((cut[G.source(e)]) && (!cut[G.target(e)])) return 1;
00051 return(0);
00052 };
00053 };
00054
00055 PATH::PATH(graph& G_, node u_, node v_, scil_map<edge>& VM_)
00056
00057
00058
00059
00060 : G(G_), u(u_), v(v_), VM(VM_) {
00061 };
00062
00063 void PATH::dfs(graph& G, node u, node_array<bool>& R) {
00064 R[u]=true;
00065 edge e;
00066 forall_out_edges(e, u) if(!R[target(e)]) {
00067 dfs(G, target(e), R);
00068 };
00069 };
00070
00071 void PATH::dfs(graph& G, node u, edge_array<NT>& val, edge_array<NT>& f,
00072 node_array<bool>& R, list<node>& mc) {
00073 R[u]=true; mc.append(u);
00074 edge e;
00075 forall_out_edges(e, u) if((!R[target(e)]) && (val[e]!=f[e])) {
00076 dfs(G, target(e), val, f, R, mc);
00077 };
00078 forall_in_edges(e, u) if((!R[source(e)]) && (f[e]!=0)) {
00079 dfs(G, source(e), val, f, R, mc);
00080 };
00081 };
00082
00083 #define NT int
00084
00085 PATH::status PATH::separate(subproblem& S) {
00086
00087
00088 int i=0;
00089 edge e;
00090
00091
00092
00093 edge_array<NT> val(G);
00094 forall_edges(e, G)
00095
00096
00097
00098 val[e]=leda_max((int) (VALONE*S.value(VM(e)))+1,1);
00099
00100
00101 <<<<<<< path.cc
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 =======
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 >>>>>>> 1.3
00217
00218 edge_array<NT> f(G);
00219 MAX_FLOW(G, u, v, val, f);
00220 node_array<bool> R(G, false);
00221 list<node> mc;
00222 dfs(G, u, val, f, R, mc);
00223 if(R[v]) cout<<"ERRROR\n";
00224
00225
00226
00227 cons_obj* c=new path_cutset_inequality(G,VM,mc);
00228
00229 if (c->violated(S)) {
00230
00231 i++; S.add_basic_constraint(c, Dynamic);
00232
00233 } else delete c;
00234
00235 if(i>0) {
00236 return constraint_found;
00237 }
00238
00239 return no_constraint_found;
00240 }
00241
00242 PATH::status PATH::feasible(solution& S) {
00243 node_array<node> GtoH(G);
00244 graph H;
00245 node u1;
00246 forall_nodes(u1, G)
00247 GtoH[u1]=H.new_node();
00248 edge e;
00249 forall_edges(e,G) {
00250 if(S.value(VM(e))>0.5) H.new_edge(GtoH[source(e)], GtoH[target(e)]);
00251 }
00252 node_array<bool> R(H, false);
00253 dfs(H, GtoH[u], R);
00254 if (R[GtoH[v]]) return feasible_solution;
00255 return infeasible_solution;
00256 };
00257
00258 #undef VALONE
00259
00260 #endif