mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 09:28:51 -06:00
Remove unused parameters
This commit is contained in:
@@ -41,7 +41,7 @@ The class `MaxWeightStableSetGenerator` can be used to generate random instances
|
|||||||
```python
|
```python
|
||||||
MaxWeightStableSetGenerator(w=uniform(loc=100., scale=50.),
|
MaxWeightStableSetGenerator(w=uniform(loc=100., scale=50.),
|
||||||
n=randint(low=200, high=201),
|
n=randint(low=200, high=201),
|
||||||
density=uniform(loc=0.05, scale=0.0),
|
p=uniform(loc=0.05, scale=0.0),
|
||||||
fix_graph=True)
|
fix_graph=True)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -12,17 +12,10 @@ from scipy.stats.distributions import rv_frozen
|
|||||||
|
|
||||||
|
|
||||||
class MaxWeightStableSetChallengeA:
|
class MaxWeightStableSetChallengeA:
|
||||||
"""
|
|
||||||
- Fixed random graph (200 vertices, 5% density)
|
|
||||||
- Random weights ~ U(100., 150.)
|
|
||||||
- 300 training instances
|
|
||||||
- 50 test instances
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.generator = MaxWeightStableSetGenerator(w=uniform(loc=100., scale=50.),
|
self.generator = MaxWeightStableSetGenerator(w=uniform(loc=100., scale=50.),
|
||||||
n=randint(low=200, high=201),
|
n=randint(low=200, high=201),
|
||||||
density=uniform(loc=0.05, scale=0.0),
|
p=uniform(loc=0.05, scale=0.0),
|
||||||
fix_graph=True)
|
fix_graph=True)
|
||||||
|
|
||||||
def get_training_instances(self):
|
def get_training_instances(self):
|
||||||
@@ -35,42 +28,37 @@ class MaxWeightStableSetChallengeA:
|
|||||||
class MaxWeightStableSetGenerator:
|
class MaxWeightStableSetGenerator:
|
||||||
"""Random instance generator for the Maximum-Weight Stable Set Problem.
|
"""Random instance generator for the Maximum-Weight Stable Set Problem.
|
||||||
|
|
||||||
The generator has two modes of operation. When `fix_graph` is True, the random graph is
|
The generator has two modes of operation. When `fix_graph=True` is provided, one random
|
||||||
generated only once, during the constructor. Each instance is constructed by generating
|
Erdős-Rényi graph $G_{n,p}$ is generated in the constructor, where $n$ and $p$ are sampled
|
||||||
random weights and by randomly deleting vertices and edges of this graph. When `fix_graph`
|
from user-provided probability distributions `n` and `p`. To generate each instance, the
|
||||||
is False, a new random graph is created each time an instance is constructed.
|
generator independently samples each $w_v$ from the user-provided probability distribution `w`.
|
||||||
|
|
||||||
|
When `fix_graph=False`, a new random graph is generated for each instance; the remaining
|
||||||
|
parameters are sampled in the same way.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
w=uniform(loc=10.0, scale=1.0),
|
w=uniform(loc=10.0, scale=1.0),
|
||||||
pe=bernoulli(1.),
|
|
||||||
pv=bernoulli(1.),
|
|
||||||
n=randint(low=250, high=251),
|
n=randint(low=250, high=251),
|
||||||
density=uniform(loc=0.05, scale=0.05),
|
p=uniform(loc=0.05, scale=0.0),
|
||||||
fix_graph=True):
|
fix_graph=True):
|
||||||
"""Initializes the problem generator.
|
"""Initialize the problem generator.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
w: rv_continuous
|
w: rv_continuous
|
||||||
Probability distribution for the vertex weights.
|
Probability distribution for vertex weights.
|
||||||
pe: rv_continuous
|
|
||||||
Probability of an edge being deleted. Only used when fix_graph=True.
|
|
||||||
pv: rv_continuous
|
|
||||||
Probability of a vertex being deleted. Only used when fix_graph=True.
|
|
||||||
n: rv_discrete
|
n: rv_discrete
|
||||||
Probability distribution for the number of vertices in the random graph.
|
Probability distribution for parameter $n$ in Erdős-Rényi model.
|
||||||
density: rv_continuous
|
p: rv_continuous
|
||||||
Probability distribution for the density of the random graph.
|
Probability distribution for parameter $p$ in Erdős-Rényi model.
|
||||||
"""
|
"""
|
||||||
assert isinstance(w, rv_frozen), "w should be a SciPy probability distribution"
|
assert isinstance(w, rv_frozen), "w should be a SciPy probability distribution"
|
||||||
assert isinstance(pe, rv_frozen), "pe should be a SciPy probability distribution"
|
|
||||||
assert isinstance(pv, rv_frozen), "pv should be a SciPy probability distribution"
|
|
||||||
assert isinstance(n, rv_frozen), "n should be a SciPy probability distribution"
|
assert isinstance(n, rv_frozen), "n should be a SciPy probability distribution"
|
||||||
assert isinstance(density, rv_frozen), "density should be a SciPy probability distribution"
|
assert isinstance(p, rv_frozen), "p should be a SciPy probability distribution"
|
||||||
self.w = w
|
self.w = w
|
||||||
self.n = n
|
self.n = n
|
||||||
self.density = density
|
self.p = p
|
||||||
self.fix_graph = fix_graph
|
self.fix_graph = fix_graph
|
||||||
self.graph = None
|
self.graph = None
|
||||||
if fix_graph:
|
if fix_graph:
|
||||||
@@ -87,7 +75,7 @@ class MaxWeightStableSetGenerator:
|
|||||||
return [_sample() for _ in range(n_samples)]
|
return [_sample() for _ in range(n_samples)]
|
||||||
|
|
||||||
def _generate_graph(self):
|
def _generate_graph(self):
|
||||||
return nx.generators.random_graphs.binomial_graph(self.n.rvs(), self.density.rvs())
|
return nx.generators.random_graphs.binomial_graph(self.n.rvs(), self.p.rvs())
|
||||||
|
|
||||||
|
|
||||||
class MaxWeightStableSetInstance(Instance):
|
class MaxWeightStableSetInstance(Instance):
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ def test_stab_generator_fixed_graph():
|
|||||||
from miplearn.problems.stab import MaxWeightStableSetGenerator
|
from miplearn.problems.stab import MaxWeightStableSetGenerator
|
||||||
gen = MaxWeightStableSetGenerator(w=uniform(loc=50., scale=10.),
|
gen = MaxWeightStableSetGenerator(w=uniform(loc=50., scale=10.),
|
||||||
n=randint(low=10, high=11),
|
n=randint(low=10, high=11),
|
||||||
density=uniform(loc=0.05, scale=0.),
|
p=uniform(loc=0.05, scale=0.),
|
||||||
fix_graph=True)
|
fix_graph=True)
|
||||||
instances = gen.generate(1_000)
|
instances = gen.generate(1_000)
|
||||||
weights = np.array([instance.weights for instance in instances])
|
weights = np.array([instance.weights for instance in instances])
|
||||||
@@ -36,7 +36,7 @@ def test_stab_generator_random_graph():
|
|||||||
from miplearn.problems.stab import MaxWeightStableSetGenerator
|
from miplearn.problems.stab import MaxWeightStableSetGenerator
|
||||||
gen = MaxWeightStableSetGenerator(w=uniform(loc=50., scale=10.),
|
gen = MaxWeightStableSetGenerator(w=uniform(loc=50., scale=10.),
|
||||||
n=randint(low=30, high=41),
|
n=randint(low=30, high=41),
|
||||||
density=uniform(loc=0.5, scale=0.),
|
p=uniform(loc=0.5, scale=0.),
|
||||||
fix_graph=False)
|
fix_graph=False)
|
||||||
instances = gen.generate(1_000)
|
instances = gen.generate(1_000)
|
||||||
n_nodes = [instance.graph.number_of_nodes() for instance in instances]
|
n_nodes = [instance.graph.number_of_nodes() for instance in instances]
|
||||||
|
|||||||
Reference in New Issue
Block a user