Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#2220 closed enhancement (done)

Improve the generation of all possible combinations of values in ValueGenerator.cs

Reported by: bburlacu Owned by: bburlacu
Priority: low Milestone: HeuristicLab 3.3.11
Component: Problems.Instances Version: 3.3.10
Keywords: Cc:

Description

The method GenerateAllCombinationsOfValuesInLists from HeuristicLab.Problems.Instances.DataAnalysis.ValueGenerator.cs seems unnecessarily complicated. The following snippet [1] should achieve the same functionality:

public static IEnumerable<IEnumerable<T>> CartesianProduct<T>(this IEnumerable<IEnumerable<T>> sequences) {
    IEnumerable<IEnumerable<T>> result = new[] { Enumerable.Empty<T>() };
    return sequences.Aggregate(result, (current, s) => (from seq in current from item in s select seq.Concat(new[] { item })));
  }

[1] http://blogs.msdn.com/b/ericlippert/archive/2010/06/28/computing-a-cartesian-product-with-linq.aspx

Change History (4)

comment:1 Changed 3 years ago by mkommend

  • Owner changed from mkommend to bburlacu
  • Status changed from new to assigned

comment:2 Changed 3 years ago by bburlacu

  • Owner changed from bburlacu to mkommend
  • Status changed from assigned to reviewing

r11347: Fixed bug in the CartesianProduct extension method that was added in r11309 as part of #2234.

comment:3 Changed 3 years ago by mkommend

  • Owner changed from mkommend to bburlacu
  • Status changed from reviewing to readytorelease

r11347 is fine. Please merge r11309 with this ticket to stable, so that #2234 and #2237 can be merged independently.

comment:4 Changed 3 years ago by mkommend

  • Resolution set to done
  • Status changed from readytorelease to closed

r11370: Merged r11309 & r11347 into stable.

Last edited 3 years ago by mkommend (previous) (diff)
Note: See TracTickets for help on using tickets.