An algorithm for a piecewise linear model of trade and production with negative prices and bankruptcy