Exemple #1
0
void CvQueryExecutionPlanView::OnDraw(CDC* pDC)
{
	CdQueryExecutionPlanDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;
	if (m_nSequence == NULL)
		return;
	if (m_bDrawingFailed)
		return;
	try
	{
		CaSqlQueryExecutionPlanData* pData = pDoc->m_listQepData.GetAt (m_nSequence);
		BOOL bPreview = pData->GetDisplayMode();
		//
		// Draw the Qep Boxes.
		DrawQepBoxes (pData->m_pQepBinaryTree, pDC, bPreview);
		//
		// Draw the links. (At this point, all Boxes of Qep of the current tree
		//                  have been allocated and created).
		CPoint pStart;
		CPoint pEnd;
		CWnd* pParentBox = NULL;
		CWnd* pChildBox  = NULL;
		CaSqlQueryExecutionPlanBoxLink* pLink = NULL;
		POSITION pos = pData->m_listLink.GetHeadPosition();
		while (pos != NULL)
		{
			pLink = pData->m_listLink.GetNext (pos);
			pParentBox =  pLink->GetParentBox(bPreview);
			pChildBox  =  pLink->GetChildBox (bPreview);
			ASSERT (pParentBox);
			ASSERT (pChildBox);
			if (!(pParentBox && pChildBox))
				return;
			GetStartingPoint (pParentBox, pStart, pLink->m_nSon);
			GetEndingPoint   (pChildBox,  pEnd);
			pDC->DPtoLP (&pStart);
			pDC->MoveTo (pStart);
			pDC->DPtoLP (&pEnd);
			pDC->LineTo (pEnd);
		}
		if (m_pPopupInfoWnd)
		{
			ClientToScreen (m_rcPopupInfo);
			m_pPopupInfoWnd->SetWindowPos (&wndTop, m_rcPopupInfo.left, m_rcPopupInfo.top, 0, 0, SWP_NOSIZE|SWP_SHOWWINDOW);
			m_pPopupInfoWnd->SetWindowPos (NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED);
		}
	}
	catch (CeSqlQueryException e)
	{
		AfxMessageBox (e.GetReason());
		return;
	}
	catch (...)
	{
		AfxMessageBox (IDS_MSG_FAIL_2_DRAW_QEP_TREE);
		return;
	}
}
bool PrimitiveLine::Intersection(const PrimitiveLine &other, Coordinate &intersection) const {
	
	// compute "line vector"
	Coordinate myP = points_[1]-points_[0];

	// compute normal vector
	Coordinate myN(-myP.GetYAsFloat(), myP.GetXAsFloat());

	assert(myP*myN == 0);
	
	myN /= myP.length();

	// get starting and ending point of other line
	Coordinate r = other.GetStartingPoint();
	Coordinate s = other.GetEndingPoint();

	// are lines parallel?
	float value = myN * (s-r);
	if(-0.001 <= value && value <= 0.001) {
		return false;
	}
	
	// calculate "d"
	float d = myN * GetStartingPoint();

	// calculate parameter of intersection
	float t = (d-myN*r)/(myN * (s-r));

	// calculate intersection
	intersection = r + t*(s-r);

	return true;
}
Exemple #3
0
void NormalSet::Solve()
{
    EditLinearDegenerates();

    GeneralMinimizer * solver = NULL;   // Initialization avoids compiler warnings

    switch (numericMinimizer)
    {
    case NORMAL_AMOEBA_MIN :
        solver = new AmoebaMinimizer();
        break;
    case NORMAL_POWELL_MIN :
        solver = new PowellMinimizer();
        break;
    case NORMAL_FLETCHER_MIN :
        solver = new FletcherMinimizer();
        break;
    }

    solver->func = new NormalSolver(this);

    // set the number of parameters to minimize
    int parameters = CountParameters();
    solver->Reset(parameters);

    // Reset the number of likelihood evaluations
    evaluations = 0;

    // If we are not using the Nelder-Mead minimizer, use it
    // to conduct a rough pre-optimization.
    if (solver != NORMAL_AMOEBA_MIN)
    {
        AmoebaMinimizer presolver;

        presolver.func = solver->func;
        presolver.Reset(parameters);
        GetStartingPoint(presolver.point);
        presolver.Minimize(precision * 1000);

        solver->point = presolver.point;
    }
    else
        GetStartingPoint(solver->point);

    // Two rounds of minimizing to be safe
    solver->Minimize(precision);

    double lastmin;
    double scale = 2.0;

    do {
        // Find the largest variance ...
        double varMax = solver->point[means.Length()];
        for (int i = means.Length() + vcEstimated - 1; i > means.Length(); i--)
            if (solver->point[i] > varMax)
                varMax = solver->point[i];

        // Check that none of the variances is effectively zero...
        for (int i = means.Length() + vcEstimated - 1; i >= means.Length(); i--)
            if (solver->point[i] < (varMax - 5.0))
                solver->point[i] = varMax - 5.0;

        lastmin = solver->fmin;
        scale *= -0.5;
        solver->Reset(parameters, scale);
        solver->Minimize(precision);
    }
    while (solver->fmin > precision &&
            (lastmin - solver->fmin)/solver->fmin > precision);

    SelectPoint(solver->point);

    delete solver->func;
    delete solver;
}