def compute_reduction_steps(self, max_nsteps=5): K = len(self.dds.actions) nsteps = [] nplans = [] ncplans = [] for n in range(1, max_nsteps + 1): nsteps.append(n) plans = plans_of_max_length(ncmd=K, maxsteps=n) cplans, _ = self.get_minimal_equiv_set(plans) # print('%3d steps: from %5d to %5d' % # (n, len(plans), len(cplans))) nplans.append(len(plans)) ncplans.append(len(cplans)) return nsteps, nplans, ncplans
def show_reduction(self, report, nsteps=4): K = len(self.dds.actions) # all plans of length 4 plans = plans_of_max_length(ncmd=K, maxsteps=nsteps) cplans, plan2cplans = self.get_minimal_equiv_set(plans) s = "\n".join('%s -> %s (sum cmd: %s)' % (self.plan2desc(a), self.plan2desc(b), self.plan2point(a)) # , self.plan2point(b)) for a, b in plan2cplans.items()) report.text('plans', s) s = "\n".join('%s (sum: %s)' % (self.plan2desc(x), self.plan2point(x)) for x in cplans) report.text('cplans', s) def plot_plan_points(pylab, plans): # points by rows points = np.array(map(self.plan2point, plans)) print points.shape ndim = points.shape[1] if ndim == 1: pylab.plot(0 * points, points, 'rx') if ndim == 2: x = points[:, 0] y = points[:, 1] pylab.plot(x, y, 'rx') if ndim == 3: pass f = report.figure() caption = 'Points reached by the %d plans of %d steps' % (len(plans), nsteps) with f.plot('plans_reached', caption=caption) as pylab: plot_plan_points(pylab, plans) pylab.axis('equal') caption = 'Points reached by %d canonical plans' % len(cplans) with f.plot('cplans_reached', caption=caption) as pylab: plot_plan_points(pylab, cplans) pylab.axis('equal')