I have the following C library: http://www.irisa.fr/polylib/
I would like to run its Domain union and Domain intersection functions in R.
Can someone show me the code to write in R or C to get it done fast?
The code source of the first function I'd like to use is:
/*
* Return the intersection of two polyhedral domains 'Pol1' and 'Pol2'.
* The maximum allowed rays in the new polyhedron generated is 'NbMaxRays'.
*/
Polyhedron *DomainIntersection(Polyhedron *Pol1,Polyhedron *Pol2,unsigned NbMaxRays) {
Polyhedron *p1, *p2, *p3, *d;
if (!Pol1 || !Pol2) return (Polyhedron*) 0;
if (Pol1->Dimension != Pol2->Dimension) {
errormsg1( "DomainIntersection", "diffdim",
"operation on different dimensions");
return (Polyhedron*) 0;
}
/* For every polyhedron pair (p1,p2) where p1 belongs to domain Pol1 and */
/* p2 belongs to domain Pol2, compute the intersection and add it to the */
/* new domain 'd'. */
d = (Polyhedron *)0;
for (p1=Pol1; p1; p1=p1->next) {
for (p2=Pol2; p2; p2=p2->next) {
p3 = AddConstraints(p2->Constraint[0],
p2->NbConstraints, p1, NbMaxRays);
d = AddPolyToDomain(p3,d);
}
}
if (!d)
return Empty_Polyhedron(Pol1->Dimension);
else
return d;
} /* DomainIntersection */
Is there a way to create an R function similarly to the following?
add <- cfunction(c(a = "integer", b = "integer"), "
SEXP result = PROTECT(allocVector(REALSXP, 1));
REAL(result)[0] = asReal(a) + asReal(b);
UNPROTECT(1);
return result;
")
add(1, 5)