This paper discusses a knowledge-base encoding methodology for diagnostic tasks, transforming such knowledge into constrained optimisation problems. The methodology is based on a re-interpretation of the consistent causal reasoning paradigm [15] as an equivalent problem of feasibility subject to equality and inequality constraints (in the binary case). Then, it is extended to the fuzzy case. Preferences under uncertain knowledge are incorporated by transforming the feasibility problem into an optimisation one, which may be interpreted in possibilistic terms. The problem is solved by efficient, widely-known, linear and quadratic programming tools, which are able to cope with large-scale problems. Examples illustrating some of the concepts and possibilities of the proposed procedure, as well as a summary comparison with other approaches are also discussed.