Optimal Resource Allocation in Grid Environments