Typically, you'll have something like the following:
- The government funds the research
- The developers get first refusal on patenting
- If they refuse, the government can patent
- If they patent, the government is given a perpetual free license to use the technology