c# - Flights: find lowest price flight combinations -


a destination may have 2 connected flights, example

for frankfurt boston

frankfurt-london (at 08:00-10:00, 14:00-18:00 etc.) flight number fl1, fl2

london-boston (at 10:00-12:00, 16:00-20:00 etc.) flight number lb1, lb2

each flight may have classes such a, b etc. (from cheap expensive)

i have cartesian such of combinations:

fl1/a - lb1/a (fl1 being flight number / being class)
fl1/a - lb1/b
fl1/b - lb1/a
fl1/b - lb1/b
...
fl2/b - lb2/b

what should present @ end screen lowest price flight each destination combination:

fl1/a - lb1/a
fl1/a - lb2/a
fl2/a - lb1/a
fl2/a - lb2/a

how can achieve linq query/queries?

what should find lowest priced flight


i have destination , flight classes:

class destination  {     list<flight> flights } 

and

class flight{     list<string> @classes;   //such a,b,c,d,e       string flightid;        } 

so far can have flatten list of flights with:

var flights = destination.selectmany(d=>d.flights); 

but cannot figure out how continue?

note: hope did not make mistake while simplifying real case

here looks case on html table structure:

enter image description here

to me unclear yet, if each destination has 2 connected flights

public class destination {    public flight flight1 {get;set;}    public flight flight2 {get;set;} } 

i this:

var comb =   (from dest in destinations               fc1 in dest.fligth1.classes.select(s=>new {flightid=dest.flight1.flightid, class=s})               fc2 in dest.fligth2.classes.select(s=>new {flightid=dest.flight2.flightid, class=s})               select new {fc1, fc2}).orderby(e=>e.fc1.class).thenby(e=>fc2.class); 

if want keet list of flights in destination, guess can use indexer of list:

var comb =   (from dest in destinations               fc1 in dest.flights[0].classes.select(s=>new {flightid=dest.flights[0].flightid, class=s})               fc2 in dest.flights[1].classes.select(s=>new {flightid=dest.flights[1].flightid, class=s})               select new {fc1, fc2}).orderby(e=>e.fc1.class).thenby(e=>e.fc2.class); 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -