constraints

Solve an implicit ODE (differential algebraic equation DAE)

倖福魔咒の 提交于 2019-12-03 13:42:51
问题 I'm trying to solve a second order ODE using odeint from scipy. The issue I'm having is the function is implicitly coupled to the second order term, as seen in the simplified snippet (please ignore the pretend physics of the example): import numpy as np from scipy.integrate import odeint def integral(y,t,F_l,mass): dydt = np.zeros_like(y) x, v = y F_r = (((1-a)/3)**2 + (2*(1+a)/3)**2) * v # 'a' implicit a = (F_l - F_r)/mass dydt = [v, a] return dydt y0 = [0,5] time = np.linspace(0.,10.,21) F

What does “where T : somevalue” mean?

試著忘記壹切 提交于 2019-12-03 13:21:26
问题 What does where T : somevalue mean? I just saw some code that said where T : Attribute . I think this has something to do with generics but I am not sure what this means or what it is doing. Does anyone know? 回答1: It is a constraint on a type parameter, meaning that the type T given to a generic class or method must inherit from the class Attribute For example: public class Foo<T> : where T : Attribute { public string GetTypeId(T attr) { return attr.TypeId.ToString(); } // .. } Foo

Why does a direct cast fail but the “as” operator succeed when testing a constrained generic type?

安稳与你 提交于 2019-12-03 11:55:12
``I've run across an interesting curiosity when compiling some C# code that uses generics with type constraints. I've written a quick test case for illustration. I'm using .NET 4.0 with Visual Studio 2010. namespace TestCast { public class Fruit { } public class Apple : Fruit { } public static class Test { public static void TestFruit<FruitType>(FruitType fruit) where FruitType : Fruit { if (fruit is Apple) { Apple apple = (Apple)fruit; } } } } The cast to Apple fails with the error: "Cannot convert type 'FruitType' to 'TestCast.Apple'". However, if I change the line to use the as operator, it

How to edit constraint in code

主宰稳场 提交于 2019-12-03 11:37:05
I have a web page that start with a width constrain of 100. When the user click a button i want to change the constrain to : 200. I tried this: NSLayoutConstraint *constrain = [NSLayoutConstraint constraintWithItem:self.webPage attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.webPage attribute:NSLayoutAttributeWidth multiplier:1 constant:100]; [self.webPage addConstraint:constrain]; But this throws out this exception : "Unable to simultaneously satisfy constraints." Any ideas? Matthias Bauch You have two options. Get a reference to the original constraint and change

How to alter length of varchar in composite primary key?

南笙酒味 提交于 2019-12-03 10:20:53
In MSSQL I have a table created like this: CREATE TABLE [mytable] (fkid int NOT NULL, data varchar(255) CONSTRAINT DF_mytable_data DEFAULT '' NOT NULL); ALTER TABLE [mytable] ADD CONSTRAINT PK_mytable_data PRIMARY KEY (fkid, data); Now I want to increase the length of the 'data' column from 255 to 4000. If I just try: ALTER TABLE [mytable] ALTER COLUMN data varchar(4000); Then I get this error: The object 'PK_mytable_data' is dependent on the column 'data' If I try this: ALTER TABLE [mytable] DROP CONSTRAINT PK_mytable_data; ALTER TABLE [mytable] ALTER COLUMN data varchar(4000); ALTER TABLE

Add dots/ellipsis on div/span element overflow without using jquery

半城伤御伤魂 提交于 2019-12-03 09:11:16
问题 Need to implement functionality similar to what dotdotdot jQuery plugin does but cannot use javascript frameworks (like jquery or ext). Is there any easy way to add the dots to the content of div or span element if content takes more space then element should??? (similar to what css overflow: ellipsis setting does) Can't use ellipsis beacause it doesn't work with many lines when height is limited. Thank you :) 回答1: Why not using the CSS property text-overflow? It works great as long as you

ASP.NET MVC - Use Reflection to find if a Controller Exists

风流意气都作罢 提交于 2019-12-03 09:06:11
I'm having a heck of a time figuring out how to properly implement my 404 redirecting. If I use the following <HandleError()> _ Public Class BaseController : Inherits System.Web.Mvc.Controller ''# do stuff End Class Then any unhandled error on the page will load up the "Error" view which works great. http://example.com/user/999 (where 999 is an invalid User ID) will throw an error while maintaining the original URL (this is what I want) However. If someone enters http://example.com/asdfjkl into the url (where asdfjkl is an invalid controller), then IIS is throwing the generic 404 page. (this

Algorithms for Updating Relational Data

时光怂恿深爱的人放手 提交于 2019-12-03 09:02:53
What algorithms are known to perform the task of updating a database by inserting, updating, and deleting rows in the presence of database constraints? More specifically, say that before images of rows to be deleted, after images of rows to be inserted, and both images of rows to be updated are in memory. The rows might be for several tables. An exact sequence of updates is either not known or has not been preserved -- only the before images and the after images that the database must ultimately be made to reflect are known. The database contains primary key, foreign key, and unique index

Postgres constraint ensuring one column of many is present?

丶灬走出姿态 提交于 2019-12-03 07:40:32
问题 What are good ways to add a constraint to PostgreSQL to check that exactly one column (from a set of columns) contains a non-null value? Update : It is likely that I want to use a check expression as detailed in Create Table and Alter Table. Update : I'm looking through the available functions. Update : Just for background, here is the Rails validation logic I'm currently using: validate :multi_column_validation def multi_column_validation n = 0 n += 1 if column_1 n += 1 if column_2 n += 1 if

MySQL with Soft-Deletion, Unique Key and Foreign Key Constraints

放肆的年华 提交于 2019-12-03 07:12:30
问题 Say I have two tables, user and comment . They have table definitions that look like this: CREATE TABLE `user` ( `id` INTEGER NOT NULL AUTO_INCREMENT, `username` VARCHAR(255) NOT NULL, `deleted` TINYINT(1) NOT NULL DEFAULT 0, PRIMARY KEY (`id`), UNIQUE KEY (`username`) ) ENGINE=InnoDB; CREATE TABLE `comment` ( `id` INTEGER NOT NULL AUTO_INCREMENT, `user_id` INTEGER NOT NULL, `comment` TEXT, `deleted` TINYINT(1) NOT NULL DEFAULT 0, PRIMARY KEY (`id`), CONSTRAINT `fk_comment_user_id` FOREIGN