Deriving the Einstein field equations (EFE) with matter fluid from the action principle is not straightforward, because mass conservation must be added as an additional constraint to make rest-frame mass density variable in reaction to metric variation. This can be avoided by introducing a constraint $delta(sqrt{-g}) = 0$ to metric variations $delta g^{mu u}$, and then the cosmological constant $Lambda$ emerges as an integration constant. This is a removal of one of the four constraints on initial conditions forced by EFE at the birth of the universe, and it may imply that EFE are unnecessarily restrictive about initial conditions. I then adopt a principle that the theory of gravity should be able to solve time evolution starting from arbitrary inhomogeneous initial conditions about spacetime and matter. The equations of gravitational fields satisfying this principle are obtained, by setting four auxiliary constraints on $delta g^{mu u}$ to extract six degrees of freedom for gravity. The cost of achieving this is a loss of general covariance, but these equations constitute a consistent theory if they hold in the special coordinate systems that can be uniquely specified with respect to the initial space-like hypersurface when the universe was born. This theory predicts that gravity is described by EFE with non-zero $Lambda$ in a homogeneous patch of the universe created by inflation, but $Lambda$ changes continuously across different patches. Then both the smallness and coincidence problems of the cosmological constant are solved by the anthropic argument. This is just a result of inhomogeneous initial conditions, not requiring any change of the fundamental physical laws in different patches.