I don't know anything about Berlin, but in San Francisco, there are plenty of affordable housing requirements placed on developers of new apartment buildings. This ends up just making new construction MUCH more expensive, as a single unit has to support itself as well as some fraction of an affordable unit. The result is that it's even less profitable to build new housing.
One clear alternative to this public housing. In Vienna, for example, about a quarter of the population lives in social housing. And these are poorly maintained slums, these are nice, well-located and affordable apartments. The city/state can optimize for the actual housing needs of the city rather than for profit.
I would argue that housing, much like healthcare, can function better when managed as a public good, as there are too many perverse incentives at play when there is a profit motive involved.