private double energy(int i, int x, int y){
        // проверка на то, чтобы все точки лежали внутри окошка (энергии не бесконечность)


        double energy = 0;
        if (x <= this.left_edge){
            energy = Double.POSITIVE_INFINITY;
        }
        if (x >= this.right_edge){
            energy = Double.POSITIVE_INFINITY;
        }
        if (y <= this.upper_edge){
            energy = Double.POSITIVE_INFINITY;
        }
        if (y >= this.down_edge){
            energy = Double.POSITIVE_INFINITY;
        }

        energy += energy_to_line(x, left_edge);
        energy += energy_to_line(x, right_edge);
        energy += energy_to_line(y, upper_edge);
        energy += energy_to_line(y, down_edge);

        for (int j = 0; j < nodesCount; ++j){
            if (j!=i)
                energy += repulsion_energy(x,y,gNodesArray[j].getX(),gNodesArray[j].getY());

        }
        for(int j = 0; j < gNodesArray[i].listIn.size(); ++j){

            GNode node = gNodesArray[i].listIn.get(j).getFinishGNode();
            energy += attraction_energy(x,y,node.getX(),node.getY());
        }
        for(int j = 0; j < gNodesArray[i].listOut.size(); ++j){
            GNode node = gNodesArray[i].listOut.get(j).getFinishGNode();
            energy += attraction_energy(x,y,node.getX(),node.getY());
        }

        return energy;
    }