optimization - Algorithm for deciding which elements N and M with N:M relation to keep, which maximize resulting number of pairs -
i have bunch of elements of 2 classes n , m related 1 in many-to-many fashion. let's call them 'restaurants' , 'dishes'. want make selection of restaurants , dishes results in largest possible number of restaurant-dish pairs. however every restaurant must serve every possible dish retain, , every dish must available in every restaurant. how go finding restaurants , dishes should kick out?
one possible (far optimal) "solution" keep restaurants serving dishes (resulting in few restaurants being retained), or dishes served in restaurants (resulting in few dishes being retained). not after, want determine optimal way make such selection, resulting in fair balance of restaurants , dishes being retained.
i working in python; in case helps anyone, here simple code generates type of many-to-many data i'm dealing with:
import numpy np # let dish identified integer between 0 , 100 dishes = np.arange(100) restaurants = [] k in range(30): # restaurant have multiple dishes # amount of dishes vary per restaurant # e.g. between 10 , 100 here restaurants.append( np.random.choice(dishes, size=np.random.randint(10, 100), replace=false) )
first, observe restaurants-to-dishes mapping bipartite graph. next, observe solution "all restaurants serve every dish, , dishes served every restaurant" problem complete bipartite subgraph, or biclique. finally, since looking maximize number of dish-restaurant pairs (as opposed maximizing number of included dishes or number of participating restaurants) biclique trying find called edge maximum (the other maximum biclique called vertex maximum).
the problem, therefore, can formally restated follows:
find edge maximum biclique in bipartite graph.
this problem has fast algorithm described in this paper:
yun zhang, elissa j. chesler , michael a. langston
on finding bicliques in bipartite graphs: novel algorithm application integration of diverse biological data types
the paper has pseudocode on page 4.
Comments
Post a Comment