public ConvexMultivariateRealFunction[] getResourcesConvexConditions(double alpha)
    {
        resourcesConvex = null; // нужный костыль
        if(resourcesConvex == null)
        {
            double talpha = getT(alpha);
            int mainSize = db.tools.size();
            int rowSize = db.resources.size();

            ConvexMultivariateRealFunction[] conditions = new ConvexMultivariateRealFunction[rowSize];

            for(Resource currentResource : db.resources)
            {
                int i = db.resourceIndexById.get(currentResource.getId());

                double[][] p = new double[mainSize][mainSize];
                double[] q = new double[mainSize];

                double[] nrftsm = getNrftsm()[i];
                double[] nrftsD = getNrftsd()[i];

                double resourceNumber = getResourceNumber()[i];
                double resourceNumberDeviation = getResourceNumberDeviation()[i];

                //0.5*XPX + QX + R <= 0
                //Fill p-matrix
                for (int j = 0; j < mainSize; ++j)
                {
                    for (int k = 0; k < mainSize; ++k)
                    {
                        p[j][k] = -nrftsm[j]*nrftsm[k];//-2*nrftsm[j]*nrftsm[k];
                        if(k == j)
                            p[j][j] += Math.pow(talpha*nrftsD[j], 2);
                        
                        p[j][k] *= 2;
                    }
                    
                }

                //Fill q-array
                for (int j = 0; j < mainSize; ++j)
                    q[j] = 2*resourceNumber*nrftsm[j];

                //r-value
                double r = 
                         Math.pow(talpha*resourceNumberDeviation,2) 
                         - Math.pow(resourceNumber, 2);

                conditions[i] 
                        = new QuadraticMultivariateRealFunction(p, q, r);
            }

            resourcesConvex = conditions;
        }
        
        return resourcesConvex;
    }