Skip to content

Instantly share code, notes, and snippets.

@brunokunace
Created March 5, 2019 16:25
Show Gist options
  • Save brunokunace/7cba50e579165be95ddc9b4d4276e7d8 to your computer and use it in GitHub Desktop.
Save brunokunace/7cba50e579165be95ddc9b4d4276e7d8 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
namespace Cortes.Tester
{
class Program
{
static List<long> keys = new List<long> ();
static Random random = new Random ();
static void Main (string[] args)
{
string fileName = @” G : TCCcortesrcarquivopadroesg0101.txt”;
TextReader reader = File.OpenText (fileName);
string text = reader.ReadToEnd ();
reader.Close ();
string[] lines = text.Split (“rn”.ToArray ());
List<string> values = new List<string> (lines.Where (s => s != string.Empty));
List<Wang> L = new List<Wang> ();
List<Wang> F = new List<Wang> ();
int tamAtu = 0, tamProx = 0;
bool first = true;
Chapa chapa = null;
///// Inicie a marcação de tempo aqui!!!!
DateTime now = DateTime.Now;
foreach (string s in values)
{
string[] elements = s.Split (“t”.ToArray ());
if (first)
{
chapa = new Chapa (Convert.ToInt32 (elements[1]),
Convert.ToInt32 (elements[2]),
Convert.ToDecimal (elements[3]));
first = false;
} else
{
Corte c = new Corte (Convert.ToInt32 (elements[1]), Convert.ToInt32 (elements[2]));
int ins = Convert.ToInt32 (elements[3]);
chapa.Add (c, false);
chapa.Demanda.Add (ins);
}
}
if (chapa.Count > 64)
{
Console.WriteLine (“Quantidade inválida de chapas.Até 64 cortes por chapa.”);
} else
{
int j = 0;
foreach (Corte c in chapa.Keys)
{
L.Add (new Wang (c, chapa, j));
L[j].Num = j;
j++;
}
}
F.AddRange (L);
tamAtu = F.Count;
do {
tamProx = tamAtu;
List<Wang> atual = new List<Wang> ();
for (int i = 0; i < F.Count; ++i)
{
for (int j = 0; j < L.Count; ++j)
{
Wang trab = new Wang (F[i], L[j], “Horizontal”);
if (trab.possivel (chapa)) atual.Add (trab);
trab = new Wang (F[i], L[j], “Vertical”);
if (trab.possivel (chapa)) atual.Add (trab);
}
}
for (int i = 0; i < atual.Count; ++i) {
bool flag = false;
for (int j = 0; j < L.Count; ++j)
{
if (iguais (atual[i], L[j]))
{
flag = true;
break;
}
}
if (!flag)
{
L.Add (atual[i]);
L[L.Count– 1].Num = L.Count– 1;
}
}
tamAtu = L.Count;
F.Clear ();
F.AddRange (atual);
} while (tamProx != tamAtu);
DateTime end = DateTime.Now;
Console.Write (“Duração em milisegundos: { 0 }”, (end– now).Duration ().TotalMilliseconds);
//////////// Finalize a marcação de tempo aqui!!!!!
for (int i = 0; i < L.Count; ++i)
{
if (L[i].PerdaTotal (chapa) < chapa.Valor * chapa.Percentual / 100)
{
mostraPadrao (L[i], ”“);
Console.WriteLine ();
Console.WriteLine ();
}
}
Console.ReadLine ();
}
public static Boolean iguais (Wang x, Wang y)
{
if (x.Largura != y.Largura || x.Altura != y.Altura || x.Valor != y.Valor || x.PerdaInterna != y.PerdaInterna ||
x.Pecas.Count != y.Pecas.Count || !pecasIguais (x, y)) return false;
return true;
}
public static Boolean pecasIguais (Wang x, Wang y)
{
Boolean flag = true;
for (int i = 0; i < x.Pecas.Count; ++i)
{
if (x.Pecas[i] != y.Pecas[i])
{
flag = false;
break;
}
}
return flag;
}
public static void mostraPadrao (Wang w, String s)
{
if (w != null)
{
Console.Write (w.Num + ”–” +w.Altura + ”–” +w.Largura + ”–” +w.Valor + ”–“ +w.Construcao + ”–“ +s + ”—“);
if (w.P1 != null)
{
Console.Write (”p1” + w.P1.Num + ”—“);
}
if (w.P2 != null)
{
Console.Write (”p2” + w.P2.Num);
}
Console.WriteLine ();
mostraPadrao (w.P1, s + ” * ”);
mostraPadrao (w.P2, s + ” * ”);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment