Ver Mensaje Individual
  #31  
Antiguo 15-04-2018
Avatar de danielmj
danielmj danielmj is offline
Miembro
 
Registrado: jun 2011
Posts: 383
Reputación: 13
danielmj Va por buen camino
Hola bucanero,
He estado mirando tu código e implementandolo para mi caso, en compilación no da error, pero como las barras de progreso no se mueven ni un par de etiquetas que muestran el recorrido de lista3 y el listbox per, no sé si realmente funciona o no.

El código resumido seria este:

Código Delphi [-]
unit primi;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, ImgList, Menus, StdCtrls, ComCtrls, Gauges, uTAlea, ListViewExt,
  ToolWin, Buttons, VirtualListData, System.ImageList, Vcl.Imaging.pngimage;

type
  ...
  private
    { Private declarations }
    list:TStringList;
    function GetComb(listBox:TListBox):String;
    function extraerComunes(const res:int64):string;
    procedure CompararCombinaciones(const Cad1, cad2:Int64);
    procedure buscarComunes(const Cad1:Int64);
    FVirtualData:  TVirtualData;
  public
    { Public declarations }
  end;

TModa = record
     Number : Integer;
     Count : Integer;
  end;

  ...

const
  ...

var
  ...

implementation

{$R *.dfm}
{$M  16384,1999999}

function ValorCombinacion(list:TStrings):Int64;
var
  elemento:Byte;
  i: Integer;
begin
  result := 0;
  with list do
    for i := 0 to Count - 1 do
    begin
      //se obtiene el valor numerico de la lista
      elemento := StrToInt(strings[i])-1;
      //se inserta en el resultado
      result := result or (Int64(1) shl elemento);
    end;
end;

function  TForm1.GetComb(listBox:TListBox):String;
begin
  result:=form1.per.items[form1.per.itemIndex];
end;


function obtenerComunes(res:int64):string;
var
  i:integer;
begin
  result:='';
  for i :=0 to 49 do
    if ((res and (int64(1) shl i))<>0) then
      result:=result+IntToStr(i+1)+' ';
end;

//... creacion y ejecucion de hilos de procesamiento

function  TForm1.extraerComunes(const res:int64):string;
var
  i:integer;
begin
  result:='';
  for i :=0 to 49 do
    if ((res and (int64(1) shl i))<>0) then
      result:=result+IntToStr(i+1)+' ';
end;

procedure TForm1.CompararCombinaciones(const Cad1, cad2:Int64);
var
  res:Int64;
  comunes:string;
begin
  res:=cad1 and cad2;
  if (cad1 = cad2) then begin
    // las dos combinaciones son iguales
    ShowMessage('Iguales');
  end
  else
    showMessage('No hay coincidencias');
    form1.timer1.Enabled:= false;
    form1.Refresh;
    exit
end;


procedure TForm1.buscarComunes(const Cad1:Int64);
var
  cad2:Int64;
  j:integer;
  list:TStringList;

begin
   // Recorro la lista2
   for j := 0 to form1.per.Items.Count -1 do
   begin
     label32.Caption:= IntToStr(j+1);
     form1.barra2.Max:= form1.per.Items.Count;
     form1.barra2.Position:= j;
     form1.label22.Caption:= IntToStr(cad2);
     form1.per.ItemIndex := j;
     //convierto el string separado por espacios a una lista
     list.delimitedText:=form1.per.items[j];
     // Calculo CAD2 cada vez que cambia el indice de per
     cad2 := ValorCombinacion(list);
     CompararCombinaciones(cad1, cad2);
     //form1.button10.Click
   end;
end;

//cargo en lista3 el archivo de sorteos
procedure LoadFromCSV(LV: TListView; const aFileName: string);
var
  LI : TListItem;
  TS1, TS2: TStrings;
  i, j: Integer;
begin
  TS1 := TStringList.Create;
  TS2 := TStringList.Create;
  try
    TS1.LoadFromFile(aFileName);
    // Columnas
    TS2.CommaText := TS1[0];
    for i := 0 to TS2.Count-1 do
    begin
      LV.Columns.Add;
      LV.Columns.Items[i].Caption := TS2[i];
      LV.Columns[i].Width:= 100; // esta línea es opcional
    end;
    // Items, Subitems
    for i := 1 to TS1.Count-1 do
    begin
      TS2.Clear;
      TS2.CommaText := TS1[i];
      LI := LV.Items.Add;
      LI.Caption := TS2[0];
      for j:= 1 to TS2.Count - 1 do
        LI.SubItems.Add(TS2[j]);
    end;
  finally
    TS1.Free;
    TS2.Free;
  end;
end;

//Crea las permutaciones y las agrega al listbox "per" a partir de un listado general
procedure combinatoria2(v: array of Integer; Serie: TStrings);
var
  a,b,c,d,e: Integer;
begin
  if Length(v) <> 5 then
    raise Exception.Create('Error: Deben ser 5 elementos');
  for a := Low(v) to High(v) do
    for b := Low(v) to High(v) do
      for c := Low(v) to High(v) do
        for d := Low(v) to High(v) do
         for e := Low(v) to High(v) do
           if not(
  (v[a]=v[b])or(v[a]=v[c])or(v[a]=v[d])or(v[a]=v[e])or
  (v[b]=v[c])or(v[b]=v[d])or(v[b]=v[e])or
  (v[c]=v[d])or(v[c]=v[e])or
  (v[d]=v[e])) then
  Serie.Add(Format('%d %d %d %d %d',[v[a], v[b], v[c], v[d], v[e]]));
end;

//Carga en lista3 el contenido del CSV
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  if Open.Execute then
       begin
            LoadFromCSV(lista3, open.FileName);
            lista3.Column[0].Width:= 85;
            lista3.Column[1].Width:=30;
            lista3.Column[2].Width:=30;
            lista3.Column[3].Width:=30;
            lista3.Column[4].Width:=30;
            lista3.Column[5].Width:=30;
            lista3.Column[6].Width:=30;
            stB.Panels.Items[0].Text:= 'Núm. Filas: '+IntToStr(lista.Items.Count);
            button9.Enabled:=true;
       end;
end;

//*** Aquí comienza el proceso de buscar coincidencias ***
procedure TForm1.Button10Click(Sender: TObject);
var
  i, j, cinco: integer;
  res, cad1, cad2:Int64;
  comunes:String;
  list:TStringList;

begin
  Application.ProcessMessages;
  stB.Panels.Items[0].Text:= 'Combinaciones: '+IntToStr(lista3.Items.Count);
  stB.Panels.Items[1].Text:= 'Permutaciones: '+IntToStr(per.Items.Count);
  timer1.Enabled:= true;
  cinco:= 0;

  // Recorro lista3
  for i := 0 to lista3.Items.Count -1 do
    begin
      barra.Max:= lista3.Items.Count;
      barra.Position:= i+1;
      with lista3 do
        begin
        selected := Items[i];
        label31.Caption:= IntToStr(i+1); //--> esta etiqueta solo muestra el primer valor (1)
        // Calculo CAD1 cada vez que cambia el indice de lista3
        list.delimitedText:= items.Item[i].SubItems[0]+' '+items.Item[i].SubItems[1]+
                             ' '+items.Item[i].SubItems[2]+' '+items.Item[i].SubItems[3]+
                             ' '+items.Item[i].SubItems[4];
        cad1:= ValorCombinacion(list);
        label21.Caption:= IntToStr(cad1);
        buscarcomunes(cad1);
    stB.Panels.Items[4].Text:= FormatFloat('0.00',(i * 100) / lista3.items.Count)+'%';
      end;
    end;
end;

//... Procesos para calcular numeros mas repetidos de lista y carga del combobox
// con el numero de combinaciones aleatorias a generar.

end.

Y aquí puedes ver el programa en funcionamiento...
Como puedes ver ni las barras de progreso se mueven ni las etiquetas F y P muestran los valores de i y j que serían los elementos seleccionados de lista3 y per.

Un saludo.
__________________
La juventud pasa, la inmadurez se supera, la ignorancia se cura con la educación, y la embriaguez con la sobriedad, pero la estupidez dura para siempre. Aristofanes.
Responder Con Cita