The competing effect of a periodic pinning potential and random point disor
der is studied for ensembles of elastic lines or directed polymers. The gro
und states are investigated by exact combinatorial optimization. In both tw
o and three dimensions a phase diagram is found with two or three distinct
phases: a strictly at phase if the disorder is bounded and weak, a weakly f
luctuating phase for intermediate valley depths, where the lines roughen in
dividually on a scale smaller than the line-line distance, and a rough phas
e for strong disorder, where the roughness follows the scaling with pure po
int disorder. In the three-dimensional, rough phase the line wandering in t
he transverse direction leads to an entangled state with a complicated topo
logy.