Skip to content

Commit

Permalink
rounding excludes agreements that do not observe the constraint of ma…
Browse files Browse the repository at this point in the history
…ximum order
  • Loading branch information
olivierch committed Apr 8, 2012
1 parent 6386985 commit 7bf7361
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 38 deletions.
10 changes: 9 additions & 1 deletion src/flowc.c
Expand Up @@ -532,7 +532,15 @@ static bool _rounding(double *fluxExact, Tchemin *pchemin) {
* the cycle exhausts the box
* Omega ~= 1.0
*/

if(!box->lastignore) {
short _kp = _dim-1;

obMRange(_k,_dim) {
if(pchemin->no[_k].omega < ((double) _flowNodes[_k]) / ((double) _flowNodes[_kp]))
goto _continue;
_kp = _k;
}
}

// choose the best
/***************************************************************/
Expand Down
8 changes: 5 additions & 3 deletions src/sql/model.sql
Expand Up @@ -741,6 +741,7 @@ BEGIN
RETURN;
END;
$$ LANGUAGE PLPGSQL;

--------------------------------------------------------------------------------
CREATE FUNCTION fcreate_tmp(_id int,_ord yorder,_np int,_nr int) RETURNS int AS $$
DECLARE
Expand Down Expand Up @@ -784,7 +785,7 @@ $$ LANGUAGE PLPGSQL;

CREATE FUNCTION fexecute_flow(_flw yflow) RETURNS int AS $$
DECLARE
_commits int[][];
_commits int8[][];
_i int;
_next_i int;
_nbcommit int;
Expand Down Expand Up @@ -1546,9 +1547,10 @@ BEGIN
END IF;

-- _o.qtt_prov/_o.qtt_requ < _mvt.qtt/_mvtprec.qtt
IF((_o.qtt_prov * _mvtprec.qtt) < (_mvt.qtt * _o.qtt_requ)) THEN
IF(((_o.qtt_prov::float8) / (_o.qtt_requ::float8)) < ((_mvt.qtt::float8)/(_mvtprec.qtt::float8))) THEN
RAISE INFO 'order %->%, with mvt %->%',_o.qtt_requ,_o.qtt_prov,_mvtprec.qtt,_mvt.qtt;
RAISE INFO 'orderid %, with mvtid %->%',_o.id,_mvtprec.id,_mvt.id;
RAISE INFO '% < 1; should be >=1',(((_o.qtt_prov::float8) / (_o.qtt_requ::float8)) / ((_mvt.qtt::float8)/(_mvtprec.qtt::float8)));
RAISE INFO 'order.uuid %, with mvtid %->%',_o.uuid,_mvtprec.id,_mvt.id;
RETURN 1;
END IF;

Expand Down
91 changes: 57 additions & 34 deletions src/yflow.c
Expand Up @@ -330,21 +330,39 @@ static bool _yflow_follow(int32 maxlen,Torder *o,Tflow *f, bool before) {
if (o->np != f->x[0].nr)
return false;

// cycle
// unexpected cycle
obMRange(i,dim-1)
if(f->x[i].np == o->nr)
return false;

// not yet an expected cycle
if(f->x[dim-1].np != o->nr)
return true;
} else {
// not end(f) -> o
if(f->x[dim-1].np != o->nr)
return false;

// cycle
// unexpected cycle
obMRange(i,dim-1)
if(o->np == f->x[i+1].nr)
return false;

// not yet an expected cycle
if(o->np != f->x[dim-1].nr)
return true;
}
// return true;
// it is an expected cycle
{
double _om = 1.;
obMRange(i,dim)
_om *= ((double)(f->x[i].qtt_prov)) / ((double)(f->x[i].qtt_requ));
_om *= ((double)(o->qtt_prov)) / ((double)(o->qtt_requ));

return (_om >= 1.);
}
return true;

}
/******************************************************************************
yflow_follow(int,yorder,yflow)
Expand Down Expand Up @@ -429,8 +447,8 @@ if (f and fr are drafts)
if (f or fr is not in (empty,draft))
error
******************************************************************************/
#define FLOWISDOE(f) (((f)->status == draft) || ((f)->status == empty))
#define FLOWAREDOE(f1,f2) (FLOWISDOE(f1) && FLOWISDOE(f2))
#define FLOWISDOEU(f) (((f)->status == draft) || ((f)->status == empty) || ((f)->status == undefined))
#define FLOWAREDOEU(f1,f2) (FLOWISDOEU(f1) && FLOWISDOEU(f2))


