A general methodology for nonlinear structural analysis by mathematical programming