#include "test.h"

int main(int argc, char* argv[])
{
	
	/*all correct solutions will satisfy La*m0 <= ba, La*D(:, Tuc) <= 0, and La*D(:, Tuo) = 0.  
  Also, a correct solution will satisfy that for all nonnegative integer vectors m, if La*m <= ba, then L*m <= b.*/
  
	char InDesc[] = "matrix D, indexarray Tuc, indexarray Tuo, matrix L, arrayi B, arrayi m0";
	char OutDesc[] = "string Message, matrix La, arrayi Ba";
	
	mroadm_r answer;
	matrix D, L;
	int BCount, m0Count, TucCount, TuoCount;
	int *B, *m0, *Tuc, *Tuo, *InFilled, OutFilled[3];
	FILE* input;
	MemoryManager mem;
	
	mem = CreateMemoryManager(10, 10, 0, 0);
	
  /*Set the verbosity level to maximum*/
	setverbose(VRB_MAX);

	if (! (input = ParseCmdLine(argc, argv)))
	{
		return 0;
	}
	
	while (ParseStructure(input, InDesc, &InFilled, &mem, &D, &Tuc, &TucCount, &Tuo, &TuoCount, &L, &B, &BCount, &m0, &m0Count))
	{
		/*Display the problem.*/
		DisplayStructure(InDesc, InFilled, &D, Tuc, TucCount, InFilled[0] ? NumberOfColumns(D) : 0, Tuo, TuoCount, InFilled[0] ? NumberOfColumns(D) : 0, &L, B, BCount, m0, m0Count);
		
		/*Solve the problem.*/
		answer = mroadm(InFilled[3] ? &L : 0, InFilled[4] ? B : 0, InFilled[0] ? &D : 0, InFilled[1] ? Tuc : 0, TucCount, InFilled[2] ? Tuo : 0, TuoCount, InFilled[5] ? m0 : 0);
		
		OutFilled[0] = 1;		
		OutFilled[1] = 1;		
		if (answer.ba)
		{
			OutFilled[2] = 1;					
		}
		else
		{
			OutFilled[2] = 0;
		}
		
		/*Show the solution*/
		printf("\nSolution:\n");
		DisplayStructure(OutDesc, OutFilled, answer.how, &answer.La, answer.ba, NumberOfRows(answer.La));	
		printf("--------------------------------------------------------------------------------\n");
		
		/*Clear and re-initialize dynamic memory log and loop again.*/
		FreeMemory(&mem);
		DeallocateIlpadm(&answer);
		mem = CreateMemoryManager(10, 10, 0, 0);
	}
	FreeMemory(&mem);
	return 0;
}