Datum yflow_reduce(PG_FUNCTION_ARGS)
Expand All @@ -443,6 +461,11 @@ Datum yflow_reduce(PG_FUNCTION_ARGS)
r = Ndbox_init(FLOW_MAX_DIM);
memcpy(r,f,sizeof(Tflow));

if (!FLOWAREDOEU(r,fr))
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("yflow_reduce: flows should be draft,undefined or empty;%s and %s instead",yflow_statusBoxToStr(r),yflow_statusBoxToStr(fr))));

if(r->status == draft && fr->status == draft) {
short _dim;

Expand All @@ -459,12 +482,8 @@ Datum yflow_reduce(PG_FUNCTION_ARGS)
}
}
(void) flowc_maximum(r);
}

if (!FLOWAREDOE(r,fr))
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("yflow_reduce: flows should be draft or empty")));
}

PG_RETURN_TFLOW(r);

Expand All @@ -489,42 +508,46 @@ Datum yflow_maxg(PG_FUNCTION_ARGS)
Tflow *f1 = PG_GETARG_TFLOW(0);
Tflow *f2 = PG_GETARG_TFLOW(1);

if(!FLOWAREDOE(f1,f2))
if(!FLOWAREDOEU(f1,f2))
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("yflow_maxg: the flow should be draft or empty")));

if(f1->status == empty)
PG_RETURN_TFLOW(f2); // f2 is draft or empty
else if(f2->status == empty) // f1 draft and f2 empty
PG_RETURN_TFLOW(f1);
errmsg("yflow_maxg: flows should be draft,undefined or empty;%s and %s instead",yflow_statusBoxToStr(f1),yflow_statusBoxToStr(f2))));


// f1 and f2 are draft
if( // for the last partner, qtt_prov(f1)/qtt_requ(f1) > qtt_prov(f2)/qtt_requ(f2)
FLOW_LAST_OMEGA(f1) > FLOW_LAST_OMEGA(f2)
) PG_RETURN_TFLOW(f2);
else PG_RETURN_TFLOW(f1);
if ((f1->status == draft) && (f2->status == draft)) {

if( // for the last partner, qtt_prov(f1)/qtt_requ(f1) > qtt_prov(f2)/qtt_requ(f2)
FLOW_LAST_OMEGA(f1) > FLOW_LAST_OMEGA(f2)
) PG_RETURN_TFLOW(f2);
else PG_RETURN_TFLOW(f1);

} else if(f1->status == draft)
PG_RETURN_TFLOW(f1);
else
PG_RETURN_TFLOW(f2);
}
Datum yflow_ming(PG_FUNCTION_ARGS)
{
Tflow *f1 = PG_GETARG_TFLOW(0);
Tflow *f2 = PG_GETARG_TFLOW(1);

if(!FLOWAREDOE(f1,f2))
if(!FLOWAREDOEU(f1,f2))
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("yflow_ming: the flow should be draft or empty")));
errmsg("yflow_ming: the flow should be draft,undefined or empty")));

if(f1->status == empty)
PG_RETURN_TFLOW(f2); // f2 is draft or empty
else if(f2->status == empty) // f1 draft and f2 empty
PG_RETURN_TFLOW(f1);

// f1 and f2 are draft
if( // for the last partner, qtt_prov(f1)/qtt_requ(f1) < qtt_prov(f2)/qtt_requ(f2)
FLOW_LAST_OMEGA(f1) < FLOW_LAST_OMEGA(f2)
) PG_RETURN_TFLOW(f2);
else PG_RETURN_TFLOW(f1);
if ((f1->status == draft) && (f2->status == draft)) {

if( // for the last partner, qtt_prov(f1)/qtt_requ(f1) < qtt_prov(f2)/qtt_requ(f2)
FLOW_LAST_OMEGA(f1) < FLOW_LAST_OMEGA(f2)
) PG_RETURN_TFLOW(f2);
else PG_RETURN_TFLOW(f1);

} else if(f1->status == draft)
PG_RETURN_TFLOW(f1);
else
PG_RETURN_TFLOW(f2);
}
/******************************************************************************
aggregate function yflow_max(yflow)
Expand Down Expand Up @@ -584,7 +607,7 @@ Datum yflow_status(PG_FUNCTION_ARGS)
}
}
/******************************************************************************
// always returns 1. !!!!!
// always returns 1. NORMAL!!!!
******************************************************************************/
Datum yflow_flr_omega(PG_FUNCTION_ARGS)
{
Expand Down

0 comments on commit 7bf7361

Please sign in to comment.