| 1 |
#ifndef lint
|
| 2 |
static const char RCSid[] = "$Id$";
|
| 3 |
#endif
|
| 4 |
/*
|
| 5 |
* Compute mass transport plan for RBF lobes
|
| 6 |
*/
|
| 7 |
|
| 8 |
#define _USE_MATH_DEFINES
|
| 9 |
#include <stdio.h>
|
| 10 |
#include <string.h>
|
| 11 |
#include "transportSimplex.h"
|
| 12 |
#include "bsdfrep.h"
|
| 13 |
|
| 14 |
using namespace t_simplex;
|
| 15 |
using namespace std;
|
| 16 |
|
| 17 |
/* Compute mass transport plan (internal call) */
|
| 18 |
extern "C" void
|
| 19 |
plan_transport(MIGRATION *mig)
|
| 20 |
{
|
| 21 |
double src[mtx_nrows(mig)];
|
| 22 |
double dst[mtx_ncols(mig)];
|
| 23 |
TsSignature<RBFVAL> srcSig(mtx_nrows(mig), mig->rbfv[0]->rbfa, src);
|
| 24 |
TsSignature<RBFVAL> dstSig(mtx_ncols(mig), mig->rbfv[1]->rbfa, dst);
|
| 25 |
TsFlow flow[mtx_nrows(mig)+mtx_ncols(mig)-1];
|
| 26 |
int n;
|
| 27 |
/* clear flow matrix */
|
| 28 |
memset(mig->mtx, 0, sizeof(float)*mtx_nrows(mig)*mtx_ncols(mig));
|
| 29 |
/* set supplies & demands */
|
| 30 |
for (n = mtx_nrows(mig); n--; )
|
| 31 |
src[n] = rbf_volume(&mig->rbfv[0]->rbfa[n]) /
|
| 32 |
mig->rbfv[0]->vtotal;
|
| 33 |
for (n = mtx_ncols(mig); n--; )
|
| 34 |
dst[n] = rbf_volume(&mig->rbfv[1]->rbfa[n]) /
|
| 35 |
mig->rbfv[1]->vtotal;
|
| 36 |
|
| 37 |
n = 0; /* minimize EMD */
|
| 38 |
transportSimplex(&srcSig, &dstSig, &lobe_distance, flow, &n);
|
| 39 |
|
| 40 |
while (n-- > 0) /* assign sparse matrix */
|
| 41 |
mtx_coef(mig, flow[n].from, flow[n].to) = flow[n].amount;
|
| 42 |
}
|