Public feed
#892535
========================================= POLYTOPES.h ================/* Created by Yann Disser on 7.1.2008. */#ifndef REDUCED_POLYTOPES_H#define REDUCED_POLYTOPES_H REDUCED_POLYTOPES_H#include <memory>#include <vector>#include "Polytope.h"#include "ReducedVertex.h"typedef std::auto_ptr<Polytope> pPolytope;//assumes two systems with binary outputspPolytope createCorrelationPolytope(int n);pPolytope createCorrelationPolytope(int n, const std::vector<std::pair<int, int> >& S);pPolytope createCorrelationPolytopeReduced(const Vertex::System& s1, const Vertex::System& s2);pPolytope createCorrelationPolytopeReduced(const Vertex::System& s1, const Vertex::System& s2, const std::vector<std::pair<int, int> >& S);pPolytope createQuantumPolytope(int n);pPolytope createQuantumPolytope(int n, const std::vector<std::pair<int, int> >& S);pPolytope createModifiedPolytope(const Polytope* poly, double eta = 1.0);pPolytope createPolytopeCopy(const Polytope& poly, const VertexFactory& fac = ReducedVertexFactory());template<class VERTEX>pPolytope createCorrelationPolytope(const Vertex::System& s1, const Vertex::System& s2){ return pPolytope(NULL); }template<>pPolytope createCorrelationPolytope<ReducedVertex>(const Vertex::System& s1, const Vertex::System& s2){ return createCorrelationPolytopeReduced(s1, s2); }template<>pPolytope createCorrelationPolytope<FullVertex>(const Vertex::System& s1, const Vertex::System& s2){ return createPolytopeCopy(*createCorrelationPolytopeReduced(s1, s2), FullVertexFactory()); }//return FullVertex representationpPolytope createWeakSignallingPolytopeFull(int m, int n, int a, int b);//return ReducedVertex representationpPolytope createWeakSignallingPolytopeReduced(int m, int n, int a, int b);template <class VERTEX>pPolytope createWeakSignallingPolytope(int m, int n, int a, int b){ return pPolytope(NULL); }template<>pPolytope createWeakSignallingPolytope<ReducedVertex>(int m, int n, int a, int b){ return createWeakSignallingPolytopeReduced(m, n, a, b); }template<>pPolytope createWeakSignallingPolytope<FullVertex>(int m, int n, int a, int b){ return createWeakSignallingPolytopeFull(m, n, a, b); }#endif //REDUCED_POLYTOPES_H========================================== TESTER.H ===============#ifndef YANN_REDUCED_TESTER_H#define YANN_REDUCED_TESTER_H YANN_REDUCED_TESTER_H#include <vector>#include "Vertex.h"#include "polytopes.h"typedef Vertex::System System;template<class VERTEX>class Tester{ public: double determineWeakSignallingEta(const System& s1, const System& s2, bool expand, double allowedDifference = 0.00001); double determineWeakSignallingEta(const System& s1, const System& s2, bool expand, double allowedDifference) { pPolytope poly = createWeakSignallingPolytope<VERTEX>(s1.outcomes, s2.outcomes, s1.inputs, s2.inputs); m_extremeVerts.clear(); const std::vector<Vertex*>& verts = poly->getVertices(); int size = verts.size(); for(int i = 0; i < size; ++i) m_extremeVerts.push_back(VERTEX(*verts[i])); pPolytope corrPoly = createCorrelationPolytope<VERTEX>( System(s1.inputs, s1.outcomes + (expand ? 1 : 0)), System(s2.inputs, s2.outcomes + (expand ? 1 : 0))); std::cerr << "Setup done (" << size << " verts)" << std::endl; double upper = 1.0, lower = 0.000; while(upper - lower >= allowedDifference) { double mid = (upper + lower)/2.0; std::vector<VERTEX> newVerts; for(unsigned int i = 0; i < verts.size(); ++i) if(!corrPoly->contains(VERTEX(ReducedVertex(verts[i], mid, 1.0, expand)))) newVerts.push_back(verts[i]); bool contained = (newVerts.size() == 0); if(contained) { lower = mid; newVerts = verts; } else upper = mid; std::cerr << mid << ": " << contained << " nVerts: " << verts.size() << std::endl; verts = newVerts; } return upper; } private: std::vector<VERTEX> m_extremeVerts;};#endif //YANN_REDUCED_TESTER_H