public LinearMultivariateRealFunction getObjectiveFunction()
    {
        if(objectiveFunction == null)
        {
            double[] goodPriceQVector = new double[db.tools.size()];
            for(Tool tool : db.tools)
            {
                goodPriceQVector[db.toolIndexById.get(tool.getId())] = 0;
            }

            //condition for good
            for(Good good : db.goods)
            {
                int i = db.goodIndexById.get(good.getId());


                //finder
                for(NeedGoodForTool ngft : good.getNeedGoodForTool())
                {
                    goodPriceQVector[db.toolIndexById.get(ngft.getToolId())] += 
                            ngft.getRequestNumber().doubleValue()
                            * good.getPrice().doubleValue();
                }
                for(GoodFromTool gft : good.getGoodFromTool())
                {
                    goodPriceQVector[db.toolIndexById.get(gft.getToolId())] += 
                            - gft.getReceiveNumber().doubleValue()
                            * good.getPrice().doubleValue();
                }
                
            }
            for(Resource resource : db.resources)
            {
                for(NeedResourceForTool nrft : resource.getNeedResourceForTool())
                {
                    goodPriceQVector[db.toolIndexById.get(nrft.getToolId())] += 
                             nrft.getRequestNumber()
                            * resource.getPrice();
                }
            }
            
            objectiveFunction
               = new LinearMultivariateRealFunction(goodPriceQVector, 0);
        }
        
        return objectiveFunction;
    }