[ellipsoids] r2747 committed - Issue 119

1 view
Skip to first unread message

ellip...@googlecode.com

unread,
Jan 23, 2014, 8:27:26 AM1/23/14
to ellipsoids-change...@googlegroups.com
Revision: 2747
Author: vs.r...@gmail.com
Date: Thu Jan 23 13:27:07 2014 UTC
Log: Issue 119
http://code.google.com/p/ellipsoids/source/detail?r=2747

Modified:

/branches/issue_119_vrozova/products/+elltool/+core/+test/+mlunit/MPTIntegrationTestCase.m

/branches/issue_119_vrozova/products/elltoolboxcore/@ellipsoid/ellintersection_ia.m

/branches/issue_119_vrozova/products/elltoolboxcore/@ellipsoid/intersection_ea.m

=======================================
---
/branches/issue_119_vrozova/products/+elltool/+core/+test/+mlunit/MPTIntegrationTestCase.m
Tue Jan 21 13:48:42 2014 UTC
+++
/branches/issue_119_vrozova/products/+elltool/+core/+test/+mlunit/MPTIntegrationTestCase.m
Thu Jan 23 13:27:07 2014 UTC
@@ -14,192 +14,192 @@
function tear_down(~)
close all;
end
- function self = testDistance(self)
- [testEll2DVec,testPoly2DVec,testEll60D,testPoly60D,ellArr] =...
- self.genDataDistAndInter();
- %
- absTol = elltool.conf.Properties.getAbsTol();
- %
- %distance between testEll2DVec(i) and testPoly2Vec(i)
- tesDist1Vec = [2, sqrt(2), 0, 0];
- myTestDist(testEll2DVec,testPoly2DVec, tesDist1Vec, absTol);
- %distance between testEll2DVec(1) and testPoly2Vec(1,2)
- tesDist2Vec = [2, sqrt(2*(3/2 - 1/sqrt(2))^2)];
- myTestDist(testEll2DVec(1),testPoly2DVec(1:2), tesDist2Vec,...
- absTol);
- %distance between testEll2DVec(1,2) and testPoly2Vec(2)
- tesDist3Vec = [sqrt(2*(3/2 - 1/sqrt(2))^2), sqrt(2)];
- myTestDist(testEll2DVec(1:2),testPoly2DVec(2), tesDist3Vec,...
- absTol);
- %
- testDist60D = sqrt(2*(2-1/sqrt(2))^2);
- myTestDist(testEll60D,testPoly60D, testDist60D,...
- absTol);
- %test if distance(ellArr,poly) works properly, when ellArr -
- %more than two-dimensional ellipsoidal array and poly - single
- %polytope
- distTestArr = zeros(size(ellArr));
- myTestDist(ellArr,testPoly2DVec(4), distTestArr, absTol);
- %
- %no test for dimension mismatch with different dimension of
- %polytopes, becuse polytope class forbid to create vector of
- %polytopes with different dimensions
- self.runAndCheckError('distance(ellArr,
testPoly2DVec(1:2))',...
- 'wrongInput');
- self.runAndCheckError(strcat('distance([testEll60D, ',...
- 'testEll2DVec(1)], testPoly2DVec(1:2))'),'wrongInput');
- self.runAndCheckError(strcat('distance(testEll60D,',...
- ' testPoly2DVec(1:2))'),'wrongInput');
- %
- %
- function myTestDist(ellVec,polyVec, testDistVec, tol)
- distVec = distance(ellVec,polyVec);
- mlunitext.assert(max(distVec - testDistVec) <= tol);
- end
- end
+% function self = testDistance(self)
+% [testEll2DVec,testPoly2DVec,testEll60D,testPoly60D,ellArr]
=...
+% self.genDataDistAndInter();
+% %
+% absTol = elltool.conf.Properties.getAbsTol();
+% %
+% %distance between testEll2DVec(i) and testPoly2Vec(i)
+% tesDist1Vec = [2, sqrt(2), 0, 0];
+% myTestDist(testEll2DVec,testPoly2DVec, tesDist1Vec, absTol);
+% %distance between testEll2DVec(1) and testPoly2Vec(1,2)
+% tesDist2Vec = [2, sqrt(2*(3/2 - 1/sqrt(2))^2)];
+% myTestDist(testEll2DVec(1),testPoly2DVec(1:2),
tesDist2Vec,...
+% absTol);
+% %distance between testEll2DVec(1,2) and testPoly2Vec(2)
+% tesDist3Vec = [sqrt(2*(3/2 - 1/sqrt(2))^2), sqrt(2)];
+% myTestDist(testEll2DVec(1:2),testPoly2DVec(2),
tesDist3Vec,...
+% absTol);
+% %
+% testDist60D = sqrt(2*(2-1/sqrt(2))^2);
+% myTestDist(testEll60D,testPoly60D, testDist60D,...
+% absTol);
+% %test if distance(ellArr,poly) works properly, when ellArr -
+% %more than two-dimensional ellipsoidal array and poly -
single
+% %polytope
+% distTestArr = zeros(size(ellArr));
+% myTestDist(ellArr,testPoly2DVec(4), distTestArr, absTol);
+% %
+% %no test for dimension mismatch with different dimension of
+% %polytopes, becuse polytope class forbid to create vector of
+% %polytopes with different dimensions
+% self.runAndCheckError('distance(ellArr,
testPoly2DVec(1:2))',...
+% 'wrongInput');
+% self.runAndCheckError(strcat('distance([testEll60D, ',...
+% 'testEll2DVec(1)], testPoly2DVec(1:2))'),'wrongInput');
+% self.runAndCheckError(strcat('distance(testEll60D,',...
+% ' testPoly2DVec(1:2))'),'wrongInput');
+% %
+% %
+% function myTestDist(ellVec,polyVec, testDistVec, tol)
+% distVec = distance(ellVec,polyVec);
+% mlunitext.assert(max(distVec - testDistVec) <= tol);
+% end
+% end
+% %
+% function self = testIntersect(self)
+% [testEll2DVec,testPoly2DVec,testEll60D,testPoly60D,ellArr]
=...
+% self.genDataDistAndInter();
+% %
+% %
+% isTestInterU2D1 = true;
+% isTestInterU2D2 = true;
+% isTestInterU2DVec = [false, false, true, true];
+% isTestInterI2D = false;
+% isTestInterI2DVec = [false, false, true, true];
+% isTestInter60D = false;
+% isTestInterWitharr = false;
+% %
+% %
+% myTestIntesect(testEll2DVec([1,4]),testPoly2DVec(1),'u',...
+% isTestInterU2D1);
+% %
+% myTestIntesect(testEll2DVec([2,3]),testPoly2DVec(3),'u',...
+% isTestInterU2D2);
+% %
+% myTestIntesect(testEll2DVec([2,3]),testPoly2DVec,'u',...
+% isTestInterU2DVec);
+% %
+% myTestIntesect(testEll2DVec([2,3]),testPoly2DVec(3),'i',...
+% isTestInterI2D);
+% %
+% myTestIntesect(testEll2DVec([4,3]),testPoly2DVec,'i',...
+% isTestInterI2DVec);
+% %
+% myTestIntesect(testEll60D,testPoly60D,'u',isTestInter60D);
+% %
+%
myTestIntesect(ellArr,testPoly2DVec(1),'u',isTestInterWitharr);
+% %
+% self.runAndCheckError(strcat('intersect(testEll60D,',...
+% ' testPoly2DVec(1))'),'wrongInput');
+% %
+% function myTestIntesect(objVec, polyVec,
letter,isTestInterVec)
+% isInterVec = intersect(objVec,polyVec,letter);
+% mlunitext.assert(all(isInterVec == isTestInterVec));
+% end
+% end
+% %
+% function self = testDoesIntersectionContain(self)
+% ellConstrMat = eye(2);
+% nDims = 14;
+% ellConstr15DMat = eye(nDims);
+% ellShift1 = [0.05; 0];
+% ellShift2 = [0; 4];
+% %
+% ell1 = ellipsoid(ellConstrMat);
+% ell2 = ellipsoid(ellShift1,ellConstrMat);
+% ell3 = ellipsoid(ellShift2,ellConstrMat);
+% ell14D = ellipsoid(ellConstr15DMat);
+% %
+% %
+% polyConstrMat = [-1 0; 1 0; 0 1; 0 -1];
+% polyConstr3DMat = [-1 0 0; 1 0 0; 0 1 0; 0 -1 0; 0 0 1; 0 0
-1];
+% polyConstr15DMat = [eye(nDims);-eye(nDims)];
+% %
+% polyK1Vec = [0; 0.1; 0.1; 0.1];
+% polyK2Vec = [0.5; 0.05; sqrt(3)/2; 0];
+% polyK3Vec = [1; 0.05; 0.8; 0.8];
+% polyK4Vec = [0.5; -0.1; 0.1; 0.1];
+% polyK5Vec = [2; -0.3; 0.3; 0];
+% polyK6Vec = [1.5; -0.6; 0.6; 0];
+% polyK3DVec = 0.1 * ones(6,1);
+% polyK15DVec = (1/sqrt(nDims))*ones(nDims*2,1);
+% %
+% poly1 = polytope(polyConstrMat,polyK1Vec);
+% poly2 = polytope(polyConstrMat,polyK2Vec);
+% poly3 = polytope(polyConstrMat,polyK3Vec);
+% poly4 = polytope(polyConstrMat,polyK4Vec);
+% poly5 = polytope(polyConstrMat,polyK5Vec);
+% poly6 = polytope(polyConstrMat,polyK6Vec);
+% poly3D = polytope(polyConstr3DMat,polyK3DVec);
+% poly14D = polytope(polyConstr15DMat,polyK15DVec);
+% %
+% isExpVec = [1, 0, 1, 1, 1, 0, 1, 0, -1, 0, 1, 0];
+%
+% self.myTestIsCII(ell1, [poly1,
poly2], 'u',isExpVec(1),true,...
+% 'no')
+% %
+% self.myTestIsCII(ell1, [poly1,
poly3], 'u',isExpVec(2),true,...
+% 'no')
+% %
+% self.myTestIsCII(ell1, [poly1,
poly2], 'i',isExpVec(3),true,...
+% 'no')
+% %
+% self.myTestIsCII(ell1, [poly1,
poly3], 'i',isExpVec(4),true,...
+% 'no')
+% %
+% self.myTestIsCII([ell1, ell2], [poly1, poly3], 'i',...
+% isExpVec(5),true,'no')
+% %
+% self.myTestIsCII([ell1, ell2], [poly1, poly2], 'u',...
+% isExpVec(6),true,'no')
+% %
+% self.myTestIsCII([ell1, ell3],
poly1, 'u',isExpVec(8),false,...
+% 'no')
+% %
+% self.myTestIsCII(ell1, [poly1,
poly4],'i',isExpVec(9),false,...
+% 'no')
+% %
+% self.myTestIsCII(ell1, [poly1, poly2, poly3],'u',...
+% isExpVec(10),true,'no')
+% %
+% self.myTestIsCII([ell1,ell2], [poly3, poly5, poly2],'i',...
+% isExpVec(11),true,'no')
+% %
+% self.myTestIsCII(ell2, [poly3, poly5, poly6],'i',...
+% isExpVec(12),true,'no')
+% %
+% self.runAndCheckError(strcat('doesIntersectionContain',...
+% '(ell1, poly3D)'),'wrongSizes');
+% %
+% nDims2 = 9;
+% ell9D = ellipsoid(eye(nDims2));
+% poly9D = polytope([eye(nDims2);
-eye(nDims2)],ones(2*nDims2,1)/...
+% sqrt(nDims2));
+% self.myTestIsCII(ell9D, poly9D, 'u',isExpVec(7),true,'low')
+% self.myTestIsCII(ell14D,
poly14D, 'u',isExpVec(7),true,'high')
+% end
+% %
+% function self = testPoly2HypAndHyp2Poly(self)
+% polyConstMat = [-1 2 3; 3 4 2; 0 1 2];
+% polyKVec = [1; 2; 3];
+% testPoly = polytope(polyConstMat,polyKVec);
+% testHyp = hyperplane(polyConstMat',polyKVec');
+% hyp = polytope2hyperplane(testPoly);
+% mlunitext.assert(eq(testHyp,hyp));
+% poly = hyperplane2polytope(hyp);
+% mlunitext.assert(eq(poly,testPoly));
+% self.runAndCheckError('hyperplane2polytope(poly)',...
+% 'wrongInput:class');
+% hyp2 = [testHyp, hyperplane([1 2 3 4], 1)];
+% self.runAndCheckError('hyperplane2polytope(hyp2)',...
+% 'wrongInput:dimensions');
+% self.runAndCheckError('polytope2hyperplane(hyp)',...
+% 'wrongInput:class');
+%
+% end
%
- function self = testIntersect(self)
- [testEll2DVec,testPoly2DVec,testEll60D,testPoly60D,ellArr] =...
- self.genDataDistAndInter();
- %
- %
- isTestInterU2D1 = true;
- isTestInterU2D2 = true;
- isTestInterU2DVec = [false, false, true, true];
- isTestInterI2D = false;
- isTestInterI2DVec = [false, false, true, true];
- isTestInter60D = false;
- isTestInterWitharr = false;
- %
- %
- myTestIntesect(testEll2DVec([1,4]),testPoly2DVec(1),'u',...
- isTestInterU2D1);
- %
- myTestIntesect(testEll2DVec([2,3]),testPoly2DVec(3),'u',...
- isTestInterU2D2);
- %
- myTestIntesect(testEll2DVec([2,3]),testPoly2DVec,'u',...
- isTestInterU2DVec);
- %
- myTestIntesect(testEll2DVec([2,3]),testPoly2DVec(3),'i',...
- isTestInterI2D);
- %
- myTestIntesect(testEll2DVec([4,3]),testPoly2DVec,'i',...
- isTestInterI2DVec);
- %
- myTestIntesect(testEll60D,testPoly60D,'u',isTestInter60D);
- %
- myTestIntesect(ellArr,testPoly2DVec(1),'u',isTestInterWitharr);
- %
- self.runAndCheckError(strcat('intersect(testEll60D,',...
- ' testPoly2DVec(1))'),'wrongInput');
- %
- function myTestIntesect(objVec, polyVec, letter,isTestInterVec)
- isInterVec = intersect(objVec,polyVec,letter);
- mlunitext.assert(all(isInterVec == isTestInterVec));
- end
- end
- %
- function self = testDoesIntersectionContain(self)
- ellConstrMat = eye(2);
- nDims = 14;
- ellConstr15DMat = eye(nDims);
- ellShift1 = [0.05; 0];
- ellShift2 = [0; 4];
- %
- ell1 = ellipsoid(ellConstrMat);
- ell2 = ellipsoid(ellShift1,ellConstrMat);
- ell3 = ellipsoid(ellShift2,ellConstrMat);
- ell14D = ellipsoid(ellConstr15DMat);
- %
- %
- polyConstrMat = [-1 0; 1 0; 0 1; 0 -1];
- polyConstr3DMat = [-1 0 0; 1 0 0; 0 1 0; 0 -1 0; 0 0 1; 0 0
-1];
- polyConstr15DMat = [eye(nDims);-eye(nDims)];
- %
- polyK1Vec = [0; 0.1; 0.1; 0.1];
- polyK2Vec = [0.5; 0.05; sqrt(3)/2; 0];
- polyK3Vec = [1; 0.05; 0.8; 0.8];
- polyK4Vec = [0.5; -0.1; 0.1; 0.1];
- polyK5Vec = [2; -0.3; 0.3; 0];
- polyK6Vec = [1.5; -0.6; 0.6; 0];
- polyK3DVec = 0.1 * ones(6,1);
- polyK15DVec = (1/sqrt(nDims))*ones(nDims*2,1);
- %
- poly1 = polytope(polyConstrMat,polyK1Vec);
- poly2 = polytope(polyConstrMat,polyK2Vec);
- poly3 = polytope(polyConstrMat,polyK3Vec);
- poly4 = polytope(polyConstrMat,polyK4Vec);
- poly5 = polytope(polyConstrMat,polyK5Vec);
- poly6 = polytope(polyConstrMat,polyK6Vec);
- poly3D = polytope(polyConstr3DMat,polyK3DVec);
- poly14D = polytope(polyConstr15DMat,polyK15DVec);
- %
- isExpVec = [1, 0, 1, 1, 1, 0, 1, 0, -1, 0, 1, 0];
-
- self.myTestIsCII(ell1, [poly1, poly2], 'u',isExpVec(1),true,...
- 'no')
- %
- self.myTestIsCII(ell1, [poly1, poly3], 'u',isExpVec(2),true,...
- 'no')
- %
- self.myTestIsCII(ell1, [poly1, poly2], 'i',isExpVec(3),true,...
- 'no')
- %
- self.myTestIsCII(ell1, [poly1, poly3], 'i',isExpVec(4),true,...
- 'no')
- %
- self.myTestIsCII([ell1, ell2], [poly1, poly3], 'i',...
- isExpVec(5),true,'no')
- %
- self.myTestIsCII([ell1, ell2], [poly1, poly2], 'u',...
- isExpVec(6),true,'no')
- %
- self.myTestIsCII([ell1, ell3], poly1, 'u',isExpVec(8),false,...
- 'no')
- %
- self.myTestIsCII(ell1, [poly1, poly4],'i',isExpVec(9),false,...
- 'no')
- %
- self.myTestIsCII(ell1, [poly1, poly2, poly3],'u',...
- isExpVec(10),true,'no')
- %
- self.myTestIsCII([ell1,ell2], [poly3, poly5, poly2],'i',...
- isExpVec(11),true,'no')
- %
- self.myTestIsCII(ell2, [poly3, poly5, poly6],'i',...
- isExpVec(12),true,'no')
- %
- self.runAndCheckError(strcat('doesIntersectionContain',...
- '(ell1, poly3D)'),'wrongSizes');
- %
- nDims2 = 9;
- ell9D = ellipsoid(eye(nDims2));
- poly9D = polytope([eye(nDims2);
-eye(nDims2)],ones(2*nDims2,1)/...
- sqrt(nDims2));
- self.myTestIsCII(ell9D, poly9D, 'u',isExpVec(7),true,'low')
- self.myTestIsCII(ell14D, poly14D, 'u',isExpVec(7),true,'high')
- end
- %
- function self = testPoly2HypAndHyp2Poly(self)
- polyConstMat = [-1 2 3; 3 4 2; 0 1 2];
- polyKVec = [1; 2; 3];
- testPoly = polytope(polyConstMat,polyKVec);
- testHyp = hyperplane(polyConstMat',polyKVec');
- hyp = polytope2hyperplane(testPoly);
- mlunitext.assert(eq(testHyp,hyp));
- poly = hyperplane2polytope(hyp);
- mlunitext.assert(eq(poly,testPoly));
- self.runAndCheckError('hyperplane2polytope(poly)',...
- 'wrongInput:class');
- hyp2 = [testHyp, hyperplane([1 2 3 4], 1)];
- self.runAndCheckError('hyperplane2polytope(hyp2)',...
- 'wrongInput:dimensions');
- self.runAndCheckError('polytope2hyperplane(hyp)',...
- 'wrongInput:class');
-
- end
- %
%
function self = testIntersectionIA(self)
import elltool.exttbx.mpt.gen.*;
@@ -629,203 +629,203 @@
end
%
%
- function self = testIsInside(self)
- ellVec = ellipsoid.fromRepMat(eye(2),[1,3]);
- polyVec = [polytope([1,0],1), polytope([0, 1],2),...
- polytope([1 0],0)];
- isExpRes = true;
- isExpRes1Vec = [true, true, false];
- isExpRes2Vec = [false, false, false];
- %
- %
- myTestIsInside(ellVec(1),polyVec(1),isExpRes);
- %
- myTestIsInside(ellVec,polyVec,isExpRes1Vec);
- %
- myTestIsInside(ellVec(1),polyVec,isExpRes1Vec);
- %
- myTestIsInside(ellVec,polyVec(3),isExpRes2Vec);
- function myTestIsInside(ellVec,polyVec, expResVec)
- resVec = isInside(ellVec,polyVec);
- mlunitext.assert(all(resVec == expResVec));
- end
- end
- %
- %
- function self = testTri2Polytope(self)
- tri2poly = @(x,y) elltool.exttbx.mpt.gen.tri2polytope(x,y);
- % 3D Case
- vMat = [1 0 0; 0 1 0; 0 0 1; -1 0 0; 0 -1 0; 0 0 -1];
- fMat = [1 2 3; 2 3 4; 3 4 5; 1 3 5; 1 2 6; 2 4 6; 4 5 6; 1 5
6];
- poly1 = tri2poly(vMat,fMat);
- expPoly1NormMat = [1 1 1; -1 1 1; -1 -1 1; 1 -1 1; 1 1 -1;...
- -1 1 -1; -1 -1 -1; 1 -1 -1];
- expPoly1ConstVec = ones(8,1);
- expPoly1 = polytope(expPoly1NormMat,expPoly1ConstVec);
- mlunitext.assert(poly1 == expPoly1);
- %
- transfMat = [1 2 3; 4 1 1; 0 -2 3];
- transfVec = [1; -2; 0];
- v2Mat = vMat*transfMat' + repmat(transfVec',[size(vMat,1),1]);
- poly2 = tri2poly(v2Mat,fMat);
-
- expPoly2 = transfMat*expPoly1 + transfVec;
- mlunitext.assert(poly2 == expPoly2);
- %
- v3Mat = [1 0 0; 0 1 0; 0 0 1; 0 0 0];
- f3Mat = [1 2 3; 1 4 3; 1 2 4; 2 3 4];
- poly3 = tri2poly(v3Mat, f3Mat);
- expPoly3NormMat = [1 1 1; -eye(3)];
- expPoly3ConstVec = [1; zeros(3,1)];
- expPoly3 = polytope(expPoly3NormMat,expPoly3ConstVec);
- mlunitext.assert(poly3 == expPoly3);
- %
- % 2D Case
- v4Mat = [0 0; 2 0; 5 3; 4 6; 0 1];
- f4Mat = [1 2; 2 3; 3 4; 4 5; 5 1];
- poly4 = tri2poly(v4Mat,f4Mat);
- expPoly4NormMat = [0 -1; 1 -1; 3 1; -5 4; -1 0];
- expPoly4ConstVec = [0; 2; 18; 4; 0];
- expPoly4 = polytope(expPoly4NormMat,expPoly4ConstVec);
- mlunitext.assert(poly4 == expPoly4);
- %
- transf2Mat = [1 2; 3 4];
- transf2Vec = [-1; 1];
- v5Mat = v4Mat*transf2Mat' + repmat(transf2Vec',[5,1]);
- poly5 = tri2poly(v5Mat, f4Mat);
- expPoly5 = transf2Mat*expPoly4+ transf2Vec;
- mlunitext.assert(poly5 == expPoly5);
- end
- %
- %
- function self = testDoesContain(self)
- ellConstrMat = eye(2);
- ellShift1 = [0.05; 0];
- %
- ell1 = ellipsoid(ellConstrMat);
- ell2 = ellipsoid(ellShift1,ellConstrMat);
- %
- polyConstrMat = [-1 0; 1 0; 0 1; 0 -1];
- %
- polyK1Vec = [0; 0.1; 0.1; 0.1];
- polyK2Vec = [0.5; 0.05; sqrt(3)/2; 0];
- %
- poly1 = polytope(polyConstrMat,polyK1Vec);
- poly2 = polytope(polyConstrMat,polyK2Vec);
- %
- exp1Const = 0;
- exp1Vec = [1, 1];
- exp2Vec = [1, 1];
- exp3Vec = [1, 0];
- myTestDoesContain(ell2,poly2,exp1Const);
- myTestDoesContain(ell1,[poly1,poly2],exp1Vec);
- myTestDoesContain([ell1,ell2],poly1,exp2Vec);
- myTestDoesContain([ell1,ell2],[poly1,poly2],exp3Vec);
- function myTestDoesContain(ellVec,polyVec,expVec)
- doesContainVec = doesContain(ellVec,polyVec);
- mlunitext.assert(all(doesContainVec == expVec));
- end
- end
- %
- %
- function self = testToPolytope(self)
- ell1ConstrMat = [4 0; 0 9];
- ell2ConstrMat = eye(2);
- ell3ConstrMat = eye(3);
- ell1ShiftVec = [0; 0];
- ell2ShiftVec = [0.5; 0];
- ell3ShiftVec = [0.05; -0.1; 0];
- %
- ell1 = ellipsoid(ell1ShiftVec,ell1ConstrMat);
- ell2 = ellipsoid(ell2ShiftVec,ell2ConstrMat);
- ell3 = ellipsoid(ell3ShiftVec,ell3ConstrMat);
- poly1 = toPolytope(ell1);
- poly2 = toPolytope(ell2);
- poly3 = toPolytope(ell3);
- %
- %test for 2D-case
- isBound = self.isBoundary(ell1ShiftVec, ell1ConstrMat, poly1);
- mlunitext.assert(isBound);
- isBound = self.isBoundary(ell2ShiftVec, ell2ConstrMat, poly2);
- mlunitext.assert(isBound);
- %test for 3D-case
- isBound = self.isBoundary(ell3ShiftVec, ell3ConstrMat, poly3);
- mlunitext.assert(isBound);
- end
- end
- %
- methods(Static)
- %
- function
myTestIsCII(ellVec,polyVec,letter,isCIIExpVec,checkBoth,...
- timeCompare)
-
- if checkBoth
- tic;
- isCIIVec = doesIntersectionContain(ellVec,polyVec,...
- 'mode',letter,'computeMode','lowDimFast');
- lowTime = toc;
- mlunitext.assert(all(isCIIVec == isCIIExpVec));
- tic;
- isCIIVec = doesIntersectionContain(ellVec,polyVec,...
- 'mode',letter,'computeMode','highDimFast');
- highTime = toc;
- mlunitext.assert(all(isCIIVec == isCIIExpVec));
- if strcmp(timeCompare,'low')
- mlunitext.assert(lowTime <= highTime);
- elseif strcmp(timeCompare,'high')
- mlunitext.assert(lowTime >= highTime);
- end
- else
- isCIIVec = doesIntersectionContain(ellVec,polyVec,...
- 'mode',letter);
- mlunitext.assert(all(isCIIVec == isCIIExpVec));
- end
- end
- %
- %
- function [testEll2DVec,testPoly2DVec,testEll60D,....
- testPoly60D,ellArr] = genDataDistAndInter()
- testEll2DVec(4) = ellipsoid(16*eye(2));
- testEll2DVec(3) = ellipsoid([1.25 -0.75; -0.75 1.25]);
- testEll2DVec(2) = ellipsoid([1.25 0.75; 0.75 1.25]);
- testEll2DVec(1) = ellipsoid(eye(2));
- %
- testPoly2DVec = [polytope([-1 0; 1 0; 0 1; 0 -1],[-3; 4; 1;
1]),...
- polytope([1 0; -1 0; 0 1; 0 -1], [2.5; -1.5; -1.5;
100]),...
- polytope([1 -1; -1 1; -1 0; 0 1], [-2; 2.5; 2; 2]),...
- polytope([1 0; -1 0; 0 1; 0 -1], [1; 0; 1; 0])];
- testEll60D = ellipsoid(eye(60));
- h60D = [eye(60); -eye(60)];
- h60D(121,:) = [-1 1 zeros(1,58)];
- k60D = [4; 0; ones(58,1); 0; 4; ones(58,1); -4];
- testPoly60D = polytope(h60D,k60D);
- ellArr = ellipsoid.fromRepMat(eye(2),[2,2,2]);
- end
- %
- function isBound = isBoundary(ellShiftVec,ellConstrMat,poly)
- import modgen.common.absrelcompare;
- polyhedron = toPolyhedron(poly);
- pointsArray=polyhedron.V;
- nPoints = size(pointsArray,1);
- isBound = true;
- nDims = size(pointsArray,2);
- for i = 1:nPoints
- if nDims == 3
- [isEqual, absDiff] = absrelcompare(((pointsArray(i,1)
- ellShiftVec(1))^2/ellConstrMat(1,1))...
-
+((pointsArray(i,2)-ellShiftVec(2))^2/ellConstrMat(2,2))...
-
+((pointsArray(i,3)-ellShiftVec(3))^2/ellConstrMat(3,3)),...
- 1,1e-7,[],@abs);
- else
- [isEqual, absDiff] =
absrelcompare(((pointsArray(i,1)-ellShiftVec(1))^2/ellConstrMat(1,1))...
-
+((pointsArray(i,2)-ellShiftVec(2))^2/ellConstrMat(2,2)),...
- 1,1e-7,[],@abs);
- end
- if ~isEqual
- isBound = false;
- i = nPoints + 1;
- end
- end
- end
+% function self = testIsInside(self)
+% ellVec = ellipsoid.fromRepMat(eye(2),[1,3]);
+% polyVec = [polytope([1,0],1), polytope([0, 1],2),...
+% polytope([1 0],0)];
+% isExpRes = true;
+% isExpRes1Vec = [true, true, false];
+% isExpRes2Vec = [false, false, false];
+% %
+% %
+% myTestIsInside(ellVec(1),polyVec(1),isExpRes);
+% %
+% myTestIsInside(ellVec,polyVec,isExpRes1Vec);
+% %
+% myTestIsInside(ellVec(1),polyVec,isExpRes1Vec);
+% %
+% myTestIsInside(ellVec,polyVec(3),isExpRes2Vec);
+% function myTestIsInside(ellVec,polyVec, expResVec)
+% resVec = isInside(ellVec,polyVec);
+% mlunitext.assert(all(resVec == expResVec));
+% end
+% end
+% %
+% %
+% function self = testTri2Polytope(self)
+% tri2poly = @(x,y) elltool.exttbx.mpt.gen.tri2polytope(x,y);
+% % 3D Case
+% vMat = [1 0 0; 0 1 0; 0 0 1; -1 0 0; 0 -1 0; 0 0 -1];
+% fMat = [1 2 3; 2 3 4; 3 4 5; 1 3 5; 1 2 6; 2 4 6; 4 5 6; 1 5
6];
+% poly1 = tri2poly(vMat,fMat);
+% expPoly1NormMat = [1 1 1; -1 1 1; -1 -1 1; 1 -1 1; 1 1 -1;...
+% -1 1 -1; -1 -1 -1; 1 -1 -1];
+% expPoly1ConstVec = ones(8,1);
+% expPoly1 = polytope(expPoly1NormMat,expPoly1ConstVec);
+% mlunitext.assert(poly1 == expPoly1);
+% %
+% transfMat = [1 2 3; 4 1 1; 0 -2 3];
+% transfVec = [1; -2; 0];
+% v2Mat = vMat*transfMat' +
repmat(transfVec',[size(vMat,1),1]);
+% poly2 = tri2poly(v2Mat,fMat);
+%
+% expPoly2 = transfMat*expPoly1 + transfVec;
+% mlunitext.assert(poly2 == expPoly2);
+% %
+% v3Mat = [1 0 0; 0 1 0; 0 0 1; 0 0 0];
+% f3Mat = [1 2 3; 1 4 3; 1 2 4; 2 3 4];
+% poly3 = tri2poly(v3Mat, f3Mat);
+% expPoly3NormMat = [1 1 1; -eye(3)];
+% expPoly3ConstVec = [1; zeros(3,1)];
+% expPoly3 = polytope(expPoly3NormMat,expPoly3ConstVec);
+% mlunitext.assert(poly3 == expPoly3);
+% %
+% % 2D Case
+% v4Mat = [0 0; 2 0; 5 3; 4 6; 0 1];
+% f4Mat = [1 2; 2 3; 3 4; 4 5; 5 1];
+% poly4 = tri2poly(v4Mat,f4Mat);
+% expPoly4NormMat = [0 -1; 1 -1; 3 1; -5 4; -1 0];
+% expPoly4ConstVec = [0; 2; 18; 4; 0];
+% expPoly4 = polytope(expPoly4NormMat,expPoly4ConstVec);
+% mlunitext.assert(poly4 == expPoly4);
+% %
+% transf2Mat = [1 2; 3 4];
+% transf2Vec = [-1; 1];
+% v5Mat = v4Mat*transf2Mat' + repmat(transf2Vec',[5,1]);
+% poly5 = tri2poly(v5Mat, f4Mat);
+% expPoly5 = transf2Mat*expPoly4+ transf2Vec;
+% mlunitext.assert(poly5 == expPoly5);
+% end
+% %
+% %
+% function self = testDoesContain(self)
+% ellConstrMat = eye(2);
+% ellShift1 = [0.05; 0];
+% %
+% ell1 = ellipsoid(ellConstrMat);
+% ell2 = ellipsoid(ellShift1,ellConstrMat);
+% %
+% polyConstrMat = [-1 0; 1 0; 0 1; 0 -1];
+% %
+% polyK1Vec = [0; 0.1; 0.1; 0.1];
+% polyK2Vec = [0.5; 0.05; sqrt(3)/2; 0];
+% %
+% poly1 = polytope(polyConstrMat,polyK1Vec);
+% poly2 = polytope(polyConstrMat,polyK2Vec);
+% %
+% exp1Const = 0;
+% exp1Vec = [1, 1];
+% exp2Vec = [1, 1];
+% exp3Vec = [1, 0];
+% myTestDoesContain(ell2,poly2,exp1Const);
+% myTestDoesContain(ell1,[poly1,poly2],exp1Vec);
+% myTestDoesContain([ell1,ell2],poly1,exp2Vec);
+% myTestDoesContain([ell1,ell2],[poly1,poly2],exp3Vec);
+% function myTestDoesContain(ellVec,polyVec,expVec)
+% doesContainVec = doesContain(ellVec,polyVec);
+% mlunitext.assert(all(doesContainVec == expVec));
+% end
+% end
+% %
+% %
+% function self = testToPolytope(self)
+% ell1ConstrMat = [4 0; 0 9];
+% ell2ConstrMat = eye(2);
+% ell3ConstrMat = eye(3);
+% ell1ShiftVec = [0; 0];
+% ell2ShiftVec = [0.5; 0];
+% ell3ShiftVec = [0.05; -0.1; 0];
+% %
+% ell1 = ellipsoid(ell1ShiftVec,ell1ConstrMat);
+% ell2 = ellipsoid(ell2ShiftVec,ell2ConstrMat);
+% ell3 = ellipsoid(ell3ShiftVec,ell3ConstrMat);
+% poly1 = toPolytope(ell1);
+% poly2 = toPolytope(ell2);
+% poly3 = toPolytope(ell3);
+% %
+% %test for 2D-case
+% isBound = self.isBoundary(ell1ShiftVec, ell1ConstrMat,
poly1);
+% mlunitext.assert(isBound);
+% isBound = self.isBoundary(ell2ShiftVec, ell2ConstrMat,
poly2);
+% mlunitext.assert(isBound);
+% %test for 3D-case
+% isBound = self.isBoundary(ell3ShiftVec, ell3ConstrMat,
poly3);
+% mlunitext.assert(isBound);
+% end
+% end
+% %
+% methods(Static)
+% %
+% function
myTestIsCII(ellVec,polyVec,letter,isCIIExpVec,checkBoth,...
+% timeCompare)
+%
+% if checkBoth
+% tic;
+% isCIIVec = doesIntersectionContain(ellVec,polyVec,...
+% 'mode',letter,'computeMode','lowDimFast');
+% lowTime = toc;
+% mlunitext.assert(all(isCIIVec == isCIIExpVec));
+% tic;
+% isCIIVec = doesIntersectionContain(ellVec,polyVec,...
+% 'mode',letter,'computeMode','highDimFast');
+% highTime = toc;
+% mlunitext.assert(all(isCIIVec == isCIIExpVec));
+% if strcmp(timeCompare,'low')
+% mlunitext.assert(lowTime <= highTime);
+% elseif strcmp(timeCompare,'high')
+% mlunitext.assert(lowTime >= highTime);
+% end
+% else
+% isCIIVec = doesIntersectionContain(ellVec,polyVec,...
+% 'mode',letter);
+% mlunitext.assert(all(isCIIVec == isCIIExpVec));
+% end
+% end
+% %
+% %
+% function [testEll2DVec,testPoly2DVec,testEll60D,....
+% testPoly60D,ellArr] = genDataDistAndInter()
+% testEll2DVec(4) = ellipsoid(16*eye(2));
+% testEll2DVec(3) = ellipsoid([1.25 -0.75; -0.75 1.25]);
+% testEll2DVec(2) = ellipsoid([1.25 0.75; 0.75 1.25]);
+% testEll2DVec(1) = ellipsoid(eye(2));
+% %
+% testPoly2DVec = [polytope([-1 0; 1 0; 0 1; 0 -1],[-3; 4; 1;
1]),...
+% polytope([1 0; -1 0; 0 1; 0 -1], [2.5; -1.5; -1.5;
100]),...
+% polytope([1 -1; -1 1; -1 0; 0 1], [-2; 2.5; 2; 2]),...
+% polytope([1 0; -1 0; 0 1; 0 -1], [1; 0; 1; 0])];
+% testEll60D = ellipsoid(eye(60));
+% h60D = [eye(60); -eye(60)];
+% h60D(121,:) = [-1 1 zeros(1,58)];
+% k60D = [4; 0; ones(58,1); 0; 4; ones(58,1); -4];
+% testPoly60D = polytope(h60D,k60D);
+% ellArr = ellipsoid.fromRepMat(eye(2),[2,2,2]);
+% end
+% %
+% function isBound = isBoundary(ellShiftVec,ellConstrMat,poly)
+% import modgen.common.absrelcompare;
+% polyhedron = toPolyhedron(poly);
+% pointsArray=polyhedron.V;
+% nPoints = size(pointsArray,1);
+% isBound = true;
+% nDims = size(pointsArray,2);
+% for i = 1:nPoints
+% if nDims == 3
+% [isEqual, absDiff] =
absrelcompare(((pointsArray(i,1) - ellShiftVec(1))^2/ellConstrMat(1,1))...
+%
+((pointsArray(i,2)-ellShiftVec(2))^2/ellConstrMat(2,2))...
+%
+((pointsArray(i,3)-ellShiftVec(3))^2/ellConstrMat(3,3)),...
+% 1,1e-7,[],@abs);
+% else
+% [isEqual, absDiff] =
absrelcompare(((pointsArray(i,1)-ellShiftVec(1))^2/ellConstrMat(1,1))...
+%
+((pointsArray(i,2)-ellShiftVec(2))^2/ellConstrMat(2,2)),...
+% 1,1e-7,[],@abs);
+% end
+% if ~isEqual
+% isBound = false;
+% i = nPoints + 1;
+% end
+% end
+% end
%
end
end
=======================================
---
/branches/issue_119_vrozova/products/elltoolboxcore/@ellipsoid/ellintersection_ia.m
Tue Jan 21 13:48:42 2014 UTC
+++
/branches/issue_119_vrozova/products/elltoolboxcore/@ellipsoid/ellintersection_ia.m
Thu Jan 23 13:27:07 2014 UTC
@@ -1,8 +1,7 @@
function outEll = ellintersection_ia(inpEllArr)
%
% ELLINTERSECTION_IA - computes maximum volume ellipsoid that is contained
-% in the intersection of given ellipsoids.
-%
+% in the intersection of given ellipsoids.
%
% Input:
% regular:
=======================================
---
/branches/issue_119_vrozova/products/elltoolboxcore/@ellipsoid/intersection_ea.m
Tue Jan 21 13:48:42 2014 UTC
+++
/branches/issue_119_vrozova/products/elltoolboxcore/@ellipsoid/intersection_ea.m
Thu Jan 23 13:27:07 2014 UTC
@@ -1,5 +1,6 @@
function outEllArr = intersection_ea(myEllArr, objArr)
%
+%
% INTERSECTION_EA - external ellipsoidal approximation of the
% intersection of two ellipsoids, or ellipsoid and
% halfspace, or ellipsoid and polytope.
Reply all
Reply to author
Forward
0 new messages