如何使用GUROBI找到LP中所有可能的最佳解决方案

时间:2018-10-13 19:54:19

标签: python linear-programming gurobi

我已经用GUROBI解决了LP模型,并且我知道该模型具有无限数量的最优解。如下所示,目标函数和构造1具有相同的斜率,构造1绑定。 GUROBI仅显示一种最佳解决方案,但是如何找到所有可能的解决方案(或范围)?如何在更复杂的LP模型中找到最佳解决方案的数量?

import 'package:flutter/material.dart';

class SmallEventCard extends StatefulWidget {
  final imageURL;
  final title;
  final time;
  final place;

  SmallEventCard({this.imageURL, this.title, this.time, this.place});

  @override
  _SmallEventCardState createState() => _SmallEventCardState();

}

class _SmallEventCardState extends State<SmallEventCard> {
  bool isFavorite;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    isFavorite = false;
  }

  @override
  Widget build(BuildContext context) {
    final screen = MediaQuery.of(context).size;


    return Material(
      child: SizedBox(
        height: screen.height / 7,
        child: Card(
          shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
          child: Row(
            children: <Widget>[
              AspectRatio(
                aspectRatio: 4 / 3,
                child: Image.network(widget.imageURL,
                  fit: BoxFit.fitHeight,
                ),
              ),
              SizedBox(
                width: 10.0,
              ),
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Text(widget.title, 
                      style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold),maxLines: 2, overflow: TextOverflow.clip,
                    ),
                    SizedBox(height: 5.0,),
                    Text(widget.time.toString(),
                      overflow: TextOverflow.clip,
                    ),
                    SizedBox(height: 5.0,),
                    Text(widget.place,
                      overflow: TextOverflow.clip,
                    ),
                  ],
                ),
              ),
              SizedBox(
                width: 50.0,
                child: Align(
                  alignment: Alignment.centerRight,
                  child: Padding(
                    padding: const EdgeInsets.all(10.0),
                    child: IconButton(
                      onPressed: () {},
                      icon: Icon(Icons.favorite_border)),
                  )),
              ),
            ],
          ),
        ),
      ),
    );
  }
}  

1 个答案:

答案 0 :(得分:0)

所有最佳LP解决方案都是一个困难的概念。可能有无限多个。 Gurobi具有用于枚举所有最佳整数解(解决方案池)的工具,但不适用于纯LP。因此,简短的答案是“否”。

可以列举所有最佳基数,但需要做一些工作(使用二进制变量对基数进行基本编码:变量或约束是基本或非基本的)。参见此link。该方法可以通过添加其他约束来实现,或者通过使用上述解决方案池来更有效地实现。尽管从概念上讲很有趣,但是要注意,这种方法对于大问题并不实用。

相关问题