Atualizado: 13/12/2011
No. | T1 | T2 | T3 | T4 | T5 |
---|---|---|---|---|---|
152985 | - | - | - | - | - |
159011 | - | - | - | - | - |
159098 | P | P | P | P | R |
171359 | P | P | P | P | R |
172072 | P | P | P | P | - |
173256 | P | P | P | - | - |
173361 | P | P | P | P | - |
180658 | P | P | P | P | - |
180689 | P | P | - | - | - |
R = recebido P = avaliado e publicado
Entrega: 26/08/2011
> ./dijkstra 1 2 < NY.gr 803
/** * \file gen.cpp * \author Marcus Ritt <mrpritt@inf.ufrgs.br> * \version $Id: emacs 2872 2009-01-31 01:46:50Z ritt $ * \date Time-stamp: <2011-08-24 15:17:49 ritt> */ #include <iostream> #include <cassert> using namespace std; #include <boost/graph/adjacency_list.hpp> #include <boost/graph/connected_components.hpp> #include <boost/graph/dijkstra_shortest_paths.hpp> using namespace boost; // information stored in vertices struct VertexInformation { unsigned component; }; // information stored in edges struct EdgeInformation { unsigned weight; }; const unsigned maxweight = 1000; // graph is an adjacency list represented by vectors typedef adjacency_list<vecS, vecS, directedS,VertexInformation,EdgeInformation> Graph; typedef graph_traits<Graph>::vertex_descriptor Node; typedef graph_traits <Graph>::edge_descriptor Edge; int main(int argc, char *argv[]) { assert(argc == 3); unsigned n = atoi(argv[1]); double p = atof(argv[2]); srand48(time(0)); // (1) generate random graph Graph g; for(unsigned i=0; i<n; i++) add_vertex(g); for(unsigned i=0; i<n; i++) for(unsigned j=0; j<n; j++) if (i != j && drand48() < p) { Edge e = add_edge(i,j,g).first; g[e].weight = lrand48()%maxweight; } // (2) print example path unsigned src = lrand48()%num_vertices(g); unsigned dst = lrand48()%num_vertices(g); vector<unsigned> dist(n); vector<unsigned> pred(n); dijkstra_shortest_paths(g,src,weight_map(get(&EdgeInformation::weight,g)).distance_map(&dist[0]).predecessor_map(&pred[0])); cerr << "Distance between " << src+1 << " and " << dst+1 << " is " << dist[dst] << endl; // (3) print out in DIMACS challenge format cout << "p sp " << num_vertices(g) << " " << num_edges(g) << endl; graph_traits<Graph>::edge_iterator eb, ee; for ( tie(eb, ee)=edges(g); eb != ee; eb++) cout << "a " << source(*eb,g)+1 << " " << target(*eb, g)+1 << " " << g[*eb].weight << endl; }
Entrega: 02/09/2011
Entrega: 26/09/2011
To use: cc washington.c -o gengraph gengraph function arg1 arg2 arg3 Command line arguments have the following meanings: function: index of desired graph type arg1, arg2, arg3: meanings depend on graph type (briefly listed below: see code comments for more info) Mesh Graph: 1 rows cols maxcapacity Random Level Graph: 2 rows cols maxcapacity Random 2-Level Graph:3 rows cols maxcapacity Matching Graph: 4 vertices degree Square Mesh: 5 side degree maxcapacity Basic Line: 6 rows cols degree Exponential Line: 7 rows cols degree Double Exponential 8 rows cols degree DinicBadCase: 9 vertices (causes n augmentation phases) GoldBadCase 10 vertices Cheryian 11 dim1 dim2 range (last 2 are bad for goldberg's algorithm)
No. | Nome | Parâmetros | Descrição | n | m |
---|---|---|---|---|---|
1 | Mesh | r,c | Grade, 3 viz. 1 direita | rc+2 | 3r(c-1) |
2 | Random level | r,c | Grade, 3 viz. rand. 1 direita | rc+2 | 3r(c-1) |
3 | Random 2-level | r,c | Grade, 3 viz. rand. 2 direita | rc+2 | 3r(c-1) |
4 | Matching | n,d | Bipart. n-n, d viz. rand. | 2n+2 | n(d+2) |
5 | Square Mesh | d,D | Quadr. mesh dxd, grau D | d*d+2 | (d-1)dD+2d |
6 | BasicLine | n,m,D | Linha, grau D | nm+2 | nmD+2m |
7 | ExpLine | n,m,D | Linha, grau D | nm+2 | nmD+2m |
8 | DExpLine | n,m,D | Linha, grau D | nm+2 | nmD+2m |
9 | DinicBad | n | Linha | n | 2n-3 |
10 | GoldBad | n | 3n+3 | 4n+1 |
/** * \file maxflow.cpp * \author Marcus Ritt <mrpritt@inf.ufrgs.br> * \version $Id: emacs 2872 2009-01-31 01:46:50Z ritt $ * \date Time-stamp: <2009-03-23 17:52:25 ritt> * * Read a maximum flow problem in DIMACS format and output the maximum flow. * */ #include <iostream> #include <cstring> using namespace std; #include <boost/graph/adjacency_list.hpp> #include <boost/graph/read_dimacs.hpp> #include <boost/graph/edmunds_karp_max_flow.hpp> using namespace boost; // a directed graph with reverse edges struct VertexInformation {}; struct EdgeInformation; typedef adjacency_list<vecS,vecS,directedS,VertexInformation,EdgeInformation> DiGraph; typedef graph_traits<DiGraph>::edge_descriptor Edge; typedef graph_traits<DiGraph>::vertex_descriptor DiNode; typedef unsigned Capacity; struct EdgeInformation { Capacity edge_capacity; Capacity edge_residual_capacity; Edge reverse_edge; }; int main(int argc, char *argv[]) { // (0) read graph DiGraph g; DiNode s,t; read_dimacs_max_flow(g, get(&EdgeInformation::edge_capacity,g), get(&EdgeInformation::reverse_edge,g), s, t); // (1) determine maximum flow cout << edmonds_karp_max_flow(g, s, t, capacity_map(get(&EdgeInformation::edge_capacity,g)). residual_capacity_map(get(&EdgeInformation::edge_residual_capacity,g)). reverse_edge_map(get(&EdgeInformation::reverse_edge,g))) << endl; }
Entrega: 10/10/2011
// image data structure enum { R = 0, G, B }; typedef unsigned short Color; typedef multi_array<Color,3> Image; // read an image im PPM (plain) format void read_ppm(Image& im, istream& in) { unsigned w,h,maxcolor; string magic; in >> magic >> w >> h >> maxcolor; assert(magic == "P3"); im.resize(extents[h][w][3]); for(unsigned i=0; i<h; i++) for(unsigned j=0; j<w; j++) in >> im[i][j][R] >> im[i][j][G] >> im[i][j][B]; }
cout << "P3 " << w << " " << h << " 255 " << endl; for(unsigned i=0; i<h; i++) { for(unsigned j=0; j<w; j++) cout << im[i][j][R] << " " << im[i][j][G] << " " << im[i][j][B] << " "; cout << endl; }
convert -compress none myimage.ext myimage.ppm
// mixture of Gaussians, according to Jones, Regh const unsigned nG = 16; const unsigned nV = 7; double skin[nG][nV] = { { 73.53, 29.94, 17.76, 765.40, 121.44, 112.80, 0.0294 }, { 249.71, 233.94, 217.49, 39.94, 154.44, 396.05, 0.0331 }, { 161.68, 116.25, 96.95, 291.03, 60.48, 162.85, 0.0654 }, { 186.07, 136.62, 114.40, 274.95, 64.60, 198.27, 0.0756 }, { 189.26, 98.37, 51.18, 633.18, 222.40, 250.69, 0.0554 }, { 247.00, 152.20, 90.84, 65.23, 691.53, 609.92, 0.0314 }, { 150.10, 72.66, 37.76, 408.63, 200.77, 257.57, 0.0454 }, { 206.85, 171.09, 156.34, 530.08, 155.08, 572.79, 0.0469 }, { 212.78, 152.82, 120.04, 160.57, 84.52, 243.90, 0.0956 }, { 234.87, 175.43, 138.94, 163.80, 121.57, 279.22, 0.0763 }, { 151.19, 97.74, 74.59, 425.40, 73.56, 175.11, 0.1100 }, { 120.52, 77.55, 59.82, 330.45, 70.34, 151.82, 0.0676 }, { 192.20, 119.62, 82.32, 152.76, 92.14, 259.15, 0.0755 }, { 214.29, 136.08, 87.24, 204.90, 140.17, 270.19, 0.0500 }, { 99.57, 54.33, 38.06, 448.13, 90.18, 151.29, 0.0667 }, { 238.88, 203.08, 176.91, 178.38, 156.27, 404.99, 0.0749 } }; double noskin[nG][nV] = { { 254.37, 254.41, 253.82, 2.77, 2.81, 5.46, 0.0637 }, { 9.39, 8.09, 8.52, 46.84, 33.59, 32.48, 0.0516 }, { 96.57, 96.95, 91.53, 280.69, 156.79, 436.58, 0.0864 }, { 160.44, 162.49, 159.06, 355.98, 115.89, 591.24, 0.0636 }, { 74.98, 63.23, 46.33, 414.84, 245.95, 361.27, 0.0747 }, { 121.83, 60.88, 18.31, 2502.24, 1383.53, 237.18, 0.0365 }, { 202.18, 154.88, 91.04, 957.42, 1766.94, 1582.52, 0.0349 }, { 193.06, 201.93, 206.55, 562.88, 190.23, 447.28, 0.0649 }, { 51.88, 57.14, 61.55, 344.11, 191.77, 433.40, 0.0656 }, { 30.88, 26.84, 25.32, 222.07, 118.65, 182.41, 0.1189 }, { 44.97, 85.96, 131.95, 651.32, 840.52, 963.67, 0.0362 }, { 236.02, 236.27, 230.70, 225.03, 117.29, 331.95, 0.0849 }, { 207.86, 191.20, 164.12, 494.04, 237.69, 533.52, 0.0368 }, { 99.83, 148.11, 188.17, 955.88, 654.95, 916.70, 0.0389 }, { 135.06, 131.92, 123.10, 350.35, 130.30, 388.43, 0.0943 }, { 135.96, 103.89, 66.88, 806.44, 642.20, 350.36, 0.0477 } }; double skin_value(Color R, Color G, Color B) { double r = 0; for(unsigned i=0; i<nG; i++) { double t; t = pow(double(R)-skin[i][0],2)/skin[i][3] + pow(double(G)-skin[i][1],2)/skin[i][4] + pow(double(B)-skin[i][2],2)/skin[i][5]; t = skin[i][6]*exp(-t/2) / (pow(2*M_PI,1.5) * sqrt(skin[i][3]*skin[i][4]*skin[i][5])); r += t; } return r; } double noskin_value(Color R, Color G, Color B) { double r = 0; for(unsigned i=0; i<nG; i++) { double t; t = pow(double(R)-noskin[i][0],2)/noskin[i][3] + pow(double(G)-noskin[i][1],2)/noskin[i][4] + pow(double(B)-noskin[i][2],2)/noskin[i][5]; t = noskin[i][6]*exp(-t/2) / (pow(2*M_PI,1.5) * sqrt(noskin[i][3]*noskin[i][4]*noskin[i][5])); r += t; } return r; }
Entrega: 12/12/2011