Ejemplo n.º 1
0
Function::Support Function::maxima(double dead_zone) /* const */
{
    Function d = derivative();
    Support s = d.zeros(), res; 
    Function dd = d.derivative();

    std::map<double,double> mins;
    // First, store all candidates in a map, ordered by value
    for (Support::const_iterator it = s.begin(); it != s.end(); it++) {
        double d2 = d.derivativeAt(*it);
        if (d2 < 0) {
            mins.insert(std::map<double,double>::value_type((*this)(*it),*it));
        }
    }
    // Then remove anything closer than deadzone
    for (std::map<double,double>::iterator it = mins.begin();
            it != mins.end(); it++) {
        res.insert(it->second);
        for (std::map<double,double>::iterator jt = mins.begin();
                jt != mins.end(); jt++) {
            if (jt == it) continue;
            if (fabs(jt->second-it->second) < dead_zone) {
                mins.erase(jt);
            }
        }
    }
    return res;
}
void Algo::run() {
    for (ATT j = m_dataset->nbAtt(); j > 0; j--) {
        if (m_dataset->attributs.find(j) != m_dataset->attributs.end()) {
            Support* tmp = new Support(j, m_dataset);
            if (tmp->frequency() >= 1 && tmp->frequency() < m_dataset->nbObj()) {
                m_libres = new PTreeLibre(j, true, tmp, NULL, m_libres);
            } else {
                cout << j << ' ' << endl;
                delete tmp;
            }
        }
    }
    delete m_dataset;
    m_dataset = NULL;

    if (m_libres) {
        _next = true;
    } else
        _next = false;

    ATT k = 1;
    while (_next) {
        _next = false;
        cerr << "# depth " << k + 1 << endl;
        if (m_libres) m_libres = m_libres->candidates(k);
        k++;
    }
}
Ejemplo n.º 3
0
void filterSupport( std::vector< PacketPtr >& packets_in,
                    std::vector< PacketPtr >& packets_out,
                    std::vector< PacketPtr >& /* packets_out_reverse */,
                    void ** /* client data */,
                    PacketPtr& params,
                    const TopologyLocalInfo& top_info)
{
   int tag = packets_in[0]->get_Tag();

   /* Bypass the filter in the back-ends, there's nothing to merge at this level! */
   if (BOTTOM_FILTER(top_info))
   {
      for (unsigned int i=0; i<packets_in.size(); i++)
      {
         packets_out.push_back(packets_in[i]);
      }
      return;
   }

   switch(tag)
   {
      case TAG_SUPPORT:
      {
         Support CumulativeSupport;

         for (int i=0; i<packets_in.size(); i++)
         {
           CumulativeSupport.Unpack( packets_in[i] );
         }
         CumulativeSupport.Serialize(packets_in[0]->get_StreamId(), packets_out);
         break;
      }
   }
}
Ejemplo n.º 4
0
MinSphere3x::MinSphere3x (int iQuantity, const Vector3x* akPoint,
    Sphere3x& rkMinimal, fixed fEpsilon)
{
    m_fEpsilon = fEpsilon;
    m_aoUpdate[0] = 0;
    m_aoUpdate[1] = &MinSphere3x::UpdateSupport1;
    m_aoUpdate[2] = &MinSphere3x::UpdateSupport2;
    m_aoUpdate[3] = &MinSphere3x::UpdateSupport3;
    m_aoUpdate[4] = &MinSphere3x::UpdateSupport4;

    Support kSupp;
    fixed fDistDiff;

    if (iQuantity >= 1)
    {
        // create identity permutation (0,1,...,iQuantity-1)
        Vector3x** apkPerm = WG_NEW Vector3x*[iQuantity];
        int i;
        for (i = 0; i < iQuantity; i++)
        {
            apkPerm[i] = (Vector3x*)&akPoint[i];
        }

        // generate random permutation
        for (i = iQuantity-1; i > 0; i--)
        {
            int j = rand() % (i+1);
            if (j != i)
            {
                Vector3x* pSave = apkPerm[i];
                apkPerm[i] = apkPerm[j];
                apkPerm[j] = pSave;
            }
        }

        rkMinimal = ExactSphere1(*apkPerm[0]);
        kSupp.Quantity = 1;
        kSupp.Index[0] = 0;
        i = 1;
        while (i < iQuantity)
        {
            if (!kSupp.Contains(i,apkPerm,m_fEpsilon))
            {
                if (!Contains(*apkPerm[i],rkMinimal,fDistDiff))
                {
                    UpdateFunction oUpdate = m_aoUpdate[kSupp.Quantity];
                    Sphere3x kSph =(this->*oUpdate)(i,apkPerm,kSupp);
                    if (kSph.Radius > rkMinimal.Radius)
                    {
                        rkMinimal = kSph;
                        i = 0;
                        continue;
                    }
                }
            }
            i++;
        }

        WG_DELETE[] apkPerm;
    }
Ejemplo n.º 5
0
Function::Support Function::zeros() const
{
	Support res;
	FDB::const_iterator it = vals.begin(),itp = it;
    if (it->second==0.0) {
        res.insert(it->first);
    }
    it++;
	for (;it != vals.end();it++,itp++) {
        if (it->second==0.0) {
            res.insert(it->first);
        } else if ((itp->second < 0) && (it->second > 0)) {
            res.insert(itp->first - itp->second * (it->first - itp->first) / (it->second - itp->second));
        } else if ((itp->second > 0) && (it->second < 0)) {
            res.insert(itp->first + itp->second * (it->first - itp->first) / (it->second - itp->second));
        }
    }
	return res;
}
Ejemplo n.º 6
0
MinCircle2<Real>::MinCircle2 (int numPoints, const Vector2<Real>* points,
    Circle2<Real>& minimal, Real epsilon)
    :
    mEpsilon(epsilon)
{
    mUpdate[0] = 0;
    mUpdate[1] = &MinCircle2<Real>::UpdateSupport1;
    mUpdate[2] = &MinCircle2<Real>::UpdateSupport2;
    mUpdate[3] = &MinCircle2<Real>::UpdateSupport3;

    Support support;
    Real distDiff;

    if (numPoints >= 1)
    {
        // Create identity permutation (0,1,...,numPoints-1).
        Vector2<Real>** permuted = new1<Vector2<Real>*>(numPoints);
        int i;
        for (i = 0; i < numPoints; ++i)
        {
            permuted[i] = (Vector2<Real>*)&points[i];
        }
        
        // Generate random permutation.
        for (i = numPoints - 1; i > 0; --i)
        {
            int j = rand() % (i+1);
            if (j != i)
            {
                Vector2<Real>* save = permuted[i];
                permuted[i] = permuted[j];
                permuted[j] = save;
            }
        }
        
        minimal = ExactCircle1(*permuted[0]);
        support.Quantity = 1;
        support.Index[0] = 0;

        // The previous version of the processing loop is
        //  i = 1;
        //  while (i < numPoints)
        //  {
        //      if (!support.Contains(i, permuted, mEpsilon))
        //      {
        //          if (!Contains(*permuted[i], minimal, distDiff))
        //          {
        //              UpdateFunction update = mUpdate[support.Quantity];
        //              Circle2<Real> circle = (this->*update)(i, permuted,
        //                  support);
        //              if (circle.Radius > minimal.Radius)
        //              {
        //                  minimal = circle;
        //                  i = 0;
        //                  continue;
        //              }
        //          }
        //      }
        //      ++i;
        //  }
        // This loop restarts from the beginning of the point list each time
        // the circle needs updating.  Linus Källberg (Computer Science at
        // Mälardalen University in Sweden) discovered that performance is
        // better when the remaining points in the array are processed before
        // restarting.  The points processed before the point that caused the
        // update are likely to be enclosed by the new circle (or near the
        // circle boundary) because they were enclosed by the previous circle.
        // The chances are better that points after the current one will cause
        // growth of the bounding circle.
        for (int i = 1 % numPoints, n = 0; i != n; i = (i + 1) % numPoints)
        {
            if (!support.Contains(i, permuted, mEpsilon))
            {
                if (!Contains(*permuted[i], minimal, distDiff))
                {
                    UpdateFunction update = mUpdate[support.Quantity];
                    Circle2<Real> circle =(this->*update)(i, permuted,
                        support);
                    if (circle.Radius > minimal.Radius)
                    {
                        minimal = circle;
                        n = i;
                    }
                }
            }
        }
        
        delete1(permuted);
    }
    else
    {
        assertion(false, "Input must contain points\n");
    }

    minimal.Radius = Math<Real>::Sqrt(minimal.Radius);
}
Ejemplo n.º 7
0
    MinSphere3<Real>::MinSphere3 ( int numPoints, const Vector3<Real>* points,
                                   Sphere3<Real>& minimal, Real epsilon )
        :
        mEpsilon( epsilon )
    {
        mUpdate[0] = 0;
        mUpdate[1] = &MinSphere3<Real>::UpdateSupport1;
        mUpdate[2] = &MinSphere3<Real>::UpdateSupport2;
        mUpdate[3] = &MinSphere3<Real>::UpdateSupport3;
        mUpdate[4] = &MinSphere3<Real>::UpdateSupport4;

        Support support;
        Real distDiff;

        if ( numPoints >= 1 )
        {
            // Create identity permutation (0,1,...,numPoints-1).
            Vector3<Real>** permuted = new1<Vector3<Real>*>( numPoints );
            int i;
            for ( i = 0; i < numPoints; ++i )
            {
                permuted[i] = ( Vector3<Real>* )&points[i];
            }

            // Generate random permutation.
            for ( i = numPoints - 1; i > 0; --i )
            {
                int j = rand() % ( i + 1 );
                if ( j != i )
                {
                    Vector3<Real>* save = permuted[i];
                    permuted[i] = permuted[j];
                    permuted[j] = save;
                }
            }

            minimal = ExactSphere1( *permuted[0] );
            support.Quantity = 1;
            support.Index[0] = 0;
            i = 1;
            while ( i < numPoints )
            {
                if ( !support.Contains( i, permuted, mEpsilon ) )
                {
                    if ( !Contains( *permuted[i], minimal, distDiff ) )
                    {
                        UpdateFunction update = mUpdate[support.Quantity];
                        Sphere3<Real> sphere = ( this->*update )( i, permuted,
                                               support );
                        if ( sphere.Radius > minimal.Radius )
                        {
                            minimal = sphere;
                            i = 0;
                            continue;
                        }
                    }
                }
                i++;
            }

            delete1( permuted );
        }
        else
        {
            assertion( false, "Input must contain points\n" );
        }

        minimal.Radius = Math<Real>::Sqrt( minimal.Radius );
    }
Ejemplo n.º 8
0
Support operator/(const Support& support, const Scalar& scale) {
    Support scaled;
    
    scaled.set_forward(support.forward() / scale);
    scaled.set_reverse(support.reverse() / scale);
    scaled.set_left(support.left() / scale);
    scaled.set_right(support.right() / scale);
    
    // log-scaled quality can just be divided. Maybe.
    scaled.set_quality(support.quality() / scale);
    
    return scaled;
}
Ejemplo n.º 9
0
Support operator*(const Scalar& scale, const Support& support) {
    Support prod;
    prod.set_forward(support.forward() * scale);
    prod.set_reverse(support.reverse() * scale);
    prod.set_left(support.left() * scale);
    prod.set_right(support.right() * scale);
    
    // log-scaled quality can just be multiplied
    prod.set_quality(support.quality() * scale);
    
    return prod;
}
Ejemplo n.º 10
0
int main() {

	Support support;

#ifdef _MSC_VER

	DWORD dwCheckExit, dwCheckExitParam = 1;
	HANDLE hcheckExit;
	hcheckExit = CreateThread(NULL, 0, CheckExit,
		&dwCheckExitParam, 0, &dwCheckExit);
	if (!hcheckExit) {
		support.SystemError("CreateThread hcheckExit failed");
	}

	STARTUPINFO si;
	ZeroMemory(&si, sizeof(STARTUPINFO));
	si.cb = sizeof(si);
	PROCESS_INFORMATION pi;
	ZeroMemory(&pi, sizeof(pi));

	/*if (!CreateProcess(NULL, "ComManager", NULL ,NULL, TRUE,
		CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi)) {
		support.SystemError("CreateProcess failed");
	}*/

	WSAData wsa;
	WORD Version = MAKEWORD(2, 1);
	WSAStartup(Version, &wsa);

	if (WSAStartup(Version, &wsa) != 0) {
		support.SystemError("Winsock is not been initialized");
	}

	SOCKET Listen = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	SOCKET Connect = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

	if (Listen == SOCKET_ERROR || Connect == SOCKET_ERROR) {
		support.SystemError("Listen or Connect socket is not been created");
	}

	SOCKADDR_IN Server;

	Server.sin_family = AF_INET;
	Server.sin_port = htons(SERVER_PORT);
	Server.sin_addr.s_addr = INADDR_ANY;

	if (bind(Listen, (SOCKADDR*)&Server, sizeof(Server)) == SOCKET_ERROR) {
		support.SystemError("Listen socket is not been binded");
	}

	listen(Listen, SOMAXCONN);

#else

	struct sockaddr_in server;
	int Listen, Connect;

	Listen = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
	if (Listen == -1) {
		support.SystemError("Socket is not been initialized");
		exit(EXIT_FAILURE);
	}

	memset(&server, 0, sizeof(server));

	server.sin_family = PF_INET;
	server.sin_port = htons(SERVER_PORT);
	server.sin_addr.s_addr = htonl(INADDR_ANY);

	if (bind(Listen, (struct sockaddr*) &server, sizeof(server)) == -1) {
		support.SystemError("Socket is not been binded");
		close(Listen);
		exit(EXIT_FAILURE);
	}

	if (listen(Listen, 10) == -1) {
		support.SystemError("Socket is not been listened");
		close(Listen);
		exit(EXIT_FAILURE);
	}

#endif
	
	char message[BUF_SIZE];

	cout << SERVER_NAME << " is running..." << endl;
	cout << "Waiting clients..." << endl;

	while (true) {

#ifdef _MSC_VER
		if (Connect = accept(Listen, NULL, NULL)) {
#else
		Connect = accept(Listen, 0, 0);
		if (Connect >= 0) {
#endif		
#ifdef _MSC_VER
			ZeroMemory(message, sizeof(message));
#else
			memset(&message, 0, sizeof(message));
#endif	
			if (recv(Connect, message, sizeof(message), 0) != NULL) {

				FileManager manager;
				Client client;
				//cout << message << endl;
				//get client info
				client.MakeClientInfo(message);
				//find requested file in public folder
				manager.MakeResponseBody(&client);
				//make response
				manager.MakeResponse(GOOD, manager.GetResponseBody());
				//get response
				string response = manager.GetResponse();
				//send response to client
#ifdef _MSC_VER
				send(Connect, response.c_str(),
					response.length(), 0);
#else
				send(Connect, response.c_str(),
					response.length(), 0);
#endif
				client.PrintClientInfo();
				//complite log file
				string content = client.MakeLogContent();
				manager.MakeLog("access", content);
#ifdef __linux__
				shutdown(Connect, SHUT_RDWR);
				close(Connect);
#endif
			}
		}
	
		if (exit_status) {
			break;
		}
	}

#ifdef _MSC_VER

	ZeroMemory(message, sizeof(message));
	closesocket(Connect);
	closesocket(Listen);
	WSACleanup();
	CloseHandle(pi.hProcess);
	CloseHandle(pi.hThread);
	CloseHandle(hcheckExit);

#else

	memset(&message, 0, sizeof(message));
	shutdown(Connect, SHUT_RDWR);
	close(Connect);
	shutdown(Listen, SHUT_RDWR);
	close(Listen);

#endif
	
	return 0;
}