Hitandrun contraints not working

I'm trying to generate uniform random numbers using the hitandrun package of R. I use inequalities and equalities contraints. That is my code:

library(hitandrun)

ineq.constr<-mergeConstraints(lowerBoundConstraint(16,1,0),upperBoundConstraint(16,1,1))
for(i in 2:16){
ineq.constr<-mergeConstraints(ineq.constr,
lowerBoundConstraint(16,i,0),upperBoundConstraint(16,i,1))
}
add.constr<- mergeConstraints(
list(constr= c(1,1,1,-1,-1,-1,-1,1,-1,-1,-1,1,1,1,1,-1), dir='<=', rhs=4),
list(constr= c(-1,-1,-1,1,1,1,1,-1,1,1,1,-1,-1,-1,-1,1), dir='<=', rhs=-2))
ineq.constr<-mergeConstraints(ineq.constr,add.constr)

eq.constr<- mergeConstraints(
list(constr= c(1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0), dir='=', rhs=1),
list(constr= c(0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0), dir='=', rhs=1),
list(constr= c(0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0), dir='=', rhs=1),
list(constr= c(0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1), dir='=', rhs=1),
list(constr= c(1,-1,0,0,1,-1,0,0,0,0,0,0,0,0,0,0), dir='=', rhsh=0),
list(constr= c(0,0,1,-1,0,0,1,-1,0,0,0,0,0,0,0,0), dir='=', rhsh=0),
list(constr= c(0,0,0,0,0,0,0,0,1,-1,0,0,1,-1,0,0), dir='=', rhsh=0),
list(constr= c(0,0,0,0,0,0,0,0,0,0,1,-1,0,0,1,-1), dir='=', rhsh=0),
list(constr= c(1,0,-1,0,0,0,0,0,1,0,-1,0,0,0,0,0), dir='=', rhsh=0),
list(constr= c(0,1,0,-1,0,0,0,0,0,1,0,-1,0,0,0,0), dir='=', rhsh=0),
list(constr= c(0,0,0,0,1,0,-1,0,0,0,0,0,1,0,-1,0), dir='=', rhsh=0),
list(constr= c(0,0,0,0,0,1,0,-1,0,0,0,0,0,1,0,-1), dir='=', rhsh=0))
constr<-mergeConstraints(ineq.constr, eq.constr)
samples <- hitandrun(constr, n.samples=2000000)
stopifnot(dim(samples) == c(2000000, 16))
df<-matrix(unlist(samples), nrow=2000000, ncol=16)
df<-data.frame(df)
write.table(df, file="har_samples.txt", row.names=FALSE, col.names=FALSE)

All the constraints seems to be working except for this one (if i remove the following lines nothing changes):

add.constr<- mergeConstraints(
list(constr= c(1,1,1,-1,-1,-1,-1,1,-1,-1,-1,1,1,1,1,-1), dir='<=', rhs=4),
list(constr= c(-1,-1,-1,1,1,1,1,-1,1,1,1,-1,-1,-1,-1,1), dir='<=', rhs=-2))
ineq.constr<-mergeConstraints(ineq.constr,add.constr)

I am sure that the constraints are compatible can someone help?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.